optparse.make_option("--silent", dest="silent", action="store_true"),
optparse.make_option("--known-branches", dest="knownBranches"),
optparse.make_option("--data-cache", dest="dataCache", action="store_true"),
- optparse.make_option("--command-cache", dest="commandCache", action="store_true")
+ optparse.make_option("--command-cache", dest="commandCache", action="store_true"),
+ optparse.make_option("--detect-labels", dest="detectLabels", action="store_true")
]
self.description = """Imports from Perforce into a git repository.\n
example:
self.committedChanges = Set()
self.branch = ""
self.detectBranches = False
+ self.detectLabels = False
self.changesFile = ""
+ self.tagLastChange = True
def p4File(self, depotPath):
return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
def getLabels(self):
self.labels = {}
- for output in p4CmdList("labels %s..." % self.globalPrefix):
+ l = p4CmdList("labels %s..." % self.globalPrefix)
+ if len(l) > 0 and not self.silent:
+ print "Finding files belonging to labels in %s" % self.globalPrefix
+
+ for output in l:
label = output["label"]
revisions = {}
newestChange = 0
self.globalPrefix = ""
self.changeRange = ""
self.initialParent = ""
- self.tagLastChange = True
if len(self.branch) == 0:
self.branch = "p4"
self.globalPrefix += "/"
self.getUserMap()
- self.getLabels();
+ self.labels = {}
+ if self.detectLabels:
+ self.getLabels();
if len(self.changeRange) == 0:
try:
newestRevision = change
if info["action"] == "delete":
- fileCnt = fileCnt + 1
+ # don't increase the file cnt, otherwise details["depotFile123"] will have gaps!
+ #fileCnt = fileCnt + 1
continue
for prop in [ "depotFile", "rev", "action", "type" ]:
if len(changes) == 0:
if not self.silent:
print "no changes to import!"
- sys.exit(1)
+ return True
cnt = 1
for change in changes:
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"
+ oldHead = os.popen("git rev-parse HEAD").read()[:-1]
+ system("git rebase p4")
+ system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
+ return True
+
+class P4Clone(P4Sync):
+ def __init__(self):
+ P4Sync.__init__(self)
+ self.description = "Creates a new git repository and imports from Perforce into it"
+ self.usage = "usage: %prog [options] //depot/path[@revRange] [directory]"
+ self.needsGit = False
+ self.tagLastChange = False
+
+ def run(self, args):
+ if len(args) < 1:
+ return False
+ depotPath = args[0]
+ dir = ""
+ if len(args) == 2:
+ dir = args[1]
+ elif len(args) > 2:
+ return False
+
+ if not depotPath.startswith("//"):
+ return False
+
+ if len(dir) == 0:
+ dir = depotPath
+ atPos = dir.rfind("@")
+ if atPos != -1:
+ dir = dir[0:atPos]
+ hashPos = dir.rfind("#")
+ if hashPos != -1:
+ dir = dir[0:hashPos]
+
+ if dir.endswith("..."):
+ dir = dir[:-3]
+
+ if dir.endswith("/"):
+ dir = dir[:-1]
+
+ slashPos = dir.rfind("/")
+ if slashPos != -1:
+ dir = dir[slashPos + 1:]
+
+ print "Importing from %s into %s" % (depotPath, dir)
+ os.makedirs(dir)
+ os.chdir(dir)
+ system("git init")
+ if not P4Sync.run(self, [depotPath]):
+ return False
+ os.wait()
+ if self.branch != "master":
+ system("git branch master p4")
+ system("git checkout -f")
+ return True
+
class HelpFormatter(optparse.IndentedHelpFormatter):
def __init__(self):
optparse.IndentedHelpFormatter.__init__(self)
"debug" : P4Debug(),
"clean-tags" : P4CleanTags(),
"submit" : P4Submit(),
- "sync" : P4Sync()
+ "sync" : P4Sync(),
+ "rebase" : P4Rebase(),
+ "clone" : P4Clone()
}
if len(sys.argv[1:]) == 0: