Added some helper function(s) to parse the depot path and change number from the log message
Signed-off-by: Simon Hausmann <simon@lst.de>
Simon Hausmann committed
Mar 22, 2007 at 21:10 UTC
6ae8de88f53f92dd593c5d03b67d0194e7d4eefe
1 file changed
+36
-12
contrib/fast-import/git-p4
+36
-12
@@ -52,12 +52,44 @@ def system(cmd):
52
if os.system(cmd) != 0:
53
die("command failed: %s" % cmd)
54
55
+def extractLogMessageFromGitCommit(commit):
56
+ logMessage = ""
57
+ foundTitle = False
58
+ for log in os.popen("git-cat-file commit %s" % commit).readlines():
59
+ if not foundTitle:
60
+ if len(log) == 1:
61
+ foundTitle = 1
62
+ continue
63
+
64
+ logMessage += log
65
+ return logMessage
66
+
67
+def extractDepotPathAndChangeFromGitLog(log):
68
+ values = {}
69
+ for line in log.split("\n"):
70
+ line = line.strip()
71
+ if line.startswith("[git-p4:") and line.endswith("]"):
72
+ line = line[8:-1].strip()
73
+ for assignment in line.split(":"):
74
+ variable = assignment.strip()
75
+ value = ""
76
+ equalPos = assignment.find("=")
77
+ if equalPos != -1:
78
+ variable = assignment[:equalPos].strip()
79
+ value = assignment[equalPos + 1:].strip()
80
+ if value.startswith("\"") and value.endswith("\""):
81
+ value = value[1:-1]
82
+ values[variable] = value
83
+
84
+ return values.get("depot-path"), values.get("change")
85
+
86
class Command:
87
def __init__(self):
88
self.usage = "usage: %prog [options]"
89
90
class P4Debug(Command):
91
def __init__(self):
92
+ Command.__init__(self)
93
self.options = [
94
]
95
self.description = "A tool to debug the output of p4 -G."
@@ -208,17 +240,9 @@ class P4Sync(Command):
240
system("p4 revert %s" % f)
241
system("p4 delete %s" % f)
242
211
- logMessage = ""
212
- foundTitle = False
213
- for log in os.popen("git-cat-file commit %s" % id).readlines():
214
- if not foundTitle:
215
- if len(log) == 1:
216
- foundTitle = 1
217
- continue
218
-
219
- if len(logMessage) > 0:
220
- logMessage += "\t"
221
- logMessage += log
243
+ logMessage = extractLogMessageFromGitCommit(id)
244
+ logMessage = logMessage.replace("\n", "\n\t")
245
+ logMessage = logMessage[:-1]
246
247
template = os.popen("p4 change -o").read()
248
@@ -506,7 +530,7 @@ class GitSync(Command):
530
531
self.gitStream.write("data <<EOT\n")
532
self.gitStream.write(details["desc"])
509
- self.gitStream.write("\n[git-p4: depot-path: \"%s\"; change: %s]\n" % (branchPrefix, details["change"]))
533
+ self.gitStream.write("\n[git-p4: depot-path = \"%s\": change = %s]\n" % (branchPrefix, details["change"]))
534
self.gitStream.write("EOT\n\n")
535
536
if len(parent) > 0: