@matheusbsbs / matheus-bagliano / commits / 0dd0b9d011
Fork 0

Ported the remaining functions that parsed p4 shell output over to the p4 python interface.

Signed-off-by: Simon Hausmann <hausmann@kde.org>

Simon Hausmann committed Jan 31, 2007 at 22:31 UTC 0dd0b9d01116d57c612a5fa90de803bdd836ce11
1 file changed +31 -58
contrib/fast-import/p4-fast-export.py
+31 -58
@@ -57,47 +57,8 @@ def p4Cmd(cmd):
57 result.update(entry)
58 return result;
59
60 -def describe(change):
61 - describeOutput = p4Cmd("describe %s" % change)
62 -
63 - author = describeOutput["user"]
64 - epoch = describeOutput["time"]
65 -
66 - log = describeOutput["desc"]
67 -
68 - changed = []
69 - removed = []
70 -
71 - i = 0
72 - while describeOutput.has_key("depotFile%s" % i):
73 - path = describeOutput["depotFile%s" % i]
74 - rev = describeOutput["rev%s" % i]
75 - action = describeOutput["action%s" % i]
76 - path = path + "#" + rev
77 -
78 - if action == "delete":
79 - removed.append(path)
80 - else:
81 - changed.append(path)
82 -
83 - i = i + 1
84 -
85 - return author, log, epoch, changed, removed
86 -
87 -def p4Stat(path):
88 - output = os.popen("p4 fstat -Ol \"%s\"" % path).readlines()
89 - fileSize = 0
90 - mode = 644
91 - for line in output:
92 - if line.startswith("... headType x"):
93 - mode = 755
94 - elif line.startswith("... fileSize "):
95 - fileSize = long(line[12:])
96 - return mode, fileSize
97 -
98 -def stripRevision(path):
99 - hashPos = path.rindex("#")
100 - return path[:hashPos]
60 +def p4FileSize(path):
61 + return int(p4Cmd("fstat -Ol \"%s\"" % path)["fileSize"])
62
63 def getUserMap():
64 users = {}
@@ -127,38 +88,50 @@ gitOutput, gitStream, gitError = popen2.popen3("git-fast-import")
88
89 cnt = 1
90 for change in changes:
130 - [ author, log, epoch, changedFiles, removedFiles ] = describe(change)
91 + description = p4Cmd("describe %s" % change)
92 +
93 sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
94 cnt = cnt + 1
95
96 + epoch = description["time"]
97 + author = description["user"]
98 +
99 gitStream.write("commit refs/heads/master\n")
100 if author in users:
101 gitStream.write("committer %s %s %s\n" % (users[author], epoch, tz))
102 else:
103 gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz))
104 gitStream.write("data <<EOT\n")
140 - gitStream.write(log)
105 + gitStream.write(description["desc"])
106 gitStream.write("EOT\n\n")
107
143 - for f in changedFiles:
144 - if not f.startswith(prefix):
145 - sys.stderr.write("\nchanged files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change))
108 + fnum = 0
109 + while description.has_key("depotFile%s" % fnum):
110 + path = description["depotFile%s" % fnum]
111 + if not path.startswith(prefix):
112 + print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, prefix, change)
113 + fnum = fnum + 1
114 continue
147 - relpath = f[len(prefix):]
115
149 - [mode, fileSize] = p4Stat(f)
116 + rev = description["rev%s" % fnum]
117 + depotPath = path + "#" + rev
118 + relPath = path[len(prefix):]
119 + action = description["action%s" % fnum]
120
151 - gitStream.write("M %s inline %s\n" % (mode, stripRevision(relpath)))
152 - gitStream.write("data %s\n" % fileSize)
153 - gitStream.write(os.popen("p4 print -q \"%s\"" % f).read())
154 - gitStream.write("\n")
121 + if action == "delete":
122 + gitStream.write("D %s\n" % relPath)
123 + else:
124 + fileSize = p4FileSize(depotPath)
125 + mode = 644
126 + if description["type%s" % fnum].startswith("x"):
127 + mode = 755
128
156 - for f in removedFiles:
157 - if not f.startswith(prefix):
158 - sys.stderr.write("\ndeleted files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change))
159 - continue
160 - relpath = f[len(prefix):]
161 - gitStream.write("D %s\n" % stripRevision(relpath))
129 + gitStream.write("M %s inline %s\n" % (mode, relPath))
130 + gitStream.write("data %s\n" % fileSize)
131 + gitStream.write(os.popen("p4 print -q \"%s\"" % depotPath).read())
132 + gitStream.write("\n")
133 +
134 + fnum = fnum + 1
135
136 gitStream.write("\n")
137