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
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