@matheusbsbs / matheus-bagliano / commits / 27d2d8119b
Fork 0

Moved the code from git-p4 submit to figure out the upstream branch point into a separate helper method.

Moved the code from git-p4 submit to figure out the upstream branch point into a separate helper method. Signed-off-by: Simon Hausmann <shausman@trolltech.com>

Simon Hausmann committed Jun 12, 2007 at 14:31 UTC 27d2d8119bf985a0b59152737316f04f871e03f7
1 file changed +26 -19
contrib/fast-import/git-p4
+26 -19
@@ -168,6 +168,28 @@ def gitBranchExists(branch):
168 def gitConfig(key):
169 return read_pipe("git config %s" % key, ignore_error=True).strip()
170
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 +
193 class Command:
194 def __init__(self):
195 self.usage = "usage: %prog [options]"
@@ -494,25 +516,10 @@ class P4Submit(Command):
516 else:
517 return False
518
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
523
524 if self.verbose:
525 print "Origin branch is " + self.origin