@matheusbsbs / matheus-bagliano / commits / 1f4ba1cbfc
Fork 0

Added support for mapping p4 labels to git tags

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

Simon Hausmann committed Mar 26, 2007 at 22:34 UTC 1f4ba1cbfc1d08a9c120012c9199caaec3dc5f58
1 file changed +57 -1
contrib/fast-import/git-p4
+57 -1
@@ -625,7 +625,47 @@ class GitSync(Command):
625
626 self.gitStream.write("\n")
627
628 - self.lastChange = int(details["change"])
628 + change = int(details["change"])
629 +
630 + self.lastChange = change
631 +
632 + if change in self.labels:
633 + label = self.labels[change]
634 + labelDetails = label[0]
635 + labelRevisions = label[1]
636 +
637 + files = p4CmdList("files %s...@%s" % (branchPrefix, change))
638 +
639 + if len(files) == len(labelRevisions):
640 +
641 + cleanedFiles = {}
642 + for info in files:
643 + if info["action"] == "delete":
644 + continue
645 + cleanedFiles[info["depotFile"]] = info["rev"]
646 +
647 + if cleanedFiles == labelRevisions:
648 + self.gitStream.write("tag tag_%s\n" % labelDetails["label"])
649 + self.gitStream.write("from %s\n" % branch)
650 +
651 + owner = labelDetails["Owner"]
652 + tagger = ""
653 + if author in self.users:
654 + tagger = "%s %s %s" % (self.users[owner], epoch, self.tz)
655 + else:
656 + tagger = "%s <a@b> %s %s" % (owner, epoch, self.tz)
657 + self.gitStream.write("tagger %s\n" % tagger)
658 + self.gitStream.write("data <<EOT\n")
659 + self.gitStream.write(labelDetails["Description"])
660 + self.gitStream.write("EOT\n\n")
661 +
662 + else:
663 + if not silent:
664 + print "Tag %s does not match with change %s: files do not match." % (labelDetails["label"], change)
665 +
666 + else:
667 + if not silent:
668 + print "Tag %s does not match with change %s: file count is different." % (labelDetails["label"], change)
669
670 def extractFilesInCommitToBranch(self, files, branchPrefix):
671 newFiles = []
@@ -757,6 +797,21 @@ class GitSync(Command):
797 continue
798 self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
799
800 + def getLabels(self):
801 + self.labels = {}
802 +
803 + for output in p4CmdList("labels %s..." % self.globalPrefix):
804 + label = output["label"]
805 + revisions = {}
806 + newestChange = 0
807 + for file in p4CmdList("files //...@%s" % label):
808 + revisions[file["depotFile"]] = file["rev"]
809 + change = int(file["change"])
810 + if change > newestChange:
811 + newestChange = change
812 +
813 + self.labels[newestChange] = [output, revisions]
814 +
815 def run(self, args):
816 self.globalPrefix = ""
817 self.changeRange = ""
@@ -829,6 +884,7 @@ class GitSync(Command):
884 self.globalPrefix += "/"
885
886 self.getUserMap()
887 + self.getLabels();
888
889 if len(self.changeRange) == 0:
890 try: