git-p4: Fix git-p4 submit to include only changed files in the perforce submit template.
Parse the files section in the "p4 change -o" output and remove lines with file changes in unrelated depot paths. Signed-off-by: Simon Hausmann <simon@lst.de> Signed-off-by: Marius Storm-Olsen <marius@trolltech.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Simon Hausmann committed
Aug 8, 2007 at 17:06 UTC
ea99c3ae0e2cecaa0950532385319d60c59e97e0
1 file changed
+30
-6
contrib/fast-import/git-p4
+30
-6
@@ -390,6 +390,30 @@ class P4Submit(Command):
390
391
return result
392
393
+ def prepareSubmitTemplate(self):
394
+ # remove lines in the Files section that show changes to files outside the depot path we're committing into
395
+ template = ""
396
+ inFilesSection = False
397
+ for line in read_pipe_lines("p4 change -o"):
398
+ if inFilesSection:
399
+ if line.startswith("\t"):
400
+ # path starts and ends with a tab
401
+ path = line[1:]
402
+ lastTab = path.rfind("\t")
403
+ if lastTab != -1:
404
+ path = path[:lastTab]
405
+ if not path.startswith(self.depotPath):
406
+ continue
407
+ else:
408
+ inFilesSection = False
409
+ else:
410
+ if line.startswith("Files:"):
411
+ inFilesSection = True
412
+
413
+ template += line
414
+
415
+ return template
416
+
417
def applyCommit(self, id):
418
if self.directSubmit:
419
print "Applying local change in working directory/index"
@@ -467,7 +491,7 @@ class P4Submit(Command):
491
logMessage = logMessage.replace("\n", "\r\n")
492
logMessage = logMessage.strip()
493
470
- template = read_pipe("p4 change -o")
494
+ template = self.prepareSubmitTemplate()
495
496
if self.interactive:
497
submitTemplate = self.prepareLogMessage(template, logMessage)
@@ -558,24 +582,24 @@ class P4Submit(Command):
582
return False
583
584
[upstream, settings] = findUpstreamBranchPoint()
561
- depotPath = settings['depot-paths'][0]
585
+ self.depotPath = settings['depot-paths'][0]
586
if len(self.origin) == 0:
587
self.origin = upstream
588
589
if self.verbose:
590
print "Origin branch is " + self.origin
591
568
- if len(depotPath) == 0:
592
+ if len(self.depotPath) == 0:
593
print "Internal error: cannot locate perforce depot path from existing branches"
594
sys.exit(128)
595
572
- self.clientPath = p4Where(depotPath)
596
+ self.clientPath = p4Where(self.depotPath)
597
598
if len(self.clientPath) == 0:
575
- print "Error: Cannot locate perforce checkout of %s in client view" % depotPath
599
+ print "Error: Cannot locate perforce checkout of %s in client view" % self.depotPath
600
sys.exit(128)
601
578
- print "Perforce checkout for depot path %s located at %s" % (depotPath, self.clientPath)
602
+ print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
603
self.oldWorkingDirectory = os.getcwd()
604
605
if self.directSubmit: