* [PATCH] git-filter-branch: Add more error-handling
@ 2009-02-11 14:09 Eric Kidd
2009-02-11 14:58 ` Johannes Sixt
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 14:09 UTC (permalink / raw)
To: git; +Cc: Eric Kidd
In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
that had slipped by the test suites because of a missing check on 'git
read-tree -u -m HEAD'.
I mentioned to Johannes Schindelin that there were several bugs of this
type in git-filter-branch, and he suggested that I send a patch.
I've tested this patch using t/t7003-filter-branch.sh, and it passes all
the existing tests. But it's entirely possible that this patch contains
errors, and I would love input from people who have more experience with
sh and who know more about git-filter-branch.
In particular, the following hunk may change the public UI to
git-filter-branch, although I'm not sure whether the change is for
better or for worse. As I understand it, this hunk would allow
$filter_commit to abort the rewriting process by returning a non-0 exit
status:
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit
+ $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ die "could not write rewritten commit"
done <../revs
I'd be happy to add a test case for what happens when $filter_commit
returns a non-0 exit status. Is the old behavior preferable?
---
git-filter-branch.sh | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
I'm trying to do the constructive thing, and send patches instead of bug
reports. :-) -Eric
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86eef56..9d50978 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -221,7 +221,7 @@ die ""
trap 'cd ../..; rm -rf "$tempdir"' 0
# Make sure refs/original is empty
-git for-each-ref > "$tempdir"/backup-refs
+git for-each-ref > "$tempdir"/backup-refs || die "Can't back up refs"
while read sha1 type name
do
case "$force,$name" in
@@ -242,7 +242,7 @@ export GIT_DIR GIT_WORK_TREE
# The refs should be updated if their heads were rewritten
git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
-sed -e '/^^/d' >"$tempdir"/heads
+sed -e '/^^/d' >"$tempdir"/heads || die "Can't make list of original refs"
test -s "$tempdir"/heads ||
die "Which ref do you want to rewrite?"
@@ -315,10 +315,11 @@ while read commit parents; do
die "tree filter failed: $filter_tree"
(
- git diff-index -r --name-only $commit
+ git diff-index -r --name-only $commit &&
git ls-files --others
) |
- git update-index --add --replace --remove --stdin
+ git update-index --add --replace --remove --stdin ||
+ die "unable to update index with results of tree filter"
fi
eval "$filter_index" < /dev/null ||
@@ -339,7 +340,8 @@ while read commit parents; do
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit
+ $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ die "could not write rewritten commit"
done <../revs
# In case of a subdirectory filter, it is possible that a specified head
@@ -407,7 +409,8 @@ do
die "Could not rewrite $ref"
;;
esac
- git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
+ git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
+ die "Could not back up branch ref"
done < "$tempdir"/heads
# TODO: This should possibly go, with the semantics that all positive given
@@ -483,7 +486,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
}
if [ "$(is_bare_repository)" = false ]; then
- git read-tree -u -m HEAD
+ git read-tree -u -m HEAD || die "Unable to checkout rewritten tree"
fi
exit $ret
--
1.6.0.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] git-filter-branch: Add more error-handling
2009-02-11 14:09 [PATCH] git-filter-branch: Add more error-handling Eric Kidd
@ 2009-02-11 14:58 ` Johannes Sixt
2009-02-11 15:36 ` Johannes Sixt
2009-02-11 15:24 ` Johannes Schindelin
2009-02-11 17:15 ` [PATCH v2] filter-branch: " Eric Kidd
2 siblings, 1 reply; 13+ messages in thread
From: Johannes Sixt @ 2009-02-11 14:58 UTC (permalink / raw)
To: Eric Kidd; +Cc: git
Eric Kidd schrieb:
> In particular, the following hunk may change the public UI to
> git-filter-branch, although I'm not sure whether the change is for
> better or for worse. As I understand it, this hunk would allow
> $filter_commit to abort the rewriting process by returning a non-0 exit
> status:
>
> @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
> - $(git write-tree) $parentstr < ../message > ../map/$commit
> + $(git write-tree) $parentstr < ../message > ../map/$commit ||
> + die "could not write rewritten commit"
> done <../revs
>
> I'd be happy to add a test case for what happens when $filter_commit
> returns a non-0 exit status. Is the old behavior preferable?
I think it's OK to die if the commit filter fails.
But generally, I think it is not necessary to use 'die with error
message', a plain '|| exit' should be enough because an error will have
been reported already by the tool that failed.
> @@ -483,7 +486,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
> }
>
> if [ "$(is_bare_repository)" = false ]; then
> - git read-tree -u -m HEAD
> + git read-tree -u -m HEAD || die "Unable to checkout rewritten tree"
Here you shouldn't die. But unlike elsewhere, this case warrants an
explanation for the user:
git read-tree -u -m HEAD ||
echo >&2 "WARNING: The working directory is not up-to-date!"
> fi
>
> exit $ret
-- Hannes
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] git-filter-branch: Add more error-handling
2009-02-11 14:09 [PATCH] git-filter-branch: Add more error-handling Eric Kidd
2009-02-11 14:58 ` Johannes Sixt
@ 2009-02-11 15:24 ` Johannes Schindelin
2009-02-11 17:15 ` [PATCH v2] filter-branch: " Eric Kidd
2 siblings, 0 replies; 13+ messages in thread
From: Johannes Schindelin @ 2009-02-11 15:24 UTC (permalink / raw)
To: Eric Kidd; +Cc: git
Hi,
On Wed, 11 Feb 2009, Eric Kidd wrote:
> In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
> that had slipped by the test suites because of a missing check on 'git
> read-tree -u -m HEAD'.
>
> I mentioned to Johannes Schindelin that there were several bugs of this
> type in git-filter-branch, and he suggested that I send a patch.
>
> I've tested this patch using t/t7003-filter-branch.sh, and it passes all
> the existing tests. But it's entirely possible that this patch contains
> errors, and I would love input from people who have more experience with
> sh and who know more about git-filter-branch.
>
> In particular, the following hunk may change the public UI to
> git-filter-branch, although I'm not sure whether the change is for
> better or for worse. As I understand it, this hunk would allow
> $filter_commit to abort the rewriting process by returning a non-0 exit
> status:
>
> @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
> - $(git write-tree) $parentstr < ../message > ../map/$commit
> + $(git write-tree) $parentstr < ../message > ../map/$commit ||
> + die "could not write rewritten commit"
> done <../revs
>
> I'd be happy to add a test case for what happens when $filter_commit
> returns a non-0 exit status. Is the old behavior preferable?
> ---
Thanks. Although it lacks a Sign-off, and part of the commit message is
actually a personal comment that belongs after the three dashes.
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 86eef56..9d50978 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -242,7 +242,7 @@ export GIT_DIR GIT_WORK_TREE
>
> # The refs should be updated if their heads were rewritten
> git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
> -sed -e '/^^/d' >"$tempdir"/heads
> +sed -e '/^^/d' >"$tempdir"/heads || die "Can't make list of original refs"
This will catch errors in the sed invocation, but not in rev-parse.
> @@ -315,10 +315,11 @@ while read commit parents; do
> die "tree filter failed: $filter_tree"
>
> (
> - git diff-index -r --name-only $commit
> + git diff-index -r --name-only $commit &&
> git ls-files --others
> ) |
> - git update-index --add --replace --remove --stdin
> + git update-index --add --replace --remove --stdin ||
> + die "unable to update index with results of tree filter"
This will catch errors in the update-index call, but neither in diff-index
nor ls-files.
Otherwise, the patch looks good to me.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] git-filter-branch: Add more error-handling
2009-02-11 14:58 ` Johannes Sixt
@ 2009-02-11 15:36 ` Johannes Sixt
0 siblings, 0 replies; 13+ messages in thread
From: Johannes Sixt @ 2009-02-11 15:36 UTC (permalink / raw)
To: Eric Kidd; +Cc: git
Johannes Sixt schrieb:
>> @@ -483,7 +486,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
>> }
>>
>> if [ "$(is_bare_repository)" = false ]; then
>> - git read-tree -u -m HEAD
>> + git read-tree -u -m HEAD || die "Unable to checkout rewritten tree"
>
> Here you shouldn't die.
I take this back. I was distracted by the 'exit $ret' that is visible in
the context:
>> fi
>>
>> exit $ret
But this exit statement is pointless: ret is initialized to zero and never
changed.
-- Hannes
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2] filter-branch: Add more error-handling
2009-02-11 14:09 [PATCH] git-filter-branch: Add more error-handling Eric Kidd
2009-02-11 14:58 ` Johannes Sixt
2009-02-11 15:24 ` Johannes Schindelin
@ 2009-02-11 17:15 ` Eric Kidd
2009-02-11 19:03 ` Junio C Hamano
2 siblings, 1 reply; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 17:15 UTC (permalink / raw)
To: git; +Cc: Eric Kidd
In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
that had slipped by the test suites because of a missing check on 'git
read-tree -u -m HEAD'.
I mentioned to Johannes Schindelin that there were several bugs of this
type in git-filter-branch, and he suggested that I send a patch. I've
tested this patch using t/t7003-filter-branch.sh, and it passes all the
existing tests.
In two places, I've had to break apart pipelines in order to check the
error code for the first stage of the pipeline, as discussed here:
http://kerneltrap.org/mailarchive/git/2009/1/28/4835614
Thank you to charon on #git for pointing me in the right direction.
This patch causes 'git filter-branch' to fail if the --commit-filter
argument returns an error. A test case for this behavior is included.
Feedback on the original version of this patch was provided by Johannes
Sixt and Johannes Schindelin.
v2:
Remove useless $ret variable
Correctly check the first command in a pipeline, not the second
Replace verbose 'die' messages with 'exit 1' in most cases
Signed-off-by: Eric Kidd <git@randomhacks.net>
---
git-filter-branch.sh | 26 ++++++++++++++------------
t/t7003-filter-branch.sh | 4 ++++
2 files changed, 18 insertions(+), 12 deletions(-)
Thank you for the feedback! I've tried to incorporate everybody's
suggestions. Please let me know if some of those 'exit 1' statements
should be changed back to 'die'. -Eric
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86eef56..fff07c8 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -221,7 +221,7 @@ die ""
trap 'cd ../..; rm -rf "$tempdir"' 0
# Make sure refs/original is empty
-git for-each-ref > "$tempdir"/backup-refs
+git for-each-ref > "$tempdir"/backup-refs || exit 1
while read sha1 type name
do
case "$force,$name" in
@@ -241,8 +241,9 @@ GIT_WORK_TREE=.
export GIT_DIR GIT_WORK_TREE
# The refs should be updated if their heads were rewritten
-git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
-sed -e '/^^/d' >"$tempdir"/heads
+git rev-parse --no-flags --revs-only --symbolic-full-name \
+ --default HEAD "$@" > "$tempdir"/raw-heads || exit 1
+sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
test -s "$tempdir"/heads ||
die "Which ref do you want to rewrite?"
@@ -251,8 +252,6 @@ GIT_INDEX_FILE="$(pwd)/../index"
export GIT_INDEX_FILE
git read-tree || die "Could not seed the index"
-ret=0
-
# map old->new commit ids for rewriting parents
mkdir ../map || die "Could not create map/ directory"
@@ -315,10 +314,11 @@ while read commit parents; do
die "tree filter failed: $filter_tree"
(
- git diff-index -r --name-only $commit
+ git diff-index -r --name-only $commit &&
git ls-files --others
- ) |
- git update-index --add --replace --remove --stdin
+ ) > "$tempdir"/tree-state || exit 1
+ git update-index --add --replace --remove --stdin \
+ < "$tempdir"/tree-state || exit 1
fi
eval "$filter_index" < /dev/null ||
@@ -339,7 +339,8 @@ while read commit parents; do
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit
+ $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ die "could not write rewritten commit"
done <../revs
# In case of a subdirectory filter, it is possible that a specified head
@@ -407,7 +408,8 @@ do
die "Could not rewrite $ref"
;;
esac
- git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
+ git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
+ exit 1
done < "$tempdir"/heads
# TODO: This should possibly go, with the semantics that all positive given
@@ -483,7 +485,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
}
if [ "$(is_bare_repository)" = false ]; then
- git read-tree -u -m HEAD
+ git read-tree -u -m HEAD || exit 1
fi
-exit $ret
+exit 0
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index cb04743..39affd9 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -48,6 +48,10 @@ test_expect_success 'result is really identical' '
test $H = $(git rev-parse HEAD)
'
+test_expect_success 'Fail if commit filter fails' '
+ ! git filter-branch -f --commit-filter "exit 1" HEAD
+'
+
test_expect_success 'rewrite, renaming a specific file' '
git filter-branch -f --tree-filter "mv d doh || :" HEAD
'
--
1.6.0.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] filter-branch: Add more error-handling
2009-02-11 17:15 ` [PATCH v2] filter-branch: " Eric Kidd
@ 2009-02-11 19:03 ` Junio C Hamano
2009-02-11 19:34 ` Eric Kidd
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Junio C Hamano @ 2009-02-11 19:03 UTC (permalink / raw)
To: Eric Kidd; +Cc: git
Eric Kidd <git@randomhacks.net> writes:
> In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
> ...
> Thank you to charon on #git for pointing me in the right direction.
The commit message is not a reception speech at Emmy Awards. If you want
to do the speech, do so after the three-dash lines.
Please just stick to what problem it tries to solve, how it does so, and
what the outcome is.
> This patch causes 'git filter-branch' to fail if the --commit-filter
> argument returns an error. A test case for this behavior is included.
That's a very good start for the description of the solution, which would
be for the second paragraph. The problem description is missing.
> Feedback on the original version of this patch was provided by Johannes
> Sixt and Johannes Schindelin.
Giving credits to others like this with a short sentence at the end is
fine.
> v2:
> Remove useless $ret variable
> Correctly check the first command in a pipeline, not the second
> Replace verbose 'die' messages with 'exit 1' in most cases
This goes after three-dashes; people who read "git log" output wouldn't
know nor care what was in v1.
Subject: Fix X under condition Z
X should do Y if condition Z holds, but it does not. This can result
in broken results such as W and V.
This patch fixes X by changing A, B and C.
Thanks for M, N and O for reviewing and suggesting improvements.
Signed-off-by: A U Thor <au.thor@example.xz>
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 86eef56..fff07c8 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -221,7 +221,7 @@ die ""
> trap 'cd ../..; rm -rf "$tempdir"' 0
>
> # Make sure refs/original is empty
> -git for-each-ref > "$tempdir"/backup-refs
> +git for-each-ref > "$tempdir"/backup-refs || exit 1
Why "exit 1", not "exit"?
> @@ -241,8 +241,9 @@ GIT_WORK_TREE=.
> export GIT_DIR GIT_WORK_TREE
>
> # The refs should be updated if their heads were rewritten
> -git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
> -sed -e '/^^/d' >"$tempdir"/heads
> +git rev-parse --no-flags --revs-only --symbolic-full-name \
> + --default HEAD "$@" > "$tempdir"/raw-heads || exit 1
Likewise.
> @@ -315,10 +314,11 @@ while read commit parents; do
> die "tree filter failed: $filter_tree"
>
> (
> - git diff-index -r --name-only $commit
> + git diff-index -r --name-only $commit &&
> git ls-files --others
> - ) |
> - git update-index --add --replace --remove --stdin
> + ) > "$tempdir"/tree-state || exit 1
> + git update-index --add --replace --remove --stdin \
> + < "$tempdir"/tree-state || exit 1
Likewise.
> @@ -339,7 +339,8 @@ while read commit parents; do
> eval "$filter_msg" > ../message ||
> die "msg filter failed: $filter_msg"
> @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
> - $(git write-tree) $parentstr < ../message > ../map/$commit
> + $(git write-tree) $parentstr < ../message > ../map/$commit ||
> + die "could not write rewritten commit"
Hmm, wouldn't commit-tree have issued its own error message already? If
redirect failed, then the shell would have.
> @@ -407,7 +408,8 @@ do
> die "Could not rewrite $ref"
> ;;
> esac
> - git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
> + git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
> + exit 1
Why "exit 1", not "exit"?
> @@ -483,7 +485,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
> }
>
> if [ "$(is_bare_repository)" = false ]; then
> - git read-tree -u -m HEAD
> + git read-tree -u -m HEAD || exit 1
Likewise
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index cb04743..39affd9 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -48,6 +48,10 @@ test_expect_success 'result is really identical' '
> test $H = $(git rev-parse HEAD)
> '
>
> +test_expect_success 'Fail if commit filter fails' '
> + ! git filter-branch -f --commit-filter "exit 1" HEAD
> +'
> +
"test_must_fail git ..." would be better here than "! git ...".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] filter-branch: Add more error-handling
2009-02-11 19:03 ` Junio C Hamano
@ 2009-02-11 19:34 ` Eric Kidd
2009-02-11 20:03 ` [PATCHv3] " Eric Kidd
2009-02-11 21:30 ` [PATCH v2] " Nanako Shiraishi
2 siblings, 0 replies; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 19:34 UTC (permalink / raw)
To: git
On Wed, Feb 11, 2009 at 2:03 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> @@ -339,7 +339,8 @@ while read commit parents; do
>> eval "$filter_msg" > ../message ||
>> die "msg filter failed: $filter_msg"
>> @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
>> - $(git write-tree) $parentstr < ../message > ../map/$commit
>> + $(git write-tree) $parentstr < ../message > ../map/$commit ||
>> + die "could not write rewritten commit"
>
> Hmm, wouldn't commit-tree have issued its own error message already? If
> redirect failed, then the shell would have.
If a custom $filter_commit calls 'exit', there won't be an error
message from git. Of course, there may be an error message from the
custom $filter_commit, but I decided not to rely on that. Would you
prefer me to remove the error message?
I'll have another patch ready shortly, incorporating your suggestions.
My apologies for giving credit in the wrong part of the commit
message, and thank you for your feedback!
Cheers,
Eric
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCHv3] filter-branch: Add more error-handling
2009-02-11 19:03 ` Junio C Hamano
2009-02-11 19:34 ` Eric Kidd
@ 2009-02-11 20:03 ` Eric Kidd
2009-02-11 20:48 ` Johannes Schindelin
2009-02-11 21:30 ` [PATCH v2] " Nanako Shiraishi
2 siblings, 1 reply; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 20:03 UTC (permalink / raw)
To: git; +Cc: Eric Kidd
In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
that had slipped by the test suites because of a missing check on 'git
read-tree -u -m HEAD'.
This patch attemps to add all the missing error checks to
git-filter-branch, and removes an existing $ret variable that did
nothing. I've tested this patch using t/t7003-filter-branch.sh, and it
passes all the existing tests.
This patch also causes 'git filter-branch' to fail if the --commit-filter
argument returns an error. A test case for this behavior is included.
In two places, I've had to break apart pipelines in order to check the
error code for the first stage of the pipeline, as discussed here:
http://kerneltrap.org/mailarchive/git/2009/1/28/4835614
Feedback on this patch was provided by Johannes Sixt, Johannes Schindelin
and Junio C Hamano. charon on #git helped with pipeline error handling.
Signed-off-by: Eric Kidd <git@randomhacks.net>
---
git-filter-branch.sh | 26 ++++++++++++++------------
t/t7003-filter-branch.sh | 4 ++++
2 files changed, 18 insertions(+), 12 deletions(-)
v3:
Replaced 'exit 1' with 'exit' to use exit status of last command
Use test_must_fail for unit test expecting failure
v2:
Remove useless $ret variable
Correctly check the first command in a pipeline, not the second
Replace verbose 'die' messages with 'exit 1' in most cases
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86eef56..27b57b8 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -221,7 +221,7 @@ die ""
trap 'cd ../..; rm -rf "$tempdir"' 0
# Make sure refs/original is empty
-git for-each-ref > "$tempdir"/backup-refs
+git for-each-ref > "$tempdir"/backup-refs || exit
while read sha1 type name
do
case "$force,$name" in
@@ -241,8 +241,9 @@ GIT_WORK_TREE=.
export GIT_DIR GIT_WORK_TREE
# The refs should be updated if their heads were rewritten
-git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
-sed -e '/^^/d' >"$tempdir"/heads
+git rev-parse --no-flags --revs-only --symbolic-full-name \
+ --default HEAD "$@" > "$tempdir"/raw-heads || exit
+sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
test -s "$tempdir"/heads ||
die "Which ref do you want to rewrite?"
@@ -251,8 +252,6 @@ GIT_INDEX_FILE="$(pwd)/../index"
export GIT_INDEX_FILE
git read-tree || die "Could not seed the index"
-ret=0
-
# map old->new commit ids for rewriting parents
mkdir ../map || die "Could not create map/ directory"
@@ -315,10 +314,11 @@ while read commit parents; do
die "tree filter failed: $filter_tree"
(
- git diff-index -r --name-only $commit
+ git diff-index -r --name-only $commit &&
git ls-files --others
- ) |
- git update-index --add --replace --remove --stdin
+ ) > "$tempdir"/tree-state || exit
+ git update-index --add --replace --remove --stdin \
+ < "$tempdir"/tree-state || exit
fi
eval "$filter_index" < /dev/null ||
@@ -339,7 +339,8 @@ while read commit parents; do
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit
+ $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ die "could not write rewritten commit"
done <../revs
# In case of a subdirectory filter, it is possible that a specified head
@@ -407,7 +408,8 @@ do
die "Could not rewrite $ref"
;;
esac
- git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
+ git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
+ exit
done < "$tempdir"/heads
# TODO: This should possibly go, with the semantics that all positive given
@@ -483,7 +485,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
}
if [ "$(is_bare_repository)" = false ]; then
- git read-tree -u -m HEAD
+ git read-tree -u -m HEAD || exit
fi
-exit $ret
+exit 0
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index cb04743..11ed4c4 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -48,6 +48,10 @@ test_expect_success 'result is really identical' '
test $H = $(git rev-parse HEAD)
'
+test_must_fail 'Fail if commit filter fails' '
+ git filter-branch -f --commit-filter "exit 1" HEAD
+'
+
test_expect_success 'rewrite, renaming a specific file' '
git filter-branch -f --tree-filter "mv d doh || :" HEAD
'
--
1.6.0.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCHv3] filter-branch: Add more error-handling
2009-02-11 20:03 ` [PATCHv3] " Eric Kidd
@ 2009-02-11 20:48 ` Johannes Schindelin
2009-02-11 21:00 ` Eric Kidd
2009-02-11 21:10 ` [PATCHv4] " Eric Kidd
0 siblings, 2 replies; 13+ messages in thread
From: Johannes Schindelin @ 2009-02-11 20:48 UTC (permalink / raw)
To: Eric Kidd; +Cc: git
Hi,
On Wed, 11 Feb 2009, Eric Kidd wrote:
> charon on #git helped with pipeline error handling.
JFYI charon is the nick of Thomas Rast.
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 86eef56..27b57b8 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -221,7 +221,7 @@ die ""
> trap 'cd ../..; rm -rf "$tempdir"' 0
>
> # Make sure refs/original is empty
> -git for-each-ref > "$tempdir"/backup-refs
> +git for-each-ref > "$tempdir"/backup-refs || exit
I haven't checked, but is "$tempdir" not the working directory? If so,
this would lead to funny interaction with --tree-filter. Rather, I'd
write the file into "$GIT_DIR". Likewise the other files.
> +test_must_fail 'Fail if commit filter fails' '
> + git filter-branch -f --commit-filter "exit 1" HEAD
> +'
> +
That's not how it is supposed to be used. Rather,
test_expect_success $LABEL '
test_must_fail git filter-branc $OPTIONS
'
Thanks,
Dscho
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCHv3] filter-branch: Add more error-handling
2009-02-11 20:48 ` Johannes Schindelin
@ 2009-02-11 21:00 ` Eric Kidd
2009-02-11 21:10 ` [PATCHv4] " Eric Kidd
1 sibling, 0 replies; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 21:00 UTC (permalink / raw)
To: git
On Wed, Feb 11, 2009 at 3:48 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> I haven't checked, but is "$tempdir" not the working directory? If so,
> this would lead to funny interaction with --tree-filter. Rather, I'd
> write the file into "$GIT_DIR". Likewise the other files.
The working directory actually lives one level down:
tempdir=.git-rewrite
workdir="$tempdir/t"
At the end of the script, git-filter-branch cleans up all of its
temporary files by deleting $tempdir. There's actually a fair bit of
stuff in there already, and none of it interferes with --tree-filter.
> That's not how it is supposed to be used. Rather,
>
> test_expect_success $LABEL '
> test_must_fail git filter-branc $OPTIONS
> '
Will fix. Thank you.
I really appreciate all this feedback from the git team. Thank you for
taking the time to help me get this right!
Cheers,
Eric
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCHv4] filter-branch: Add more error-handling
2009-02-11 20:48 ` Johannes Schindelin
2009-02-11 21:00 ` Eric Kidd
@ 2009-02-11 21:10 ` Eric Kidd
1 sibling, 0 replies; 13+ messages in thread
From: Eric Kidd @ 2009-02-11 21:10 UTC (permalink / raw)
To: git; +Cc: Eric Kidd
In commit 9273b56278e64dd47b1a96a705ddf46aeaf6afe3, I fixed an error
that had slipped by the test suites because of a missing check on 'git
read-tree -u -m HEAD'.
This patch attemps to add all the missing error checks to
git-filter-branch, and removes an existing $ret variable that did
nothing. I've tested this patch using t/t7003-filter-branch.sh, and it
passes all the existing tests.
This patch also causes 'git filter-branch' to fail if the --commit-filter
argument returns an error. A test case for this behavior is included.
In two places, I've had to break apart pipelines in order to check the
error code for the first stage of the pipeline, as discussed here:
http://kerneltrap.org/mailarchive/git/2009/1/28/4835614
Feedback on this patch was provided by Johannes Sixt, Johannes Schindelin
and Junio C Hamano. Thomas Rast helped with pipeline error handling.
Signed-off-by: Eric Kidd <git@randomhacks.net>
---
git-filter-branch.sh | 26 ++++++++++++++------------
t/t7003-filter-branch.sh | 4 ++++
2 files changed, 18 insertions(+), 12 deletions(-)
v4:
Call test_must_fail from inside test_expect_success
v3:
Replaced 'exit 1' with 'exit' to use exit status of last command
Use test_must_fail for unit test expecting failure
v2:
Remove useless $ret variable
Correctly check the first command in a pipeline, not the second
Replace verbose 'die' messages with 'exit 1' in most cases
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86eef56..27b57b8 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -221,7 +221,7 @@ die ""
trap 'cd ../..; rm -rf "$tempdir"' 0
# Make sure refs/original is empty
-git for-each-ref > "$tempdir"/backup-refs
+git for-each-ref > "$tempdir"/backup-refs || exit
while read sha1 type name
do
case "$force,$name" in
@@ -241,8 +241,9 @@ GIT_WORK_TREE=.
export GIT_DIR GIT_WORK_TREE
# The refs should be updated if their heads were rewritten
-git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
-sed -e '/^^/d' >"$tempdir"/heads
+git rev-parse --no-flags --revs-only --symbolic-full-name \
+ --default HEAD "$@" > "$tempdir"/raw-heads || exit
+sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
test -s "$tempdir"/heads ||
die "Which ref do you want to rewrite?"
@@ -251,8 +252,6 @@ GIT_INDEX_FILE="$(pwd)/../index"
export GIT_INDEX_FILE
git read-tree || die "Could not seed the index"
-ret=0
-
# map old->new commit ids for rewriting parents
mkdir ../map || die "Could not create map/ directory"
@@ -315,10 +314,11 @@ while read commit parents; do
die "tree filter failed: $filter_tree"
(
- git diff-index -r --name-only $commit
+ git diff-index -r --name-only $commit &&
git ls-files --others
- ) |
- git update-index --add --replace --remove --stdin
+ ) > "$tempdir"/tree-state || exit
+ git update-index --add --replace --remove --stdin \
+ < "$tempdir"/tree-state || exit
fi
eval "$filter_index" < /dev/null ||
@@ -339,7 +339,8 @@ while read commit parents; do
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit
+ $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ die "could not write rewritten commit"
done <../revs
# In case of a subdirectory filter, it is possible that a specified head
@@ -407,7 +408,8 @@ do
die "Could not rewrite $ref"
;;
esac
- git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
+ git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
+ exit
done < "$tempdir"/heads
# TODO: This should possibly go, with the semantics that all positive given
@@ -483,7 +485,7 @@ test -z "$ORIG_GIT_INDEX_FILE" || {
}
if [ "$(is_bare_repository)" = false ]; then
- git read-tree -u -m HEAD
+ git read-tree -u -m HEAD || exit
fi
-exit $ret
+exit 0
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index cb04743..56b5ecc 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -48,6 +48,10 @@ test_expect_success 'result is really identical' '
test $H = $(git rev-parse HEAD)
'
+test_expect_success 'Fail if commit filter fails' '
+ test_must_fail git filter-branch -f --commit-filter "exit 1" HEAD
+'
+
test_expect_success 'rewrite, renaming a specific file' '
git filter-branch -f --tree-filter "mv d doh || :" HEAD
'
--
1.6.0.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] filter-branch: Add more error-handling
2009-02-11 19:03 ` Junio C Hamano
2009-02-11 19:34 ` Eric Kidd
2009-02-11 20:03 ` [PATCHv3] " Eric Kidd
@ 2009-02-11 21:30 ` Nanako Shiraishi
2009-02-11 22:28 ` Junio C Hamano
2 siblings, 1 reply; 13+ messages in thread
From: Nanako Shiraishi @ 2009-02-11 21:30 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Eric Kidd, git
Quoting Junio C Hamano <gitster@pobox.com>:
> This goes after three-dashes; people who read "git log" output wouldn't
> know nor care what was in v1.
>
> Subject: Fix X under condition Z
>
> X should do Y if condition Z holds, but it does not. This can result
> in broken results such as W and V.
>
> This patch fixes X by changing A, B and C.
>
> Thanks for M, N and O for reviewing and suggesting improvements.
>
> Signed-off-by: A U Thor <au.thor@example.xz>
I think you meant this as a sample to follow. Can we add it to Documentation/SubmittingPatches?
--
Nanako Shiraishi, an unofficial project secretary
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] filter-branch: Add more error-handling
2009-02-11 21:30 ` [PATCH v2] " Nanako Shiraishi
@ 2009-02-11 22:28 ` Junio C Hamano
0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2009-02-11 22:28 UTC (permalink / raw)
To: Nanako Shiraishi; +Cc: Eric Kidd, git
Nanako Shiraishi <nanako3@lavabit.com> writes:
> Quoting Junio C Hamano <gitster@pobox.com>:
>
>> This goes after three-dashes; people who read "git log" output wouldn't
>> know nor care what was in v1.
>>
>> Subject: Fix X under condition Z
>>
>> X should do Y if condition Z holds, but it does not. This can result
>> in broken results such as W and V.
>>
>> This patch fixes X by changing A, B and C.
>>
>> Thanks for M, N and O for reviewing and suggesting improvements.
>>
>> Signed-off-by: A U Thor <au.thor@example.xz>
>
> I think you meant this as a sample to follow. Can we add it to Documentation/SubmittingPatches?
I did mean it as such, but I doubt it is good enough to be in in the
document (primarily because I wrote it).
Just quoting the above verbatim does not make it clear that "Thanks for M,
N..." is usually not even wanted, but was merely a suggestion for this
specific case of Eric's commit, iow, _only if he wanted to_. We need more
commentary like that, but with too much details, it would cease to be a
generic recommendation.
Also, the above is not suitable for new features at all as a template.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-02-11 22:29 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-11 14:09 [PATCH] git-filter-branch: Add more error-handling Eric Kidd
2009-02-11 14:58 ` Johannes Sixt
2009-02-11 15:36 ` Johannes Sixt
2009-02-11 15:24 ` Johannes Schindelin
2009-02-11 17:15 ` [PATCH v2] filter-branch: " Eric Kidd
2009-02-11 19:03 ` Junio C Hamano
2009-02-11 19:34 ` Eric Kidd
2009-02-11 20:03 ` [PATCHv3] " Eric Kidd
2009-02-11 20:48 ` Johannes Schindelin
2009-02-11 21:00 ` Eric Kidd
2009-02-11 21:10 ` [PATCHv4] " Eric Kidd
2009-02-11 21:30 ` [PATCH v2] " Nanako Shiraishi
2009-02-11 22:28 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).