Make git-p4 submit detect the correct reference (origin) branch when working with multi-branch imports.
Make git-p4 submit detect the correct reference (origin) branch when working with multi-branch imports. Signed-off-by: Simon Hausmann <simon@lst.de>
Simon Hausmann committed
Jun 7, 2007 at 22:54 UTC
a3fdd57901bfe1014c4a48e13815d80f1f0e8577
1 file changed
+24
-14
contrib/fast-import/git-p4
+24
-14
@@ -156,7 +156,8 @@ def extractSettingsGitLog(log):
156
paths = values.get("depot-paths")
157
if not paths:
158
paths = values.get("depot-path")
159
- values['depot-paths'] = paths.split(',')
159
+ if paths:
160
+ values['depot-paths'] = paths.split(',')
161
return values
162
163
def gitBranchExists(branch):
@@ -494,12 +495,27 @@ class P4Submit(Command):
495
return False
496
497
depotPath = ""
497
- settings = None
498
- if gitBranchExists("p4"):
499
- settings = extractSettingsGitLog(extractLogMessageFromGitCommit("p4"))
500
- if len(depotPath) == 0 and gitBranchExists("origin"):
501
- settings = extractSettingsGitLog(extractLogMessageFromGitCommit("origin"))
502
- depotPath = settings['depot-paths'][0]
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
516
+
517
+ if self.verbose:
518
+ print "Origin branch is " + self.origin
519
520
if len(depotPath) == 0:
521
print "Internal error: cannot locate perforce depot path from existing branches"
@@ -530,12 +546,6 @@ class P4Submit(Command):
546
if response == "y" or response == "yes":
547
system("p4 sync ...")
548
533
- if len(self.origin) == 0:
534
- if gitBranchExists("p4"):
535
- self.origin = "p4"
536
- else:
537
- self.origin = "origin"
538
-
549
if self.reset:
550
self.firstTime = True
551
@@ -969,7 +979,7 @@ class P4Sync(Command):
979
print "creating %s" % remoteHead
980
update = True
981
else:
972
- settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
982
+ settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
983
if settings.has_key('change') > 0:
984
if settings['depot-paths'] == original['depot-paths']:
985
originP4Change = int(original['change'])