def gitConfig(key):
return read_pipe("git config %s" % key, ignore_error=True).strip()
+def findUpstreamBranchPoint():
+ settings = None
+ branchPoint = ""
+ parent = 0
+ while parent < 65535:
+ commit = "HEAD~%s" % parent
+ log = extractLogMessageFromGitCommit(commit)
+ settings = extractSettingsGitLog(log)
+ if not settings.has_key("depot-paths"):
+ parent = parent + 1
+ continue
+
+ names = read_pipe_lines("git name-rev \"--refs=refs/remotes/p4/*\" \"%s\"" % commit)
+ if len(names) <= 0:
+ continue
+
+ # strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
+ branchPoint = names[0].strip()[len(commit) + 1:]
+ break
+
+ return [branchPoint, settings]
+
class Command:
def __init__(self):
self.usage = "usage: %prog [options]"
system(applyPatchCmd)
for f in filesToAdd:
- system("p4 add %s" % f)
+ system("p4 add \"%s\"" % f)
for f in filesToDelete:
- system("p4 revert %s" % f)
- system("p4 delete %s" % f)
+ system("p4 revert \"%s\"" % f)
+ system("p4 delete \"%s\"" % f)
logMessage = ""
if not self.directSubmit:
else:
return False
- depotPath = ""
- parent = 0
- while parent < 65535:
- commit = "HEAD~%s" % parent
- log = extractLogMessageFromGitCommit(commit)
- settings = extractSettingsGitLog(log)
- if not settings.has_key("depot-paths"):
- parent = parent + 1
- continue
-
- depotPath = settings['depot-paths'][0]
-
- if len(self.origin) == 0:
- names = read_pipe_lines("git name-rev '--refs=refs/remotes/p4/*' '%s'" % commit)
- if len(names) > 0:
- # strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
- self.origin = names[0].strip()[len(commit) + 1:]
-
- break
+ [upstream, settings] = findUpstreamBranchPoint()
+ depotPath = settings['depot-paths'][0]
+ if len(self.origin) == 0:
+ self.origin = upstream
if self.verbose:
print "Origin branch is " + self.origin
self.isWindows = (platform.system() == "Windows")
self.keepRepoPath = False
self.depotPaths = None
+ self.p4BranchesInGit = []
if gitConfig("git-p4.syncFromOrigin") == "false":
self.syncWithOrigin = False
if branch not in branches:
branches[branch] = []
branches[branch].append(file)
+ break
return branches
if not files:
return
- filedata = p4CmdList('print %s' % ' '.join(['"%s#%s"' % (f['path'],
- f['rev'])
- for f in files]))
+ # We cannot put all the files on the command line
+ # OS have limitations on the max lenght of arguments
+ # POSIX says it's 4096 bytes, default for Linux seems to be 130 K.
+ # and all OS from the table below seems to be higher than POSIX.
+ # See http://www.in-ulm.de/~mascheck/various/argmax/
+ argmax = min(4000, os.sysconf('SC_ARG_MAX'))
+ chunk = ''
+ filedata = []
+ for i in xrange(len(files)):
+ f = files[i]
+ chunk += '"%s#%s" ' % (f['path'], f['rev'])
+ if len(chunk) > argmax or i == len(files)-1:
+ data = p4CmdList('print %s' % chunk)
+ if "p4ExitCode" in data[0]:
+ die("Problems executing p4. Error: [%d]." % (data[0]['p4ExitCode']));
+ filedata.extend(data)
+ chunk = ''
j = 0;
contents = {}
return p
def getBranchMapping(self):
+ lostAndFoundBranches = set()
+
for info in p4CmdList("branches"):
details = p4Cmd("branch -o %s" % info["branch"])
viewIdx = 0
if source.startswith(self.depotPaths[0]) and destination.startswith(self.depotPaths[0]):
source = source[len(self.depotPaths[0]):-4]
destination = destination[len(self.depotPaths[0]):-4]
- if destination not in self.knownBranches:
- self.knownBranches[destination] = source
+
+ if destination in self.knownBranches:
+ if not self.silent:
+ print "p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination)
+ print "but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination)
+ continue
+
+ self.knownBranches[destination] = source
+
+ lostAndFoundBranches.discard(destination)
+
if source not in self.knownBranches:
- self.knownBranches[source] = source
+ lostAndFoundBranches.add(source)
+
+
+ for branch in lostAndFoundBranches:
+ self.knownBranches[branch] = branch
def listExistingP4GitBranches(self):
self.p4BranchesInGit = []
self.gitError = importProcess.stderr
if self.revision:
- print "Doing initial import of %s from revision %s" % (' '.join(self.depotPaths), self.revision)
+ print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), self.revision, self.branch)
details = { "user" : "git perforce import user", "time" : int(time.time()) }
details["desc"] = ("Initial import of %s from the state at revision %s"
print "No changes to import!"
return True
+ if not self.silent and not self.detectBranches:
+ print "Import destination: %s" % self.branch
+
self.updatedBranches = set()
cnt = 1
def run(self, args):
sync = P4Sync()
sync.run([])
- print "Rebasing the current branch"
+
+ [upstream, settings] = findUpstreamBranchPoint()
+ if len(upstream) == 0:
+ die("Cannot find upstream branchpoint for rebase")
+
+ # the branchpoint may be p4/foo~3, so strip off the parent
+ upstream = re.sub("~[0-9]+$", "", upstream)
+
+ print "Rebasing the current branch onto %s" % upstream
oldHead = read_pipe("git rev-parse HEAD").strip()
- system("git rebase p4")
+ system("git rebase %s" % upstream)
system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
return True