Skip to content

Commit 27d2d81

Browse files
committed
Moved the code from git-p4 submit to figure out the upstream branch point
into a separate helper method. Signed-off-by: Simon Hausmann <[email protected]>
1 parent e6b711f commit 27d2d81

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

contrib/fast-import/git-p4

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ def gitBranchExists(branch):
168168
def gitConfig(key):
169169
return read_pipe("git config %s" % key, ignore_error=True).strip()
170170

171+
def findUpstreamBranchPoint():
172+
settings = None
173+
branchPoint = ""
174+
parent = 0
175+
while parent < 65535:
176+
commit = "HEAD~%s" % parent
177+
log = extractLogMessageFromGitCommit(commit)
178+
settings = extractSettingsGitLog(log)
179+
if not settings.has_key("depot-paths"):
180+
parent = parent + 1
181+
continue
182+
183+
names = read_pipe_lines("git name-rev '--refs=refs/remotes/p4/*' '%s'" % commit)
184+
if len(names) <= 0:
185+
continue
186+
187+
# strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
188+
branchPoint = names[0].strip()[len(commit) + 1:]
189+
break
190+
191+
return [branchPoint, settings]
192+
171193
class Command:
172194
def __init__(self):
173195
self.usage = "usage: %prog [options]"
@@ -494,25 +516,10 @@ class P4Submit(Command):
494516
else:
495517
return False
496518

497-
depotPath = ""
498-
parent = 0
499-
while parent < 65535:
500-
commit = "HEAD~%s" % parent
501-
log = extractLogMessageFromGitCommit(commit)
502-
settings = extractSettingsGitLog(log)
503-
if not settings.has_key("depot-paths"):
504-
parent = parent + 1
505-
continue
506-
507-
depotPath = settings['depot-paths'][0]
508-
509-
if len(self.origin) == 0:
510-
names = read_pipe_lines("git name-rev '--refs=refs/remotes/p4/*' '%s'" % commit)
511-
if len(names) > 0:
512-
# strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
513-
self.origin = names[0].strip()[len(commit) + 1:]
514-
515-
break
519+
[upstream, settings] = findUpstreamBranchPoint()
520+
depotPath = settings['depot-paths'][0]
521+
if len(self.origin) == 0:
522+
self.origin = upstream
516523

517524
if self.verbose:
518525
print "Origin branch is " + self.origin

0 commit comments

Comments
 (0)