Minor code cleanups and ported some p4 interfacing code over to the p4 python mode.
Signed-off-by: Simon Hausmann <hausmann@kde.org>
Simon Hausmann committed
Jan 31, 2007 at 22:13 UTC
f6148d912965686f8bb081a53107ad21a9227007
1 file changed
+14
-39
contrib/fast-import/p4-fast-export.py
+14
-39
@@ -51,54 +51,30 @@ def p4Cmd(cmd):
51
return result
52
53
def describe(change):
54
- output = os.popen("p4 describe %s" % change).readlines()
54
+ describeOutput = p4Cmd("describe %s" % change)
55
56
- firstLine = output[0]
56
+ author = describeOutput["user"]
57
+ epoch = describeOutput["time"]
58
58
- splitted = firstLine.split(" ")
59
- author = splitted[3]
60
- author = author[:author.find("@")]
61
- tm = time.strptime(splitted[5] + " " + splitted[6], "%Y/%m/%d %H:%M:%S ")
62
- epoch = int(time.mktime(tm))
63
-
64
- filesSection = 0
65
- try:
66
- filesSection = output.index("Affected files ...\n")
67
- except ValueError:
68
- sys.stderr.write("Change %s doesn't seem to affect any files. Weird.\n" % change)
69
- return [], [], [], [], []
70
-
71
- differencesSection = 0
72
- try:
73
- differencesSection = output.index("Differences ...\n")
74
- except ValueError:
75
- sys.stderr.write("Change %s doesn't seem to have a differences section. Weird.\n" % change)
76
- return [], [], [], [], []
77
-
78
- log = output[2:filesSection - 1]
79
-
80
- lines = output[filesSection + 2:differencesSection - 1]
59
+ log = describeOutput["desc"]
60
61
changed = []
62
removed = []
63
85
- for line in lines:
86
- # chop off "... " and trailing newline
87
- line = line[4:len(line) - 1]
88
-
89
- lastSpace = line.rfind(" ")
90
- if lastSpace == -1:
91
- sys.stderr.write("trouble parsing line %s, skipping!\n" % line)
92
- continue
64
+ i = 0
65
+ while describeOutput.has_key("depotFile%s" % i):
66
+ path = describeOutput["depotFile%s" % i]
67
+ rev = describeOutput["rev%s" % i]
68
+ action = describeOutput["action%s" % i]
69
+ path = path + "#" + rev
70
94
- operation = line[lastSpace + 1:]
95
- path = line[:lastSpace]
96
-
97
- if operation == "delete":
71
+ if action == "delete":
72
removed.append(path)
73
else:
74
changed.append(path)
75
76
+ i = i + 1
77
+
78
return author, log, epoch, changed, removed
79
80
def p4Stat(path):
@@ -161,8 +137,7 @@ for change in changes:
137
else:
138
gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz))
139
gitStream.write("data <<EOT\n")
164
- for l in log:
165
- gitStream.write(l)
140
+ gitStream.write(log)
141
gitStream.write("EOT\n\n")
142
143
for f in changedFiles: