Skip to content

Commit

Permalink
git p4: rearrange submit template construction
Browse files Browse the repository at this point in the history
Put all items in order as they appear, and add comments.

Signed-off-by: Pete Wyckoff <pw@padd.com>
Acked-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pete Wyckoff authored and Junio C Hamano committed Sep 17, 2012
1 parent f7fbc98 commit 55ac2ed
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ def applyCommit(self, id):
p4_revert(f)
return False

#
# Apply the patch for real, and do add/delete/+x handling.
#
system(applyPatchCmd)

for f in filesToAdd:
Expand All @@ -1215,6 +1218,10 @@ def applyCommit(self, id):
mode = filesToChangeExecBit[f]
setP4ExecBit(f, mode)

#
# Build p4 change description, starting with the contents
# of the git commit message.
#
logMessage = extractLogMessageFromGitCommit(id)
logMessage = logMessage.strip()
(logMessage, jobs) = self.separate_jobs_from_description(logMessage)
Expand All @@ -1223,15 +1230,24 @@ def applyCommit(self, id):
submitTemplate = self.prepareLogMessage(template, logMessage, jobs)

if self.preserveUser:
submitTemplate = submitTemplate + ("\n######## Actual user %s, modified after commit\n" % p4User)
submitTemplate += "\n######## Actual user %s, modified after commit\n" % p4User

if self.checkAuthorship and not self.p4UserIsMe(p4User):
submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail
submitTemplate += "######## Use option --preserve-user to modify authorship.\n"
submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"

separatorLine = "######## everything below this line is just the diff #######\n"

# diff
if os.environ.has_key("P4DIFF"):
del(os.environ["P4DIFF"])
diff = ""
for editedFile in editedFiles:
diff += p4_read_pipe(['diff', '-du',
wildcard_encode(editedFile)])

# new file diff
newdiff = ""
for newFile in filesToAdd:
newdiff += "==== new file ====\n"
Expand All @@ -1242,13 +1258,7 @@ def applyCommit(self, id):
newdiff += "+" + line
f.close()

if self.checkAuthorship and not self.p4UserIsMe(p4User):
submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail
submitTemplate += "######## Use option --preserve-user to modify authorship.\n"
submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"

separatorLine = "######## everything below this line is just the diff #######\n"

# change description file: submitTemplate, separatorLine, diff, newdiff
(handle, fileName) = tempfile.mkstemp()
tmpFile = os.fdopen(handle, "w+")
if self.isWindows:
Expand All @@ -1258,6 +1268,9 @@ def applyCommit(self, id):
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
tmpFile.close()

#
# Let the user edit the change description, then submit it.
#
if self.edit_template(fileName):
# read the edited message and submit
ret = True
Expand Down

0 comments on commit 55ac2ed

Please sign in to comment.