@@ -168,6 +168,28 @@ def gitBranchExists(branch):
168
168
def gitConfig (key ):
169
169
return read_pipe ("git config %s" % key , ignore_error = True ).strip ()
170
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
+
171
193
class Command :
172
194
def __init__ (self ):
173
195
self .usage = "usage: %prog [options]"
@@ -494,25 +516,10 @@ class P4Submit(Command):
494
516
else :
495
517
return False
496
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
516
523
517
524
if self .verbose :
518
525
print "Origin branch is " + self .origin
0 commit comments