@matheusbsbs / matheus-bagliano / commits / 6754a299d8
Fork 0

minor cleanups

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>

Han-Wen Nienhuys committed May 23, 2007 at 17:41 UTC 6754a299d8d977326e396d641106cc5db4d29db1
1 file changed +20 -10
contrib/fast-import/git-p4
+20 -10
@@ -30,7 +30,8 @@ def write_pipe(c, str):
30 return val
31
32 def read_pipe(c):
33 - sys.stderr.write('reading pipe: %s\n' % c)
33 + if not silent:
34 + sys.stderr.write('reading pipe: %s\n' % c)
35 ## todo: check return status
36 pipe = os.popen(c, 'rb')
37 val = pipe.read()
@@ -42,7 +43,8 @@ def read_pipe(c):
43
44
45 def read_pipe_lines(c):
45 - sys.stderr.write('reading pipe: %s\n' % c)
46 + if not silent:
47 + sys.stderr.write('reading pipe: %s\n' % c)
48 ## todo: check return status
49 pipe = os.popen(c, 'rb')
50 val = pipe.readlines()
@@ -52,6 +54,14 @@ def read_pipe_lines(c):
54
55 return val
56
57 +def system(cmd):
58 + if not silent:
59 + sys.stderr.write("executing %s" % cmd)
60 + if os.system(cmd) != 0:
61 + die("command failed: %s" % cmd)
62 +
63 +
64 +
65 def p4CmdList(cmd):
66 cmd = "p4 -G %s" % cmd
67 pipe = os.popen(cmd, "rb")
@@ -111,10 +121,6 @@ def isValidGitDir(path):
121 def parseRevision(ref):
122 return read_pipe("git rev-parse %s" % ref)[:-1]
123
114 -def system(cmd):
115 - if os.system(cmd) != 0:
116 - die("command failed: %s" % cmd)
117 -
124 def extractLogMessageFromGitCommit(commit):
125 logMessage = ""
126
@@ -571,7 +577,6 @@ class P4Sync(Command):
577 (a ... is not needed in the path p4 specification, it's added implicitly)"""
578
579 self.usage += " //depot/path[@revRange]"
574 -
580 self.silent = False
581 self.createdBranches = Set()
582 self.committedChanges = Set()
@@ -584,6 +589,7 @@ class P4Sync(Command):
589 self.importIntoRemotes = True
590 self.maxChanges = ""
591 self.isWindows = (platform.system() == "Windows")
592 + self.depotPath = None
593
594 if gitConfig("git-p4.syncFromOrigin") == "false":
595 self.syncWithOrigin = False
@@ -611,9 +617,11 @@ class P4Sync(Command):
617 fnum = fnum + 1
618 return files
619
620 + def stripRepoPath(self, path):
621 + return path[len(self.depotPath):]
622 +
623 def splitFilesIntoBranches(self, commit):
624 branches = {}
616 -
625 fnum = 0
626 while commit.has_key("depotFile%s" % fnum):
627 path = commit["depotFile%s" % fnum]
@@ -630,10 +638,12 @@ class P4Sync(Command):
638 file["type"] = commit["type%s" % fnum]
639 fnum = fnum + 1
640
633 - relPath = path[len(self.depotPath):]
641 + relPath = self.stripRepoPath(path)
642
643 for branch in self.knownBranches.keys():
636 - if relPath.startswith(branch + "/"): # add a trailing slash so that a commit into qt/4.2foo doesn't end up in qt/4.2
644 +
645 + # add a trailing slash so that a commit into qt/4.2foo doesn't end up in qt/4.2
646 + if relPath.startswith(branch + "/"):
647 if branch not in branches:
648 branches[branch] = []
649 branches[branch].append(file)