Ported the remaining functions that parsed p4 shell output over to the p4 python interface.
Signed-off-by: Simon Hausmann <hausmann@kde.org>
This commit is contained in:
parent
a39811b46e
commit
0dd0b9d011
@ -57,47 +57,8 @@ def p4Cmd(cmd):
|
|||||||
result.update(entry)
|
result.update(entry)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
def describe(change):
|
def p4FileSize(path):
|
||||||
describeOutput = p4Cmd("describe %s" % change)
|
return int(p4Cmd("fstat -Ol \"%s\"" % path)["fileSize"])
|
||||||
|
|
||||||
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 getUserMap():
|
def getUserMap():
|
||||||
users = {}
|
users = {}
|
||||||
@ -127,38 +88,50 @@ gitOutput, gitStream, gitError = popen2.popen3("git-fast-import")
|
|||||||
|
|
||||||
cnt = 1
|
cnt = 1
|
||||||
for change in changes:
|
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)))
|
sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
|
|
||||||
|
epoch = description["time"]
|
||||||
|
author = description["user"]
|
||||||
|
|
||||||
gitStream.write("commit refs/heads/master\n")
|
gitStream.write("commit refs/heads/master\n")
|
||||||
if author in users:
|
if author in users:
|
||||||
gitStream.write("committer %s %s %s\n" % (users[author], epoch, tz))
|
gitStream.write("committer %s %s %s\n" % (users[author], epoch, tz))
|
||||||
else:
|
else:
|
||||||
gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz))
|
gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz))
|
||||||
gitStream.write("data <<EOT\n")
|
gitStream.write("data <<EOT\n")
|
||||||
gitStream.write(log)
|
gitStream.write(description["desc"])
|
||||||
gitStream.write("EOT\n\n")
|
gitStream.write("EOT\n\n")
|
||||||
|
|
||||||
for f in changedFiles:
|
fnum = 0
|
||||||
if not f.startswith(prefix):
|
while description.has_key("depotFile%s" % fnum):
|
||||||
sys.stderr.write("\nchanged files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change))
|
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
|
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)))
|
if action == "delete":
|
||||||
|
gitStream.write("D %s\n" % relPath)
|
||||||
|
else:
|
||||||
|
fileSize = p4FileSize(depotPath)
|
||||||
|
mode = 644
|
||||||
|
if description["type%s" % fnum].startswith("x"):
|
||||||
|
mode = 755
|
||||||
|
|
||||||
|
gitStream.write("M %s inline %s\n" % (mode, relPath))
|
||||||
gitStream.write("data %s\n" % fileSize)
|
gitStream.write("data %s\n" % fileSize)
|
||||||
gitStream.write(os.popen("p4 print -q \"%s\"" % f).read())
|
gitStream.write(os.popen("p4 print -q \"%s\"" % depotPath).read())
|
||||||
gitStream.write("\n")
|
gitStream.write("\n")
|
||||||
|
|
||||||
for f in removedFiles:
|
fnum = fnum + 1
|
||||||
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("\n")
|
gitStream.write("\n")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user