Code cleanups.
Signed-off-by: Simon Hausmann <simon@lst.de>
Simon Hausmann committed
Feb 12, 2007 at 20:28 UTC
44b3add6519d6a85fb75b90173ecd6e7ec1ba650
1 file changed
+21
-12
contrib/fast-import/p4-fast-export.py
+21
-12
@@ -93,7 +93,20 @@ def p4Cmd(cmd):
93
result.update(entry)
94
return result;
95
96
-def commit(details):
96
+def extractFilesFromCommit(commit):
97
+ files = []
98
+ fnum = 0
99
+ while commit.has_key("depotFile%s" % fnum):
100
+ file = {}
101
+ file["path"] = commit["depotFile%s" % fnum]
102
+ file["rev"] = commit["rev%s" % fnum]
103
+ file["action"] = commit["action%s" % fnum]
104
+ file["type"] = commit["type%s" % fnum]
105
+ files.append(file)
106
+ fnum = fnum + 1
107
+ return files
108
+
109
+def commit(details, files, branch):
110
global initialParent
111
global users
112
global lastChange
@@ -119,24 +132,22 @@ def commit(details):
132
gitStream.write("from %s\n" % initialParent)
133
initialParent = ""
134
122
- fnum = 0
123
- while details.has_key("depotFile%s" % fnum):
124
- path = details["depotFile%s" % fnum]
135
+ for file in files:
136
+ path = file["path"]
137
if not path.startswith(prefix):
138
print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, prefix, change)
127
- fnum = fnum + 1
139
continue
140
130
- rev = details["rev%s" % fnum]
141
+ rev = file["rev"]
142
depotPath = path + "#" + rev
143
relPath = path[len(prefix):]
133
- action = details["action%s" % fnum]
144
+ action = file["action"]
145
146
if action == "delete":
147
gitStream.write("D %s\n" % relPath)
148
else:
149
mode = 644
139
- if details["type%s" % fnum].startswith("x"):
150
+ if file["type"].startswith("x"):
151
mode = 755
152
153
data = os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
@@ -146,8 +157,6 @@ def commit(details):
157
gitStream.write(data)
158
gitStream.write("\n")
159
149
- fnum = fnum + 1
150
-
160
gitStream.write("\n")
161
162
lastChange = details["change"]
@@ -215,7 +224,7 @@ if len(revision) > 0:
224
details["change"] = newestRevision
225
226
try:
218
- commit(details)
227
+ commit(details, extractFilesFromCommit(details), branch)
228
except:
229
print gitError.read()
230
@@ -242,7 +251,7 @@ else:
251
cnt = cnt + 1
252
253
try:
245
- commit(description)
254
+ commit(description, extractFilesFromCommit(description), branch)
255
except:
256
print gitError.read()
257
sys.exit(1)