+def commit(details):
+ global initialParent
+ global users
+
+ epoch = details["time"]
+ author = details["user"]
+
+ gitStream.write("commit %s\n" % branch)
+ committer = ""
+ if author in users:
+ committer = "%s %s %s" % (users[author], epoch, tz)
+ else:
+ committer = "%s <a@b> %s %s" % (author, epoch, tz)
+
+ gitStream.write("committer %s\n" % committer)
+
+ gitStream.write("data <<EOT\n")
+ gitStream.write(details["desc"])
+ gitStream.write("\n[ imported from %s; change %s ]\n" % (prefix, change))
+ gitStream.write("EOT\n\n")
+
+ if len(initialParent) > 0:
+ gitStream.write("merge %s\n" % initialParent)
+ initialParent = ""
+
+ fnum = 0
+ while details.has_key("depotFile%s" % fnum):
+ path = details["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
+
+ rev = details["rev%s" % fnum]
+ depotPath = path + "#" + rev
+ relPath = path[len(prefix):]
+ action = details["action%s" % fnum]
+
+ if action == "delete":
+ gitStream.write("D %s\n" % relPath)
+ else:
+ mode = 644
+ if details["type%s" % fnum].startswith("x"):
+ mode = 755
+
+ data = os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
+
+ gitStream.write("M %s inline %s\n" % (mode, relPath))
+ gitStream.write("data %s\n" % len(data))
+ gitStream.write(data)
+ gitStream.write("\n")
+
+ fnum = fnum + 1
+
+ gitStream.write("\n")
+
+ gitStream.write("tag p4/%s\n" % change)
+ gitStream.write("from %s\n" % branch);
+ gitStream.write("tagger %s\n" % committer);
+ gitStream.write("data 0\n\n")
+
+