@matheusbsbs / matheus-bagliano / commits / 179caebff4
Fork 0

Brand new smart incremental import that doesn't need tags or git repo-config :)

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed Mar 22, 2007 at 22:17 UTC 179caebff4a917dc35c8166ec183bc5c76df53e1
2 files changed +33 -11
contrib/fast-import/git-p4
+31 -7
@@ -84,7 +84,9 @@ def extractDepotPathAndChangeFromGitLog(log):
84 return values.get("depot-path"), values.get("change")
85
86 def gitBranchExists(branch):
87 - return os.system("git-rev-parse %s 2>/dev/null >/dev/null") == 0
87 + if os.system("git-rev-parse %s 2>/dev/null >/dev/null" % branch) == 0:
88 + return True
89 + return False
90
91 class Command:
92 def __init__(self):
@@ -706,17 +708,40 @@ class GitSync(Command):
708 self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
709
710 def run(self, args):
711 + self.globalPrefix = ""
712 + self.changeRange = ""
713 + self.initialParent = ""
714 + self.tagLastChange = True
715 +
716 if len(self.branch) == 0:
717 self.branch = "p4"
718 + if len(args) == 0:
719 + if not gitBranchExists(self.branch) and gitBranchExists("origin"):
720 + if not self.silent:
721 + print "Creating %s branch in git repository based on origin" % self.branch
722 + system("git branch %s origin" % self.branch)
723 +
724 + [self.previousDepotPath, p4Change] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit(self.branch))
725 + if len(self.previousDepotPath) > 0 and len(p4Change) > 0:
726 + p4Change = int(p4Change) + 1
727 + self.globalPrefix = self.previousDepotPath
728 + self.changeRange = "@%s,#head" % p4Change
729 + self.initialParent = self.branch
730 + self.tagLastChange = False
731 + if not self.silent:
732 + print "Performing incremental import into %s git branch" % self.branch
733
734 self.branch = "refs/heads/" + self.branch
713 - self.globalPrefix = self.previousDepotPath = os.popen("git-repo-config --get p4.depotpath").read()
735 +
736 + if len(self.globalPrefix) == 0:
737 + self.globalPrefix = self.previousDepotPath = os.popen("git-repo-config --get p4.depotpath").read()
738 +
739 if len(self.globalPrefix) != 0:
740 self.globalPrefix = self.globalPrefix[:-1]
741
742 if len(args) == 0 and len(self.globalPrefix) != 0:
743 if not self.silent:
719 - print "[using previously specified depot path %s]" % self.globalPrefix
744 + print "Depot path: %s" % self.globalPrefix
745 elif len(args) != 1:
746 return False
747 else:
@@ -725,10 +750,8 @@ class GitSync(Command):
750 sys.exit(1)
751 self.globalPrefix = args[0]
752
728 - self.changeRange = ""
753 self.revision = ""
754 self.users = {}
731 - self.initialParent = ""
755 self.lastChange = 0
756 self.initialTag = ""
757
@@ -890,8 +913,9 @@ class GitSync(Command):
913 if not self.silent:
914 print ""
915
893 - self.gitStream.write("reset refs/tags/p4/%s\n" % self.lastChange)
894 - self.gitStream.write("from %s\n\n" % self.branch);
916 + if self.tagLastChange:
917 + self.gitStream.write("reset refs/tags/p4/%s\n" % self.lastChange)
918 + self.gitStream.write("from %s\n\n" % self.branch);
919
920
921 self.gitStream.close()
contrib/fast-import/git-p4.txt
+2 -4
@@ -38,11 +38,9 @@ Incremental Imports
38 After an initial import you can easily synchronize your git repository with
39 newer changes from the Perforce depot by just calling
40
41 - git-p4.p4 sync
41 + git-p4 sync
42
43 -in your git repository. git-p4 stores the depot path of the original import in
44 -the .git/config file and remembers the last imported p4 revision as a git tag
45 -called p4/<changenum> .
43 +in your git repository.
44
45 It is recommended to run 'git repack -a -d -f' from time to time when using
46 incremental imports to optimally combine the individual git packs that each