Skip to content

Commit

Permalink
git-p4: Clean up git-p4 submit's log message handling.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Simon Hausmann committed Feb 27, 2008
1 parent 4b61b5c commit edae1e2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions contrib/fast-import/git-p4
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,6 @@ class P4Submit(Command):
self.verbose = False
self.isWindows = (platform.system() == "Windows")

self.logSubstitutions = {}
self.logSubstitutions["<enter description here>"] = "%log%"
self.logSubstitutions["\tDetails:"] = "\tDetails: %log%"

def check(self):
if len(p4CmdList("opened ...")) > 0:
die("You have files opened with perforce! Close them before starting the sync.")
Expand All @@ -507,26 +503,31 @@ class P4Submit(Command):

self.config["commits"] = commits

# replaces everything between 'Description:' and the next P4 submit template field with the
# commit message
def prepareLogMessage(self, template, message):
result = ""

inDescriptionSection = False

for line in template.split("\n"):
if line.startswith("#"):
result += line + "\n"
continue

substituted = False
for key in self.logSubstitutions.keys():
if line.find(key) != -1:
value = self.logSubstitutions[key]
value = value.replace("%log%", message)
if value != "@remove@":
result += line.replace(key, value) + "\n"
substituted = True
break
if inDescriptionSection:
if line.startswith("Files:"):
inDescriptionSection = False
else:
continue
else:
if line.startswith("Description:"):
inDescriptionSection = True
line += "\n"
for messageLine in message.split("\n"):
line += "\t" + messageLine + "\n"

if not substituted:
result += line + "\n"
result += line + "\n"

return result

Expand Down Expand Up @@ -650,7 +651,6 @@ class P4Submit(Command):
logMessage = ""
if not self.directSubmit:
logMessage = extractLogMessageFromGitCommit(id)
logMessage = logMessage.replace("\n", "\n\t")
if self.isWindows:
logMessage = logMessage.replace("\n", "\r\n")
logMessage = logMessage.strip()
Expand Down

0 comments on commit edae1e2

Please sign in to comment.