diff options
author | Simon Hausmann <hausmann@kde.org> | 2007-01-31 22:31:28 +0100 |
---|---|---|
committer | Simon Hausmann <hausmann@kde.org> | 2007-01-31 22:31:28 +0100 |
commit | 0dd0b9d01116d57c612a5fa90de803bdd836ce11 (patch) | |
tree | 05bff183cde0098039fba887f81328726e2433d8 /contrib | |
parent | Instead of parsing the output of "p4 users" use the python objects of "p4 -G ... (diff) | |
download | tgif-0dd0b9d01116d57c612a5fa90de803bdd836ce11.tar.xz |
Ported the remaining functions that parsed p4 shell output over to the p4 python interface.
Signed-off-by: Simon Hausmann <hausmann@kde.org>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/fast-import/p4-fast-export.py | 89 |
1 files changed, 31 insertions, 58 deletions
diff --git a/contrib/fast-import/p4-fast-export.py b/contrib/fast-import/p4-fast-export.py index d3e65f0f39..45d5157961 100644 --- a/contrib/fast-import/p4-fast-export.py +++ b/contrib/fast-import/p4-fast-export.py @@ -57,47 +57,8 @@ def p4Cmd(cmd): result.update(entry) return result; -def describe(change): - describeOutput = p4Cmd("describe %s" % change) - - author = describeOutput["user"] - epoch = describeOutput["time"] - - log = describeOutput["desc"] - - changed = [] - removed = [] - - i = 0 - while describeOutput.has_key("depotFile%s" % i): - path = describeOutput["depotFile%s" % i] - rev = describeOutput["rev%s" % i] - action = describeOutput["action%s" % i] - path = path + "#" + rev - - if action == "delete": - removed.append(path) - else: - changed.append(path) - - i = i + 1 - - return author, log, epoch, changed, removed - -def p4Stat(path): - output = os.popen("p4 fstat -Ol \"%s\"" % path).readlines() - fileSize = 0 - mode = 644 - for line in output: - if line.startswith("... headType x"): - mode = 755 - elif line.startswith("... fileSize "): - fileSize = long(line[12:]) - return mode, fileSize - -def stripRevision(path): - hashPos = path.rindex("#") - return path[:hashPos] +def p4FileSize(path): + return int(p4Cmd("fstat -Ol \"%s\"" % path)["fileSize"]) def getUserMap(): users = {} @@ -127,38 +88,50 @@ gitOutput, gitStream, gitError = popen2.popen3("git-fast-import") cnt = 1 for change in changes: - [ author, log, epoch, changedFiles, removedFiles ] = describe(change) + description = p4Cmd("describe %s" % change) + sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes))) cnt = cnt + 1 + epoch = description["time"] + author = description["user"] + gitStream.write("commit refs/heads/master\n") if author in users: gitStream.write("committer %s %s %s\n" % (users[author], epoch, tz)) else: gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz)) gitStream.write("data <<EOT\n") - gitStream.write(log) + gitStream.write(description["desc"]) gitStream.write("EOT\n\n") - for f in changedFiles: - if not f.startswith(prefix): - sys.stderr.write("\nchanged files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change)) + fnum = 0 + while description.has_key("depotFile%s" % fnum): + path = description["depotFile%s" % fnum] + if not path.startswith(prefix): + print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, prefix, change) + fnum = fnum + 1 continue - relpath = f[len(prefix):] - [mode, fileSize] = p4Stat(f) + rev = description["rev%s" % fnum] + depotPath = path + "#" + rev + relPath = path[len(prefix):] + action = description["action%s" % fnum] - gitStream.write("M %s inline %s\n" % (mode, stripRevision(relpath))) - gitStream.write("data %s\n" % fileSize) - gitStream.write(os.popen("p4 print -q \"%s\"" % f).read()) - gitStream.write("\n") + if action == "delete": + gitStream.write("D %s\n" % relPath) + else: + fileSize = p4FileSize(depotPath) + mode = 644 + if description["type%s" % fnum].startswith("x"): + mode = 755 - for f in removedFiles: - if not f.startswith(prefix): - sys.stderr.write("\ndeleted files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change)) - continue - relpath = f[len(prefix):] - gitStream.write("D %s\n" % stripRevision(relpath)) + gitStream.write("M %s inline %s\n" % (mode, relPath)) + gitStream.write("data %s\n" % fileSize) + gitStream.write(os.popen("p4 print -q \"%s\"" % depotPath).read()) + gitStream.write("\n") + + fnum = fnum + 1 gitStream.write("\n") |