git-p4: Clean up git-p4 submit's log message handling.
Instead of trying to substitute fields in the p4 submit template we now simply replace the description of the submit with the log message of the git commit. Signed-off-by: Simon Hausmann <simon@lst.de>
Simon Hausmann committed
Feb 19, 2008 at 09:29 UTC
edae1e2f407d0e9c6c92333047bc31b27bfdd58f
1 file changed
+16
-16
contrib/fast-import/git-p4
+16
-16
@@ -483,10 +483,6 @@ class P4Submit(Command):
483
self.verbose = False
484
self.isWindows = (platform.system() == "Windows")
485
486
- self.logSubstitutions = {}
487
- self.logSubstitutions["<enter description here>"] = "%log%"
488
- self.logSubstitutions["\tDetails:"] = "\tDetails: %log%"
489
-
486
def check(self):
487
if len(p4CmdList("opened ...")) > 0:
488
die("You have files opened with perforce! Close them before starting the sync.")
@@ -507,26 +503,31 @@ class P4Submit(Command):
503
504
self.config["commits"] = commits
505
506
+ # replaces everything between 'Description:' and the next P4 submit template field with the
507
+ # commit message
508
def prepareLogMessage(self, template, message):
509
result = ""
510
511
+ inDescriptionSection = False
512
+
513
for line in template.split("\n"):
514
if line.startswith("#"):
515
result += line + "\n"
516
continue
517
518
- substituted = False
519
- for key in self.logSubstitutions.keys():
520
- if line.find(key) != -1:
521
- value = self.logSubstitutions[key]
522
- value = value.replace("%log%", message)
523
- if value != "@remove@":
524
- result += line.replace(key, value) + "\n"
525
- substituted = True
526
- break
518
+ if inDescriptionSection:
519
+ if line.startswith("Files:"):
520
+ inDescriptionSection = False
521
+ else:
522
+ continue
523
+ else:
524
+ if line.startswith("Description:"):
525
+ inDescriptionSection = True
526
+ line += "\n"
527
+ for messageLine in message.split("\n"):
528
+ line += "\t" + messageLine + "\n"
529
528
- if not substituted:
529
- result += line + "\n"
530
+ result += line + "\n"
531
532
return result
533
@@ -650,7 +651,6 @@ class P4Submit(Command):
651
logMessage = ""
652
if not self.directSubmit:
653
logMessage = extractLogMessageFromGitCommit(id)
653
- logMessage = logMessage.replace("\n", "\n\t")
654
if self.isWindows:
655
logMessage = logMessage.replace("\n", "\r\n")
656
logMessage = logMessage.strip()