Skip to content

Commit

Permalink
Merge branch 'mc/git-p4-prepare-p4-only'
Browse files Browse the repository at this point in the history
* mc/git-p4-prepare-p4-only:
  git-p4: Do not include diff in spec file when just preparing p4
  • Loading branch information
Junio C Hamano committed Jun 6, 2014
2 parents 3784ba3 + b4073bb commit eb5398a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
49 changes: 26 additions & 23 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,28 @@ def edit_template(self, template_file):
if response == 'n':
return False

def get_diff_description(self, editedFiles):
# 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"
newdiff += "--- /dev/null\n"
newdiff += "+++ %s\n" % newFile
f = open(newFile, "r")
for line in f.readlines():
newdiff += "+" + line
f.close()

return diff + newdiff

def applyCommit(self, id):
"""Apply one commit, return True if it succeeded."""

Expand Down Expand Up @@ -1398,34 +1420,15 @@ def applyCommit(self, id):
submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"

separatorLine = "######## everything below this line is just the diff #######\n"
if not self.prepare_p4_only:
submitTemplate += separatorLine
submitTemplate += self.get_diff_description(editedFiles)

# 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"
newdiff += "--- /dev/null\n"
newdiff += "+++ %s\n" % newFile
f = open(newFile, "r")
for line in f.readlines():
newdiff += "+" + line
f.close()

# change description file: submitTemplate, separatorLine, diff, newdiff
(handle, fileName) = tempfile.mkstemp()
tmpFile = os.fdopen(handle, "w+")
if self.isWindows:
submitTemplate = submitTemplate.replace("\n", "\r\n")
separatorLine = separatorLine.replace("\n", "\r\n")
newdiff = newdiff.replace("\n", "\r\n")
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
tmpFile.write(submitTemplate)
tmpFile.close()

if self.prepare_p4_only:
Expand Down
3 changes: 2 additions & 1 deletion t/t9807-git-p4-submit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' '
git commit -m "prep only add" &&
git p4 submit --prepare-p4-only >out &&
test_i18ngrep "prepared for submission" out &&
test_i18ngrep "must be deleted" out
test_i18ngrep "must be deleted" out &&
! test_i18ngrep "everything below this line is just the diff" out
) &&
(
cd "$cli" &&
Expand Down

0 comments on commit eb5398a

Please sign in to comment.