git p4: submit conflict handling
cover git p4: submit conflict handling
These patches rework how git p4 deals with conflicts that arise during a "git p4 submit". These may arise due to changes that happened in p4 since the last "git p4 sync".
Luke: I especially wanted to get this out as you suggested that you had a different way of dealing with skipped commits.
The part that needs the most attention is the interaction loop that happens when a commit failed. Currently, three options are offered:
[s]kip this commit, but continue to apply others [a]pply the commit forcefully, generating .rej files [w]rite the commit to a patch.txt file
and the implicit <ctrl-c> to stop
After this series, it offers two:
[c]ontinue to apply others
[q]uit to stop
This feels more natural to me, and I like the term "continue" rather than "skip" as it matches what rebase uses. I'd like to know what others think of the new flow.
Other observable changes are new command-line options:
Alias -v for --verbose, similar to other git commands.
The --dry-run option addresses Luke's concern in
http://thread.gmane.org/gmane.comp.version-control.git/201004/focus=201022
when I removed an unused "self.interactive" variable that did a similar thing if you edited the code. It prints commits that would be applied to p4.
Option --prepare-p4-only is similar to --dry-run, in that it does not submit anything to p4, but it does prepare the p4 workspace, then prints long instructions about how to submit everything properly. It also serves, perhaps, as a replacement for the [a]pply option in the submit-conflict loop.
Pete Wyckoff (12):
git p4 test: remove bash-ism of combined export/assignment git p4 test: use p4d -L option to suppress log messages git p4: gracefully fail if some commits could not be applied git p4: remove submit failure options [a]pply and [w]rite git p4: move conflict prompt into run, use [c]ontinue and [q]uit git p4: standardize submit cancel due to unchanged template git p4: test clean-up after failed submit, fix added files git p4: rearrange submit template construction
git p4: revert deleted files after submit cancel
git p4: accept -v for --verbose
git p4: add submit --dry-run option
git p4: add submit --prepare-p4-only option
Documentation/git-p4.txt | 13 +- git-p4.py | 213 +++++++++++++++------ t/lib-git-p4.sh | 10 +- t/t9805-git-p4-skip-submit-edit.sh | 2 +- t/t9807-git-p4-submit.sh | 65 +++++++ t/t9810-git-p4-rcs.sh | 50 +---- t/t9815-git-p4-submit-fail.sh | 367 +++++++++++++++++++++++++++++++++++++ 7 files changed, 612 insertions(+), 108 deletions(-) create mode 100755 t/t9815-git-p4-submit-fail.sh
Signature · 1 line
1.7.11.4
PATCH 1/12 git p4 test: remove bash-ism of combined export/assignment
--- t/lib-git-p4.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
t/lib-git-p4.sh +4 -3
@@ -26,9 +26,10 @@ testid=${this_test#t} git_p4_test_start=9800 P4DPORT=$((10669 + ($testid - $git_p4_test_start))) -export P4PORT=localhost:$P4DPORT -export P4CLIENT=client -export P4EDITOR=: +P4PORT=localhost:$P4DPORT +P4CLIENT=client +P4EDITOR=: +export P4PORT P4CLIENT P4EDITOR db="$TRASH_DIRECTORY/db" cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli")
Signature · 1 line
1.7.11.4
Re: [PATCH 01/12] git p4 test: remove bash-ism of combined export/assignment
Thanks.
PATCH 2/12 git p4 test: use p4d -L option to suppress log messages
In reply to Pete WyckoffSend p4d output to a logfile in the $TRASH_DIRECTORY. Its messages add no value to testing.
--- t/lib-git-p4.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/lib-git-p4.sh +2 -1
@@ -35,12 +35,13 @@ db="$TRASH_DIRECTORY/db" cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli") git="$TRASH_DIRECTORY/git" pidfile="$TRASH_DIRECTORY/p4d.pid" +logfile="$TRASH_DIRECTORY/p4d.log" start_p4d() { mkdir -p "$db" "$cli" "$git" && rm -f "$pidfile" && ( - p4d -q -r "$db" -p $P4DPORT & + p4d -q -r "$db" -p $P4DPORT -L "$logfile" & echo $! >"$pidfile" ) &&
Signature · 1 line
1.7.11.4
Re: [PATCH 02/12] git p4 test: use p4d -L option to suppress log messages
Quoted 2 lines · Pete Wyckoff
Send p4d output to a logfile in the $TRASH_DIRECTORY. Its messages add no value to testing.
I'm not totally sold on this; I still fairly frequently see weird errors from p4d and these help me work out what's going on. For example, at the moment if you run a test too quickly after the last one, then it won't start up (or something like that).
The problem with hiding the error messages is that I don't think I will think to look in this log file if tests start failing.
Quoted 25 lines
Signed-off-by Pete Wyckoff<[email protected]>--- t/lib-git-p4.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)t/lib-git-p4.sh +2
-1@@ -35,12 +35,13 @@ db="$TRASH_DIRECTORY/db" cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli") git="$TRASH_DIRECTORY/git" pidfile="$TRASH_DIRECTORY/p4d.pid" +logfile="$TRASH_DIRECTORY/p4d.log" start_p4d() { mkdir -p "$db" "$cli" "$git"&& rm -f "$pidfile"&& ( - p4d -q -r "$db" -p $P4DPORT& + p4d -q -r "$db" -p $P4DPORT -L "$logfile"& echo $!>"$pidfile" )&&
PATCH 3/12 git p4: gracefully fail if some commits could not be applied
In reply to Pete WyckoffIf a commit fails to apply cleanly to the p4 tree, an interactive prompt asks what to do next. In all cases (skip, apply, write), the behavior after the prompt had a few problems.
Change it so that it does not claim erroneously that all commits were applied. Instead list the set of the patches under consideration, and mark with an asterisk those that were applied successfully. Like this example:
Applying 592f1f9 line5 in file1 will conflict
...
Unfortunately applying the change failed!
What do you want to do?
[s]kip this patch / [a]pply the patch forcibly and with .rej files / [w]rite the patch to a file (patch.txt) s Skipping! Good luck with the next patches...
//depot/file1#4 - was edit, reverted
Applying b8db1c6 okay_commit_after_skip
...
Change 6 submitted.
Applied only the commits marked with '*':
592f1f9 line5 in file1 will conflict
* b8db1c6 okay_commit_after_skip
Do not try to sync and rebase unless all patches were applied. If there was a conflict during the submit, there is sure to be one at the rebase. Let the user to do the sync and rebase manually.
This changes how a couple tets in t9810-git-p4-rcs.sh behave:
- git p4 now does not leave files open and edited in the client
- If a git commit contains a change to a file that was deleted in p4, the test used to check that the sync/rebase loop happened after the failure to apply the change. Since now sync/rebase does not happen after failure, do not test this. Normal rebase machinery, outside of git p4, will let rebase --skip work.
--- git-p4.py | 42 ++++++++++++++----- t/t9810-git-p4-rcs.sh | 50 ++--------------------- t/t9815-git-p4-submit-fail.sh | 93 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 56 deletions(-) create mode 100755 t/t9815-git-p4-submit-fail.sh
git-p4.py +33 -9
@@ -1088,7 +1088,10 @@ class P4Submit(Command, P4UserMap): return False def applyCommit(self, id): - print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id)) + """Apply one commit, return True if it succeeded.""" + + print "Applying", read_pipe(["git", "show", "-s", + "--format=format:%h %s", id]) (p4User, gitEmail) = self.p4UserForCommit(id)
@@ -1206,7 +1209,7 @@ class P4Submit(Command, P4UserMap): p4_revert(f) for f in filesToAdd: os.remove(f) - return + return False elif response == "a": os.system(applyPatchCmd) if len(filesToAdd) > 0:
@@ -1312,6 +1315,7 @@ class P4Submit(Command, P4UserMap): os.remove(f) os.remove(fileName) + return True # success # Export git tags as p4 labels. Create a p4 label and then tag # with that.
@@ -1487,14 +1491,16 @@ class P4Submit(Command, P4UserMap): if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true": self.diffOpts += " --find-copies-harder" - while len(commits) > 0: - commit = commits[0] - commits = commits[1:] - self.applyCommit(commit) + applied = [] + for commit in commits: + ok = self.applyCommit(commit) + if ok: + applied.append(commit) - if len(commits) == 0: - print "All changes applied!" - chdir(self.oldWorkingDirectory) + chdir(self.oldWorkingDirectory) + + if len(commits) == len(applied): + print "All commits applied!" sync = P4Sync() sync.run([])
@@ -1502,6 +1508,20 @@ class P4Submit(Command, P4UserMap): rebase = P4Rebase() rebase.rebase() + else: + if len(applied) == 0: + print "No commits applied." + else: + print "Applied only the commits marked with '*':" + for c in commits: + if c in applied: + star = "*" + else: + star = " " + print star, read_pipe(["git", "show", "-s", + "--format=format:%h %s", c]) + print "You will have to do 'git p4 sync' and rebase." + if gitConfig("git-p4.exportLabels", "--bool") == "true": self.exportLabels = True
@@ -1512,6 +1532,10 @@ class P4Submit(Command, P4UserMap): missingGitTags = gitTags - p4Labels self.exportGitTags(missingGitTags) + # exit with error unless everything applied perfecly + if len(commits) != len(applied): + sys.exit(1) + return True class View(object):
t/t9810-git-p4-rcs.sh +3 -47
70 lines not on this page · raw message
t/t9815-git-p4-submit-fail.sh new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
1.7.11.4
Re: [PATCH 03/12] git p4: gracefully fail if some commits could not be applied
Am 8/17/2012 1:35, schrieb Pete Wyckoff:
t/t9815-git-p4-submit-fail.sh line 2
Quoted 4 lines
+++
b/t/t9815-git-p4-submit-fail.sht/t9815-git-p4-submit-fail.sh new file +2
-0@@ -0,0 +1,93 @@ + +#!/bin/sh
This initial blank line is an accident, right? ;-)
-- Hannes
Re: [PATCH 03/12] git p4: gracefully fail if some commits could not be applied
[email protected] wrote on Fri, 17 Aug 2012 08:53 +0200:
Quoted 7 lines
Am 8/17/2012 1:35, schrieb Pete Wyckoff:
t/t9815-git-p4-submit-fail.sh line 2
Quoted 4 lines
+++
b/t/t9815-git-p4-submit-fail.sht/t9815-git-p4-submit-fail.sh new file +2
-0@@ -0,0 +1,93 @@ + +#!/bin/shThis initial blank line is an accident, right? ;-)
Yes, the paint on the font was still wet. Thanks!
-- Pete
Re: [PATCH 03/12] git p4: gracefully fail if some commits could not be applied
In reply to Pete WyckoffQuoted 8 lines · Pete Wyckoff
If a commit fails to apply cleanly to the p4 tree, an interactive prompt asks what to do next. In all cases (skip, apply, write), the behavior after the prompt had a few problems.
Change it so that it does not claim erroneously that all commits were applied. Instead list the set of the patches under consideration, and mark with an asterisk those that were applied successfully. Like this example:
I could be wrong about this, but this change doesn't seem to help out with "git p4 rebase", which for me at least, is where the conflicts usually get picked up first.
I modified a file in p4, and the same file in git, and then did 'git p4 rebase' and it just failed in the rebase in the usual way with a big 'ol python backtrace.
If this patch series is intended to sort out conflict handling, then it needs a bit more work.
(Says Luke, trying not to sound too confrontational, as I'm rubbish at handling conflict....)
Thanks!
Luke
Re: [PATCH 03/12] git p4: gracefully fail if some commits could not be applied
[email protected] wrote on Fri, 17 Aug 2012 08:21 +0100:
Quoted 5 lines · Pete Wyckoff
Quoted 4 lines
If a commit fails to apply cleanly to the p4 tree, an interactive prompt asks what to do next. In all cases (skip, apply, write), the behavior after the prompt had a few problems.
Quoted 8 lines
Quoted 4 lines
Change it so that it does not claim erroneously that all commits were applied. Instead list the set of the patches under consideration, and mark with an asterisk those that were applied successfully. Like this example:
I could be wrong about this, but this change doesn't seem to help out with "git p4 rebase", which for me at least, is where the conflicts usually get picked up first.
Right, this is only about the submit path. I wasn't thinking about rebase when I worked on this code (or read your message about rebase ORIG_HEAD).
Quoted 3 lines
I modified a file in p4, and the same file in git, and then did 'git p4 rebase' and it just failed in the rebase in the usual way with a big 'ol python backtrace.
The backtraces are not pretty, and should be fixed. I confess I never use git p4 rebase, because it should be only git p4 sync + git rebase @{u}. There's no conflict handling at all in the git p4 code.
Quoted 2 lines
If this patch series is intended to sort out conflict handling, then it needs a bit more work.
This patch series tries to fix the conflict handling in the submit path only. Have to start somewhere.
What do you think we might do about the rebase path? It feels like a situation that belongs to native git. Are there p4-specific things like $Id$ tags that need help? We could just catch the errors from git rebase more gracefully, or exec directly into git rebase.
-- Pete
PATCH 4/12 git p4: remove submit failure options [a]pply and [w]rite
In reply to Pete WyckoffWhen a patch failed to apply, these interactive options offered to:
1) apply the patch anyway, leaving reject (.rej) files around, or,
2) write the patch to a file (patch.txt)
In both cases it suggested to invoke "git p4 submit --continue", an unimplemented option.
While manually fixing the rejects and submitting the result might work, there are many steps that must be done to the job properly:
* apply patch
* invoke p4 add and delete
* change executable bits
* p4 sync -f renamed/copied files
* extract commit message into p4 change description and move Jobs lines out of description section
* set changelist owner for --preserve-user
Plus the following manual sync/rebase will cause conflicts too, which must be resolved once again.
Drop these workflows. Instead users should do a sync/rebase in git, fix the conflicts there, and do a clean "git p4 submit".
--- git-p4.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
git-p4.py +2 -18
@@ -1200,9 +1200,8 @@ class P4Submit(Command, P4UserMap): if not patch_succeeded: print "What do you want to do?" response = "x" - while response != "s" and response != "a" and response != "w": - response = raw_input("[s]kip this patch / [a]pply the patch forcibly " - "and with .rej files / [w]rite the patch to a file (patch.txt) ") + while response != "s": + response = raw_input("[s]kip this patch ") if response == "s": print "Skipping! Good luck with the next patches..." for f in editedFiles:
@@ -1210,21 +1209,6 @@ class P4Submit(Command, P4UserMap): for f in filesToAdd: os.remove(f) return False - elif response == "a": - os.system(applyPatchCmd) - if len(filesToAdd) > 0: - print "You may also want to call p4 add on the following files:" - print " ".join(filesToAdd) - if len(filesToDelete): - print "The following files should be scheduled for deletion with p4 delete:" - print " ".join(filesToDelete) - die("Please resolve and submit the conflict manually and " - + "continue afterwards with git p4 submit --continue") - elif response == "w": - system(diffcmd + " > patch.txt") - print "Patch saved to patch.txt in %s !" % self.clientPath - die("Please resolve and submit the conflict manually and " - "continue afterwards with git p4 submit --continue") system(applyPatchCmd)
Signature · 1 line
1.7.11.4
PATCH 5/12 git p4: move conflict prompt into run, use [c]ontinue and [q]uit
In reply to Pete WyckoffWhen applying a commit to the p4 workspace fails, a prompt asks what to do next. This belongs up in run() instead of in applyCommit(), where run() can notice, for instance, that the prompt is unnecessary because this is the last commit.
Remove the [s]kip option in favor of two new ones: [c]ontinue and [q]uit. Continue means the same as skip, but is more similar to the --continue option of rebase. Option [q]uit stops processing. This is an improvement on the current requirement of ctrl-c, s an explicit "quit" gives git p4 a chance to clean up, show the applied-commit summary, and do tag export.
--- git-p4.py | 41 +++++++++++++++++++++++++++++------------ t/t9815-git-p4-submit-fail.sh | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 19 deletions(-)
git-p4.py +29 -12
@@ -1198,17 +1198,11 @@ class P4Submit(Command, P4UserMap): patch_succeeded = True if not patch_succeeded: - print "What do you want to do?" - response = "x" - while response != "s": - response = raw_input("[s]kip this patch ") - if response == "s": - print "Skipping! Good luck with the next patches..." - for f in editedFiles: - p4_revert(f) - for f in filesToAdd: - os.remove(f) - return False + for f in editedFiles: + p4_revert(f) + for f in filesToAdd: + os.remove(f) + return False system(applyPatchCmd)
@@ -1475,11 +1469,34 @@ class P4Submit(Command, P4UserMap): if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true": self.diffOpts += " --find-copies-harder" + # + # Apply the commits, one at a time. On failure, ask if should + # continue to try the rest of the patches, or quit. + # applied = [] - for commit in commits: + last = len(commits) - 1 + for i, commit in enumerate(commits): ok = self.applyCommit(commit) if ok: applied.append(commit) + else: + if i < last: + quit = False + while True: + print "What do you want to do?" + response = raw_input( + "[c]ontinue to submit other patches, or [q]uit? ") + if not response: + continue + if response[0] == "c": + print "Continuing to submit the rest of the patches" + break + if response[0] == "q": + print "Quitting" + quit = True + break + if quit: + break chdir(self.oldWorkingDirectory)
t/t9815-git-p4-submit-fail.sh +30 -7
@@ -19,7 +19,7 @@ test_expect_success 'init depot' ' ) ' -test_expect_success 'conflict on one commit, skip' ' +test_expect_success 'conflict on one commit' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && (
@@ -35,12 +35,12 @@ test_expect_success 'conflict on one commit, skip' ' echo line3 >>file1 && git add file1 && git commit -m "line3 in file1 will conflict" && - echo s | test_expect_code 1 git p4 submit >out && + test_expect_code 1 git p4 submit >out && test_i18ngrep "No commits applied" out ) ' -test_expect_success 'conflict on second of two commits, skip' ' +test_expect_success 'conflict on second of two commits' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && (
@@ -58,12 +58,12 @@ test_expect_success 'conflict on second of two commits, skip' ' echo line4 >>file1 && git add file1 && git commit -m "line4 in file1 will conflict" && - echo s | test_expect_code 1 git p4 submit >out && + test_expect_code 1 git p4 submit >out && test_i18ngrep "Applied only the commits" out ) ' -test_expect_success 'conflict on first of two commits, skip' ' +test_expect_success 'conflict on first of two commits, continue' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && (
@@ -80,12 +80,35 @@ test_expect_success 'conflict on first of two commits, skip' ' git add file1 && git commit -m "line5 in file1 will conflict" && # but this commit is okay - test_commit "okay_commit_after_skip" && - echo s | test_expect_code 1 git p4 submit >out && + test_commit "okay_commit_after_continue" && + echo c | test_expect_code 1 git p4 submit >out && test_i18ngrep "Applied only the commits" out ) ' +test_expect_success 'conflict on first of two commits, quit' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$cli" && + p4 open file1 && + echo line7 >>file1 && + p4 submit -d "line7 in file1" + ) && + ( + cd "$git" && + git config git-p4.skipSubmitEdit true && + # this submit should cause a conflict + echo line8 >>file1 && + git add file1 && + git commit -m "line8 in file1 will conflict" && + # but this commit is okay + test_commit "okay_commit_after_quit" && + echo q | test_expect_code 1 git p4 submit >out && + test_i18ngrep "No commits applied" out + ) +' + test_expect_success 'kill p4d' ' kill_p4d '
Signature · 1 line
1.7.11.4
PATCH 6/12 git p4: standardize submit cancel due to unchanged template
In reply to Pete WyckoffWhen editing the submit template, if no change was made to it, git p4 offers a prompt "Submit anyway?". Answering "no" cancels the submit.
Previously, a "no" answer behaves like a "[s]kip" answer to the failed-patch prompt, in that it proceeded to try to apply the rest of the commits. Instead, put users back into the new "[s]kip / [c]ontinue" loop so that they can decide. This makes both cases of patch failure behave identically.
The return code of git p4 after a "no" answer is now the same as that for a "skip" due to failed patch; update a test to understand this.
--- git-p4.py | 4 +++- t/t9805-git-p4-skip-submit-edit.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
git-p4.py +3 -1
@@ -1262,6 +1262,7 @@ class P4Submit(Command, P4UserMap): if self.edit_template(fileName): # read the edited message and submit + ret = True tmpFile = open(fileName, "rb") message = tmpFile.read() tmpFile.close()
@@ -1285,6 +1286,7 @@ class P4Submit(Command, P4UserMap): else: # skip this patch + ret = False print "Submission cancelled, undoing p4 changes." for f in editedFiles: p4_revert(f)
@@ -1293,7 +1295,7 @@ class P4Submit(Command, P4UserMap): os.remove(f) os.remove(fileName) - return True # success + return ret # Export git tags as p4 labels. Create a p4 label and then tag # with that.
t/t9805-git-p4-skip-submit-edit.sh +1 -1
@@ -38,7 +38,7 @@ test_expect_success 'no config, unedited, say no' ' cd "$git" && echo line >>file1 && git commit -a -m "change 3 (not really)" && - printf "bad response\nn\n" | git p4 submit && + printf "bad response\nn\n" | test_expect_code 1 git p4 submit && p4 changes //depot/... >wc && test_line_count = 2 wc )
Signature · 1 line
1.7.11.4
PATCH 7/12 git p4: test clean-up after failed submit, fix added files
In reply to Pete WyckoffTest a variety of cases where a patch failed to apply to p4 and had to be cleaned up.
If the patch failed to apply cleanly, do not try to remove to-be-added files, as they have not really been added yet.
--- git-p4.py | 2 - t/t9815-git-p4-submit-fail.sh | 132 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 2 deletions(-)
git-p4.py +0 -2
@@ -1200,8 +1200,6 @@ class P4Submit(Command, P4UserMap): if not patch_succeeded: for f in editedFiles: p4_revert(f) - for f in filesToAdd: - os.remove(f) return False system(applyPatchCmd)
t/t9815-git-p4-submit-fail.sh +132 -0
138 lines not on this page · raw message
Signature · 1 line
1.7.11.4
PATCH 8/12 git p4: rearrange submit template construction
In reply to Pete WyckoffPut all items in order as they appear, and add comments.
--- git-p4.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
git-p4.py +21 -8
@@ -1202,6 +1202,9 @@ class P4Submit(Command, P4UserMap): p4_revert(f) return False + # + # Apply the patch for real, and do add/delete/+x handling. + # system(applyPatchCmd) for f in filesToAdd:
@@ -1215,6 +1218,10 @@ class P4Submit(Command, P4UserMap): 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)
@@ -1223,8 +1230,16 @@ class P4Submit(Command, P4UserMap): 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 = ""
@@ -1232,6 +1247,7 @@ class P4Submit(Command, P4UserMap): diff += p4_read_pipe(['diff', '-du', wildcard_encode(editedFile)]) + # new file diff newdiff = "" for newFile in filesToAdd: newdiff += "==== new file ====\n"
@@ -1242,13 +1258,7 @@ class P4Submit(Command, P4UserMap): 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:
@@ -1258,6 +1268,9 @@ class P4Submit(Command, P4UserMap): 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
Signature · 1 line
1.7.11.4
PATCH 9/12 git p4: revert deleted files after submit cancel
In reply to Pete WyckoffThe user can decide not to continue with a submission, by not saving the p4 submit template, then answering "no" to the "Submit anyway?" prompt. In this case, be sure to return the p4 client to its initial state.
Deleted files were not reverted; fix this and test all cases.
--- git-p4.py | 2 + t/t9815-git-p4-submit-fail.sh | 119 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+)
git-p4.py +2 -0
@@ -1304,6 +1304,8 @@ class P4Submit(Command, P4UserMap): for f in filesToAdd: p4_revert(f) os.remove(f) + for f in filesToDelete: + p4_revert(f) os.remove(fileName) return ret
t/t9815-git-p4-submit-fail.sh +119 -0
125 lines not on this page · raw message
Signature · 1 line
1.7.11.4
PATCH 10/12 git p4: accept -v for --verbose
In reply to Pete WyckoffThe short form "-v" is common in many git commands as an alias for "--verbose".
--- Documentation/git-p4.txt | 2 +- git-p4.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/git-p4.txt +1 -1
@@ -163,7 +163,7 @@ All commands except clone accept these options. --git-dir <dir>:: Set the 'GIT_DIR' environment variable. See linkgit:git[1]. ---verbose:: +--verbose, -v:: Provide more progress information. Sync options
git-p4.py +1 -1
@@ -3028,7 +3028,7 @@ def main(): args = sys.argv[2:] - options.append(optparse.make_option("--verbose", dest="verbose", action="store_true")) + options.append(optparse.make_option("--verbose", "-v", dest="verbose", action="store_true")) if cmd.needsGit: options.append(optparse.make_option("--git-dir", dest="gitdir"))
Signature · 1 line
1.7.11.4
PATCH 11/12 git p4: add submit --dry-run option
In reply to Pete WyckoffA new option, "git p4 submit --dry-run" can be used to verify what commits and labels would be moved into p4.
--- Documentation/git-p4.txt | 4 ++++ git-p4.py | 43 ++++++++++++++++++++++++++++++------------- t/t9807-git-p4-submit.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 13 deletions(-)
Documentation/git-p4.txt +4 -0
@@ -269,6 +269,10 @@ These options can be used to modify 'git p4 submit' behavior. Export tags from git as p4 labels. Tags found in git are applied to the perforce working directory. +--dry-run, -n:: + Show just what commits would be submitted to p4; do not change + state in git or p4. + Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior.
git-p4.py +30 -13
85 lines not on this page · raw message
t/t9807-git-p4-submit.sh +41 -0
47 lines not on this page · raw message
Signature · 1 line
1.7.11.4
PATCH 12/12 git p4: add submit --prepare-p4-only option
In reply to Pete WyckoffThis option can be used to prepare the client workspace for submission, only. It does not invoke the final "p4 submit". A message describes how to proceed, either submitting the changes or reverting.
--- Documentation/git-p4.txt | 7 +++++++ git-p4.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ t/t9807-git-p4-submit.sh | 24 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
Documentation/git-p4.txt +7 -0
@@ -273,6 +273,13 @@ These options can be used to modify 'git p4 submit' behavior. Show just what commits would be submitted to p4; do not change state in git or p4. +--prepare-p4-only:: + Apply a commit to the p4 workspace, opening, adding and deleting + files in p4 as for a normal submit operation. Do not issue the + final "p4 submit", but instead print a message about how to + submit manually or revert. This option always stops after the + first (oldest) commit. Git tags are not exported to p4. + Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior.
git-p4.py +46 -0
82 lines not on this page · raw message
t/t9807-git-p4-submit.sh +24 -0
@@ -375,6 +375,30 @@ test_expect_success 'description with Jobs section and bogus following text' ' make_job $(cat jobname) && test_must_fail git p4 submit 2>err && test_i18ngrep "Unknown field name" err + ) && + ( + cd "$cli" && + p4 revert desc6 && + rm desc6 + ) +' + +test_expect_success 'submit --prepare-p4-only' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + echo prep-only-add >prep-only-add && + git add prep-only-add && + 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 + ) && + ( + cd "$cli" && + test_path_is_file prep-only-add && + p4 fstat -T action prep-only-add | grep -w add ) '
Signature · 1 line
1.7.11.4
Quoted 16 lines · Pete Wyckoff
These patches rework how git p4 deals with conflicts that arise during a "git p4 submit". These may arise due to changes that happened in p4 since the last "git p4 sync".
Luke: I especially wanted to get this out as you suggested that you had a different way of dealing with skipped commits.
The part that needs the most attention is the interaction loop that happens when a commit failed. Currently, three options are offered:
[s]kip this commit, but continue to apply others [a]pply the commit forcefully, generating .rej files [w]rite the commit to a patch.txt file
and the implicit<ctrl-c> to stop
Quoted 8 lines
After this series, it offers two:
[c]ontinue to apply others
[q]uit to stopThis feels more natural to me, and I like the term "continue" rather than "skip" as it matches what rebase uses. I'd like to know what others think of the new flow.
The skip is still needed. In my workflow, git-p4 gets run periodically and does the usual sync+rebase on behalf of all the people who have pushed to the git repo.
If someone pushes a change which conflicts with something from Perforce land, then what I want to happen is for the script to discard the offending commit (git rebase --skip) and then carry on with the others.
In 99% of cases this does exactly what I need, as conflicting commits are usually caused by people committing the same fix to both p4 and git at around the same time (someone breaks top-of-tree with an obvious error, two separate people check in slightly different fixes). Discarding the git commit then means that everything carries on working.
I've got a small patch which makes skipping work non-interactively; the thing it's missing is reporting the commits which are skipped.
Quoted 43 lines
Other observable changes are new command-line options:
Alias -v for --verbose, similar to other git commands.
The --dry-run option addresses Luke's concern in
http://thread.gmane.org/gmane.comp.version-control.git/201004/focus=201022when I removed an unused "self.interactive" variable that did a similar thing if you edited the code. It prints commits that would be applied to p4.
Option --prepare-p4-only is similar to --dry-run, in that it does not submit anything to p4, but it does prepare the p4 workspace, then prints long instructions about how to submit everything properly. It also serves, perhaps, as a replacement for the [a]pply option in the submit-conflict loop.
Pete Wyckoff (12):
git p4 test: remove bash-ism of combined export/assignment git p4 test: use p4d -L option to suppress log messages git p4: gracefully fail if some commits could not be applied git p4: remove submit failure options [a]pply and [w]rite git p4: move conflict prompt into run, use [c]ontinue and [q]uit git p4: standardize submit cancel due to unchanged template git p4: test clean-up after failed submit, fix added files git p4: rearrange submit template construction
git p4: revert deleted files after submit cancel
git p4: accept -v for --verbose
git p4: add submit --dry-run option
git p4: add submit --prepare-p4-only optionDocumentation/git-p4.txt | 13 +- git-p4.py | 213 +++++++++++++++------ t/lib-git-p4.sh | 10 +- t/t9805-git-p4-skip-submit-edit.sh | 2 +- t/t9807-git-p4-submit.sh | 65 +++++++ t/t9810-git-p4-rcs.sh | 50 +---- t/t9815-git-p4-submit-fail.sh | 367 +++++++++++++++++++++++++++++++++++++ 7 files changed, 612 insertions(+), 108 deletions(-)create mode 100755
t/t9815-git-p4-submit-fail.sh
[email protected] wrote on Fri, 17 Aug 2012 07:04 +0100:
Quoted 42 lines · Pete Wyckoff
Quoted 16 lines
These patches rework how git p4 deals with conflicts that arise during a "git p4 submit". These may arise due to changes that happened in p4 since the last "git p4 sync".
Luke: I especially wanted to get this out as you suggested that you had a different way of dealing with skipped commits.
The part that needs the most attention is the interaction loop that happens when a commit failed. Currently, three options are offered:
[s]kip this commit, but continue to apply others [a]pply the commit forcefully, generating .rej files [w]rite the commit to a patch.txt file
and the implicit<ctrl-c> to stopQuoted 8 lines
After this series, it offers two:
[c]ontinue to apply others
[q]uit to stopThis feels more natural to me, and I like the term "continue" rather than "skip" as it matches what rebase uses. I'd like to know what others think of the new flow.
The skip is still needed. In my workflow, git-p4 gets run periodically and does the usual sync+rebase on behalf of all the people who have pushed to the git repo.
If someone pushes a change which conflicts with something from Perforce land, then what I want to happen is for the script to discard the offending commit (git rebase --skip) and then carry on with the others.
In 99% of cases this does exactly what I need, as conflicting commits are usually caused by people committing the same fix to both p4 and git at around the same time (someone breaks top-of-tree with an obvious error, two separate people check in slightly different fixes). Discarding the git commit then means that everything carries on working.
Quoted 2 lines
I've got a small patch which makes skipping work non-interactively; the thing it's missing is reporting the commits which are skipped.
This "discard offending commits" part I had not thought anyone would ever do. Instead, why not do "git p4 rebase" on its own and use "git rebase --skip" to discard the offending ones explicitly. It seems dangerous to do it implicitly as part of a multi-commit submit to p4.
Thanks for sending your RFC work. I see what you are thinking about.
Assuming that it really would be good to have a way to _automatically_ discard conflicting commits, then sure, keeping a list in submit and plumbing that into the rebase would work. It still scares me. There are quite a few special cases where it fails, of course, like if future commits involve dependencies on the one you want to skip.
Would this alternative approach work: "git p4 submit --discard-conflicting-commits" (and/or the option). It automatically hits "skip" after every submit failure. When done, it does "git p4 sync" to get a report on what ended up in tree. Then instead of rebasing, the HEAD is simply taken to the top of the p4 tree. No need to rebase if the rule is to discard all skipped patches. Plus some reporting to say what was lost.
I will reroll my series once we've figured out how we want these to co-exist.
-- Pete