Added git-p4 rebase convenience
[gitweb.git] / contrib / fast-import / git-p4
index 59c3edae1900c2e0823cf2a9eadd4fc7870b6743..aa85800d697f25518886dcd5d1826eb1eef91958 100755 (executable)
@@ -160,7 +160,7 @@ class P4CleanTags(Command):
         print "%s tags removed." % len(allTags)
         return True
 
-class P4Sync(Command):
+class P4Submit(Command):
     def __init__(self):
         Command.__init__(self)
         self.options = [
@@ -407,7 +407,7 @@ class P4Sync(Command):
 
         return True
 
-class GitSync(Command):
+class P4Sync(Command):
     def __init__(self):
         Command.__init__(self)
         self.options = [
@@ -416,7 +416,7 @@ class GitSync(Command):
                 optparse.make_option("--changesfile", dest="changesFile"),
                 optparse.make_option("--silent", dest="silent", action="store_true"),
                 optparse.make_option("--known-branches", dest="knownBranches"),
-                optparse.make_option("--cache", dest="doCache", action="store_true"),
+                optparse.make_option("--data-cache", dest="dataCache", action="store_true"),
                 optparse.make_option("--command-cache", dest="commandCache", action="store_true")
         ]
         self.description = """Imports from Perforce into a git repository.\n
@@ -500,7 +500,7 @@ class GitSync(Command):
             if knownBranch:
                 continue
 
-            for branch in knownBranches:
+            for branch in self.knownBranches:
                 #if relativePath.startswith(branch):
                 if self.isSubPathOf(relativePath, branch):
                     if len(branches) == 0:
@@ -804,7 +804,11 @@ class GitSync(Command):
     def getLabels(self):
         self.labels = {}
 
-        for output in p4CmdList("labels %s..." % self.globalPrefix):
+        l = p4CmdList("labels %s..." % self.globalPrefix)
+        if len(l) > 0:
+            print "Finding files belonging to labels in %s" % self.globalPrefix
+
+        for output in l:
             label = output["label"]
             revisions = {}
             newestChange = 0
@@ -1039,6 +1043,19 @@ class GitSync(Command):
 
         return True
 
+class P4Rebase(Command):
+    def __init__(self):
+        Command.__init__(self)
+        self.options = [ ]
+        self.description = "Fetches the latest revision from perforce and rebases the current work (branch) against it"
+
+    def run(self, args):
+        sync = P4Sync()
+        sync.run([])
+        print "Rebasing the current branch"
+        system("git rebase p4")
+        return True
+
 class HelpFormatter(optparse.IndentedHelpFormatter):
     def __init__(self):
         optparse.IndentedHelpFormatter.__init__(self)
@@ -1060,8 +1077,9 @@ def printUsage(commands):
 commands = {
     "debug" : P4Debug(),
     "clean-tags" : P4CleanTags(),
-    "submit" : P4Sync(),
-    "sync" : GitSync()
+    "submit" : P4Submit(),
+    "sync" : P4Sync(),
+    "rebase" : P4Rebase()
 }
 
 if len(sys.argv[1:]) == 0: