post-rewrite hook and copying notes
cover post-rewrite hook and copying notes
This series implements a post-rewrite hook. This has been on my todo list since we first got notes, but I never got around to it.
My original intended use-case was to add a note for the source of the rewritten commit, but recent discussion on git-notes was that we should add some feature that lets users copy over their notes when rewriting commits. The hook in the last patch, together with the 'git notes copy' command now in 'pu', can achieve this.
I'm not sure whether we should stop here and declare it the user's responsibility to enable the hook though. My idea of a "full integration" approach would be to instead teach 'git notes copy' to read the same type of lists that I'm handing to post-rewrite, and then wire calls to it into the scripts in the same places that call post-rewrite. Opinions?
Thomas Rast (6):
Documentation: document post-rewrite hook commit --amend: invoke post-rewrite hook
filter-branch: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
contrib: add a hook that copies notes over rewrites
Documentation/githooks.txt | 36 +++++++ builtin-commit.c | 43 ++++++++ contrib/hooks/post-rewrite-copy-notes | 37 +++++++ git-am.sh | 10 ++ git-filter-branch.sh | 10 ++ git-rebase--interactive.sh | 41 +++++++- git-rebase.sh | 5 + t/t5407-post-rewrite-hook.sh | 180 +++++++++++++++++++++++++++++++++ 8 files changed, 361 insertions(+), 1 deletions(-) create mode 100644 contrib/hooks/post-rewrite-copy-notes create mode 100755 t/t5407-post-rewrite-hook.sh
RFC PATCH 1/6 Documentation: document post-rewrite hook
This defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
--- Documentation/githooks.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
Documentation/githooks.txt +36 -0
@@ -317,6 +317,42 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase', 'git-filter-branch'). Its first argument +denotes the command it was invoked by: currently one of `amend`, +`rebase`, or `filter-branch`. Further command-dependent arguments may +be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. + +filter-branch:: + Commits that were processed by 'git-filter-branch', but not + changed, are not included in the list. If the list is empty + after this filtering, the hook is not invoked at all. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.216.g74d8e
RFC PATCH 2/6 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
--- builtin-commit.c | 43 ++++++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin-commit.c +43 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +struct commit *commit; + commit =lookup_commit (head_sha1); +if (!commit ||parse_commit (commit)) +die ("HEAD commit disappeared right under my eyes?" ); +run_rewrite_hook (commit->object.sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -445,7 +445,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.216.g74d8e
RFC PATCH 3/6 filter-branch: invoke post-rewrite hook
In reply to Thomas Rast--- git-filter-branch.sh | 10 ++++++++++ t/t5407-post-rewrite-hook.sh | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-)
git-filter-branch.sh +10 -0
@@ -358,6 +358,10 @@ while read commit parents; do @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \ $(git write-tree) $parentstr < ../message > ../map/$commit || die "could not write rewritten commit" + new_commit=$(map $commit) + if test $commit != $new_commit; then + echo $commit $new_commit >> "$workdir"/../rewritten + fi done <../revs # If we are filtering for paths, as in the case of a subdirectory
@@ -484,6 +488,12 @@ if [ "$filter_tag_name" ]; then fi cd ../.. + +if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$workdir"/../rewritten; then + "$GIT_DIR"/hooks/post-rewrite filter-branch < "$workdir"/../rewritten +fi + rm -rf "$tempdir" trap - 0
t/t5407-post-rewrite-hook.sh +20 -0
@@ -49,4 +49,24 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git filter-branch' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f --tree-filter "touch newfile" B..HEAD && + echo filter-branch >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git filter-branch (no-op)' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f B..HEAD && + test ! -f post-rewrite.args && + test ! -f post-rewrite.data +' + test_done
Signature · 1 line
1.7.0.216.g74d8e
RFC PATCH 4/6 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
--- git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -575,6 +575,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -582,6 +583,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -768,6 +770,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -776,6 +782,10 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + git gc --auto rm -fr "$dotest"
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -69,4 +69,34 @@ test_expect_success 'git filter-branch (no-op)' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.216.g74d8e
PATCH 1/1 WIP: git notes copy --stdin
In reply to Thomas RastThis implements a 'git notes copy --stdin' mode suitable to read the data fed to the post-rewrite hook.
---
Ok, so I changed my mind and decided to implement the "make it built-in and configurable" way. This helper should work. I spent some time trying to refactor cmd_notes() into something that can nicely handle commands that do not fit the normal scheme, but eventually was too tired to continue and just crafted it in the existing code in the right place.
If nobody beats me to it I'll pick this up later this week, but tomorrow will be too busy to even think about it.
builtin-notes.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-)
builtin-notes.c +56 -0
@@ -278,6 +278,52 @@ int commit_notes(struct notes_tree *t, const char *msg)return 0 ; } +int notes_copy_from_stdin (int force) +{ +struct strbuf buf =STRBUF_INIT ; +struct notes_tree *t; + +init_notes (NULL ,NULL ,NULL ,0 ); + t = &default_notes_tree; + +while (strbuf_getline (&buf, stdin,'\n' ) !=EOF ) { +unsigned char from_obj[20 ], to_obj[20 ]; +struct strbuf **split; +const unsigned char *note; + + split =strbuf_split (&buf,' ' ); +if (!split[0 ] || !split[1 ]) +die ("Malformed input line: '%s'." , buf.buf); +strbuf_rtrim (split[0 ]); +strbuf_rtrim (split[1 ]); +if (get_sha1 (split[0 ]->buf, from_obj)) +die ("Failed to resolve '%s' as a valid ref." , split[0 ]->buf); +if (get_sha1 (split[1 ]->buf, to_obj)) +die ("Failed to resolve '%s' as a valid ref." , split[1 ]->buf); + + note =get_note (t, from_obj); +if (!force) { +const unsigned char *existing_note =get_note (t, to_obj); +if (existing_note) { +error ("Cannot copy notes. Found existing notes for object" +" %s. Use '-f' to overwrite existing notes" , +sha1_to_hex (to_obj)); +return 1 ; + } + } + +if (note) +add_note (t, to_obj, note, combine_notes_overwrite); +else +remove_note (t, to_obj); + +strbuf_list_free (split); + } + +commit_notes (t,"Notes added by 'git notes copy'" ); +return 0 ; +} +int cmd_notes (int argc,const char **argv,const char *prefix) {struct notes_tree *t;
@@ -301,6 +347,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)OPT_CALLBACK ('C' ,"reuse-message" , &msg,"OBJECT" ,"reuse specified note object" , parse_reuse_arg),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ), +OPT_BOOLEAN (0 ,"stdin" , &force,"read objects from stdin" ), OPT_END() };
@@ -351,6 +398,15 @@ int cmd_notes(int argc, const char **argv, const char *prefix)if (copy) {const char *from_ref; +if (stdin) { +if (argc >2 ) { +error ("too few parameters" ); +usage_with_options (git_notes_usage, options); + }else { + retval =notes_copy_from_stdin (force); + goto end; + } + }if (argc <3 ) {error ("too few parameters" );usage_with_options (git_notes_usage, options);
Signature · 1 line
1.7.0.224.g30f23.dirty
Re: [PATCH] WIP: git notes copy --stdin
Quoted 24 lines · Thomas Rast
This implements a 'git notes copy --stdin' mode suitable to read the data fed to the post-rewrite hook.
---Ok, so I changed my mind and decided to implement the "make it built-in and configurable" way. This helper should work. I spent some time trying to refactor
cmd_notes()into something that can nicely handle commands that do not fit the normal scheme, but eventually was too tired to continue and just crafted it in the existing code in the right place.If nobody beats me to it I'll pick this up later this week, but tomorrow will be too busy to even think about it.
builtin-notes.c | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-)
builtin-notes.c +0
-0
builtin-notes.c int commit_notes(struct notes_tree *t, const char · line 287
Quoted 10 lines
builtin-notes.c +7
-0@@ -278,6 +278,52 @@ int commit_notes(struct notes_tree *t, const char *msg) return 0; } +int notes_copy_from_stdin (int force) +{ +struct strbuf buf =STRBUF_INIT ; +struct notes_tree *t; + +init_notes (NULL ,NULL ,NULL ,0 ); + t = &default_notes_tree;
As you say, cmd_notes() should be refactored, so that you don't have to duplicate all of this (and some of the below stuff).
Quoted 25 lines
builtin-notes.c +25
-0+while (strbuf_getline (&buf, stdin,'\n' ) !=EOF ) { +unsigned char from_obj[20 ], to_obj[20 ]; +struct strbuf **split; +const unsigned char *note; + + split =strbuf_split (&buf,' ' ); +if (!split[0 ] || !split[1 ]) +die ("Malformed input line: '%s'." , buf.buf); +strbuf_rtrim (split[0 ]); +strbuf_rtrim (split[1 ]); +if (get_sha1 (split[0 ]->buf, from_obj)) +die ("Failed to resolve '%s' as a valid ref." , split[0 ]->buf); +if (get_sha1 (split[1 ]->buf, to_obj)) +die ("Failed to resolve '%s' as a valid ref." , split[1 ]->buf); + + note =get_note (t, from_obj); +if (!force) { +const unsigned char *existing_note =get_note (t, to_obj); +if (existing_note) { +error ("Cannot copy notes. Found existing notes for object" +" %s. Use '-f' to overwrite existing notes" , +sha1_to_hex (to_obj)); +return 1 ; + } + }
builtin-notes.c int commit_notes(struct notes_tree *t, const char *msg) · line 323
Quoted 10 lines
builtin-notes.c +10
-0+ +if (note) +add_note (t, to_obj, note, combine_notes_overwrite); +else +remove_note (t, to_obj); + +strbuf_list_free (split); + } + +commit_notes (t,"Notes added by 'git notes copy'" );
We (this goes for the existing commit_notes() call in cmd_notes() as well) should either check the return value for commit_notes(), or (since it currently only returns 0) we should change commit_notes() to void instead of int. Actually, the correct solution is probably to "return error()" instead of "die()" inside commit_notes(), and then check the return value.
builtin-notes.c int cmd_notes(int argc, const char **argv, const char · line 350
Quoted 11 lines
builtin-notes.c +4
-0+return 0 ; +} +int cmd_notes (int argc,const char **argv,const char *prefix) {struct notes_tree *t;@@ -301,6 +347,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix) OPT_CALLBACK('C', "reuse-message", &msg, "OBJECT","reuse specified note object" , parse_reuse_arg),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ), + OPT_BOOLEAN(0, "stdin", &force, "read objects from stdin"),
Why are you setting &force from "--stdin"?
builtin-notes.c int cmd_notes(int argc, const char **argv, const · line 402
Quoted 6 lines
builtin-notes.c +1
-0@@ -351,6 +398,15 @@ int cmd_notes(int argc, const char **argv, const char *prefix) if (copy) {const char *from_ref; +if (stdin) {
I don't think this is intended. Isn't stdin (the standard input FILE *) _always_ true?
Quoted 11 lines
builtin-notes.c +8
-0+if (argc >2 ) { +error ("too few parameters" ); +usage_with_options (git_notes_usage, options); + }else { + retval =notes_copy_from_stdin (force); + goto end; + } + }if (argc <3 ) {error ("too few parameters" );
usage_with_options(git_notes_usage, options);
The patch needs to add code that barfs if "--stdin" is used with any subcommand other than "copy".
Of course, the patch also needs documentation and tests, but I guess you knew that... ;)
I like the intent of this patch, although it needs more work before it's finished.
...Johan
Signature · 2 lines
Johan Herland, <[email protected]> www.herland.net
RFC PATCH 5/6 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
--- git-rebase--interactive.sh | 39 +++++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 0 deletions(-)
git-rebase--interactive.sh +39 -0
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/conflicted-sha make_patch "$1" git rerere die "$2"
@@ -348,6 +356,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -425,6 +434,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -438,6 +467,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -446,6 +476,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -454,6 +485,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" make_patch $sha1 + record_in_rewritten "$sha1" git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest" warn "You can amend the commit now, with"
@@ -509,6 +541,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -537,6 +570,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -685,6 +723,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/conflicted-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +78 -0
82 lines not on this page · raw message
Signature · 1 line
1.7.0.216.g74d8e
RFC PATCH 6/6 contrib: add a hook that copies notes over rewrites
In reply to Thomas RastThis hook can be used to copy your notes across rewrites. You must also choose across which type of rewrite you want to copy them, or just enable all of them by saying
git config hooks.rewriteCopyNotes all
--- contrib/hooks/post-rewrite-copy-notes | 37 +++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) create mode 100644 contrib/hooks/post-rewrite-copy-notes
contrib/hooks/post-rewrite-copy-notes new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/sh + +# This hook copies over the git-notes annotation from the +# pre-rewritten commit to the post-rewritten one. It only does so if +# the invoking command is listed in hooks.rewriteCopyNotes (which must +# be space separated). If hooks.rewriteCopyNotesVerbose is set, it +# lists the commits for which 'git notes copy' was successful on +# stderr. + +type="$1" +run= + +enabled="$(git config --get hooks.rewriteCopyNotes)" +if test "$enabled" = all || test "$enabled" = true; then + enabled="amend rebase filter-branch" +fi + +for enabled_type in $enabled; do + test "$enabled_type" = "$type" && run=t +done + +if test -z "$run"; then + exit +done + +verbose=$(git config --get hooks.rewriteCopyNotesVerbose) +test "$verbose" = true && echo "Copying notes:" >2 +end_msg="No commit had any notes." + +while read pre post extra; do + git notes copy "$pre" "$post" 2>/dev/null && + end_msg="Done." && + test "$verbose" = true && + echo " $pre -> $post" >2 +done + +test "$verbose" = true && echo "$end_msg" >2
Signature · 1 line
1.7.0.216.g74d8e
Re: [RFC PATCH 6/6] contrib: add a hook that copies notes over rewrites
contrib/hooks/post-rewrite-copy-notes line 24
Quoted 3 lines · On Sunday 14 February 2010 17:17:11 Thomas Rast wrote:
contrib/hooks/post-rewrite-copy-notes new file +3
-0+if test -z "$run"; then + exit +done
Argh, that's what I get for writing lots of tests except for the PoC hook. This should of course say 'fi' instead of 'done'. Sorry.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [RFC PATCH 3/6] filter-branch: invoke post-rewrite hook
In reply to Thomas Rastgit-filter-branch.sh if [ "$filter_tag_name" ]; then · line 495
Quoted 4 lines · Thomas Rast
git-filter-branch.sh +4
-0+if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$workdir"/../rewritten; then + "$GIT_DIR"/hooks/post-rewrite filter-branch < "$workdir"/../rewritten +fi
This sounds extra-strange. As if filter-branch is used 20 times a day. If the intent is to carry notes over to new commits, then filter-branch should grow a --notes-filter instruction, no? With an easily accessible copy-everything mode like --tagname-filter=cat.
-- Hannes
v2 cover post-rewrite / automatic notes copying
In reply to Thomas RastI originally had two series, but to retain my sanity while shuffling fixups, I based the entire batch on a rebase of jh/notes onto current master. The first four do not depend on jh/notes though, and are almost unchanged from the first round.
The docs are probably sprinkled a bit strangely over the patches, not sure if it's worth a cleanup though (or I could just gather all the docs in a final patch). At least tests should be in the right place.
Based on Hannes's comment:
Quoted 10 lines · On Monday 15 February 2010 21:36:05 Johannes Sixt wrote:
Review
Quoted 4 lines · Thomas Rast
(quoted diff) +4
-0+if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$workdir"/../rewritten; then + "$GIT_DIR"/hooks/post-rewrite filter-branch < "$workdir"/../rewritten +fiThis sounds extra-strange. As if filter-branch is used 20 times a day. If the intent is to carry notes over to new commits, then filter-branch should grow a --notes-filter instruction, no? With an easily accessible copy-everything mode like --tagname-filter=cat.
I made filter-branch extra-tweakable, but tried to stay consistent with the configuration of the rest of the series. Maybe it's a bit overengineered now, dunno.
Quoted 6 lines · On Monday 15 February 2010 02:25:52 Johan Herland wrote:
Quoted 5 lines · Thomas Rast
I spent some time trying to refactor
cmd_notes()into something that can nicely handle commands that do not fit the normal scheme, but eventually was too tired to continue and just crafted it in the existing code in the right place.
[...]
Quoted 2 lines
As you say,
cmd_notes()should be refactored, so that you don't have to duplicate all of this (and some of the below stuff).
Actually I meant something different: it took me quite some time to figure out what goes where in the flow of the current main() function, since it is sprinkled with if(subcommand) -- for most of them, several such clauses.
I guess it made sense at the time, because all commands more or less worked with the same arguments and mostly the same background logic, just in a slightly different way. But I think it's quite unnatural for an entirely-different command like 'copy --stdin'.
But maybe that's just me.
Quoted 5 lines
We (this goes for the existing
commit_notes()call incmd_notes()as well) should either check the return value forcommit_notes(), or (since it currently only returns 0) we should changecommit_notes()to void instead of int. Actually, the correct solution is probably to "returnerror()" instead of "die()" insidecommit_notes(), and then check the return value.
I'll leave that up to your judgement; I haven't looked into the API workings much, so I'm not sure when it should fail how.
[Thanks for the other comments on my embarrassing mistakes; I was apparently rather too tired to continue programming.]
Thomas Rast (11):
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: clean up t3301
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
filter-branch: invoke post-rewrite hook
filter-branch: learn how to filter notes
Documentation/config.txt | 17 +++ Documentation/git-filter-branch.txt | 20 +++- Documentation/git-notes.txt | 16 ++- Documentation/githooks.txt | 40 +++++ builtin-commit.c | 49 +++++++ builtin-notes.c | 134 +++++++++++++++++- builtin.h | 15 ++ git-am.sh | 13 ++ git-filter-branch.sh | 37 +++++ git-rebase--interactive.sh | 45 ++++++- git-rebase.sh | 6 + notes.c | 21 +++ notes.h | 9 ++ t/t3301-notes.sh | 273 +++++++++++++++++++++++------------ t/t3400-rebase.sh | 16 ++ t/t3404-rebase-interactive.sh | 10 ++ t/t5407-post-rewrite-hook.sh | 188 ++++++++++++++++++++++++ t/t7003-filter-branch.sh | 22 +++ t/t7501-commit.sh | 11 ++ 19 files changed, 843 insertions(+), 99 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
RFC PATCH v2 1/11 Documentation: document post-rewrite hook
This defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
--- Documentation/githooks.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
Documentation/githooks.txt +36 -0
@@ -317,6 +317,42 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase', 'git-filter-branch'). Its first argument +denotes the command it was invoked by: currently one of `amend`, +`rebase`, or `filter-branch`. Further command-dependent arguments may +be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. + +filter-branch:: + Commits that were processed by 'git-filter-branch', but not + changed, are not included in the list. If the list is empty + after this filtering, the hook is not invoked at all. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.53.g5c2e6.dirty
Re: [RFC PATCH v2 01/11] Documentation: document post-rewrite hook
Documentation/githooks.txt This hook is invoked by 'git gc --auto'. It takes no parameter, and · line 344
Quoted 5 lines · Thomas Rast
Documentation/githooks.txt +5
-0+rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'.
Similar to filter-branch being silent on dropped commits, I presume "rebase -i" will stay silent if a pick is removed, or rebase --skip is given.
I wondered if squash/fixup case wants to distinguish the "primary" commit and "follow-up" fixup commits (not a complaint, but thinking-aloud), but I think the rebase command itself and this hook have the same amount of information needed to guess which one is the primary and which ones are the follow ups, so it probably is Ok.
Is the order of input lines guaranteed in some way? For example, if I run rebase to make A B C into A' and B+C, do we get these three lines:
A -> A'
B -> B+C
C -> B+Cin some known order? If so, should we document that order?
Re: [RFC PATCH v2 01/11] Documentation: document post-rewrite hook
Quoted 11 lines · On Wednesday 17 February 2010 00:59:51 Junio C Hamano wrote:
Documentation/githooks.txt This hook is invoked by 'git gc --auto'. It takes no parameter, and · line 344
Quoted 5 lines · Thomas Rast
Documentation/githooks.txt +5
-0+rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'.Similar to filter-branch being silent on dropped commits, I presume "rebase -i" will stay silent if a pick is removed, or rebase --skip is given.
Indeed. Due to the way that rebase works, it would be a hassle to report '00..00' (or so) for dropped commits, so I'm not too keen on going there. (My intended use-cases don't require it. Do you have one that does?) Documenting this absence wouldn't hurt though.
Quoted 5 lines
I wondered if squash/fixup case wants to distinguish the "primary" commit and "follow-up" fixup commits (not a complaint, but thinking-aloud), but I think the rebase command itself and this hook have the same amount of information needed to guess which one is the primary and which ones are the follow ups, so it probably is Ok.
That's what I put in the <extra-info> for :-)
Quoted 8 lines
Is the order of input lines guaranteed in some way? For example, if I run rebase to make A B C into A' and B+C, do we get these three lines:
A -> A' B -> B+C C -> B+Cin some known order? If so, should we document that order?
Currently they're in the order that they were rewritten, but what would the hook learn from that?
I left it unspecified because I wasn't sure we would always have the list in a specific order (e.g., when reconstructed from a hash map of rewritings, it's not) but then, keeping the list ordered isn't that expensive either...
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [RFC PATCH v2 01/11] Documentation: document post-rewrite hook
Quoted 13 lines · Thomas Rast
Quoted 11 lines · On Wednesday 17 February 2010 00:59:51 Junio C Hamano wrote:
Documentation/githooks.txt This hook is invoked by 'git gc --auto'. It takes no parameter, and · line 344
Quoted 5 lines · Thomas Rast
Documentation/githooks.txt +5
-0+rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'.Similar to filter-branch being silent on dropped commits, I presume "rebase -i" will stay silent if a pick is removed, or rebase --skip is given.
Quoted 4 lines
Indeed. Due to the way that rebase works, it would be a hassle to report '00..00' (or so) for dropped commits, so I'm not too keen on going there. (My intended use-cases don't require it. Do you have one that does?) Documenting this absence wouldn't hurt though.
I was solely interested in the documentation at this point. I don't see a reason to report "old -> nul"; somebody else may, but I don't.
Quoted 11 lines
Quoted 8 lines
Is the order of input lines guaranteed in some way? For example, if I run rebase to make A B C into A' and B+C, do we get these three lines:
A -> A' B -> B+C C -> B+Cin some known order? If so, should we document that order?
Currently they're in the order that they were rewritten, but what would the hook learn from that?
For example, a user may say "I _always_ make a big commit that describes everything at the beginning, and then follow-ups are irrelevant", in which case the user may want to say "notes for B carries to B+C but discard anything attached to C" in _his_ hook.
Another example. A build-bot may attach "builds fine" note to C but B may have "failed to build" note without the fix-up in C. B+C will want to have the "builds fine" note from C (you would probably also need to verify that C^{tree} == (B+C)^{tree} before moving the note, but the point is you do not even want to consider moving it from B to B+C).
These become possible if the output at least guarantees topological ordering for things that are squashed into one.
But again I am just thinking aloud. I don't know how much benefit will such a guarantee give us in practice.
RFC PATCH v2 2/11 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
--- builtin-commit.c | 43 ++++++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin-commit.c +43 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +struct commit *commit; + commit =lookup_commit (head_sha1); +if (!commit ||parse_commit (commit)) +die ("HEAD commit disappeared right under my eyes?" ); +run_rewrite_hook (commit->object.sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -445,7 +445,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 3/11 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
--- git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -575,6 +575,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -582,6 +583,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -768,6 +770,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -776,6 +782,10 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + git gc --auto rm -fr "$dotest"
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 4/11 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
--- git-rebase--interactive.sh | 39 +++++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 0 deletions(-)
git-rebase--interactive.sh +39 -0
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/conflicted-sha make_patch "$1" git rerere die "$2"
@@ -348,6 +356,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -425,6 +434,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -438,6 +467,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -446,6 +476,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -454,6 +485,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" make_patch $sha1 + record_in_rewritten "$sha1" git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest" warn "You can amend the commit now, with"
@@ -509,6 +541,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -537,6 +570,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -685,6 +723,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/conflicted-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +78 -0
82 lines not on this page · raw message
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 5/11 notes: clean up t3301
In reply to Thomas RastThe existing tests handrolled test_commit, so use that instead.
Unfortunately this changes all sha1's. Since we're not supposed to unneccessarily rely on them anyway, introduce a small helper that filters out the commit headers before comparing, and remove them from the expected outputs.
--- t/t3301-notes.sh | 141 ++++++++++++++++++------------------------------------ 1 files changed, 46 insertions(+), 95 deletions(-)
t/t3301-notes.sh +46 -95
@@ -7,6 +7,15 @@ test_description='Test commit notes' . ./test-lib.sh +strip_header () { + sed -i '/^\(commit\|tree\|parent\) /d' "$@" +} + +strip_then_cmp () { + strip_header "$2" + test_cmp "$@" +} + cat > fake_editor.sh << \EOF echo "$MSG" > "$1" echo "$MSG" >& 2
@@ -20,14 +29,8 @@ test_expect_success 'cannot annotate non-existing HEAD' ' ' test_expect_success setup ' - : > a1 && - git add a1 && - test_tick && - git commit -m 1st && - : > a2 && - git add a2 && - test_tick && - git commit -m 2nd + test_commit 1st && + test_commit 2nd ' test_expect_success 'need valid notes ref' '
@@ -92,7 +95,6 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' ' ' cat > expect << EOF -commit 268048bfb8a1fb38e703baceb8ab235421bf80c5 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:14:13 2005 -0700
@@ -105,21 +107,17 @@ EOF test_expect_success 'show notes' ' ! (git cat-file commit HEAD | grep b1) && git log -1 > output && - test_cmp expect output + strip_then_cmp expect output ' test_expect_success 'create multi-line notes (setup)' ' - : > a3 && - git add a3 && - test_tick && - git commit -m 3rd && + test_commit 3rd && MSG="b3 c3c3c3c3 d3d3d3" git notes add ' cat > expect-multiline << EOF -commit 1584215f1d29c65e99c6c6848626553fdd07fd75 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:15:13 2005 -0700
@@ -136,19 +134,15 @@ cat expect >> expect-multiline test_expect_success 'show multi-line notes' ' git log -2 > output && - test_cmp expect-multiline output + strip_then_cmp expect-multiline output ' test_expect_success 'create -F notes (setup)' ' - : > a4 && - git add a4 && - test_tick && - git commit -m 4th && + test_commit 4th && echo "xyzzy" > note5 && git notes add -F note5 ' cat > expect-F << EOF -commit 15023535574ded8b1a89052b32673f84cf9582b8 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:16:13 2005 -0700
@@ -163,13 +157,10 @@ cat expect-multiline >> expect-F test_expect_success 'show -F notes' ' git log -3 > output && - test_cmp expect-F output + strip_then_cmp expect-F output ' cat >expect << EOF -commit 15023535574ded8b1a89052b32673f84cf9582b8 -tree e070e3af51011e47b183c33adf9736736a525709 -parent 1584215f1d29c65e99c6c6848626553fdd07fd75 author A U Thor <[email protected]> 1112912173 -0700 committer C O Mitter <[email protected]> 1112912173 -0700
@@ -177,7 +168,7 @@ committer C O Mitter <[email protected]> 1112912173 -0700 EOF test_expect_success 'git log --pretty=raw does not show notes' ' git log -1 --pretty=raw >output && - test_cmp expect output + strip_then_cmp expect output ' cat >>expect <<EOF
@@ -187,7 +178,7 @@ Notes: EOF test_expect_success 'git log --show-notes' ' git log -1 --pretty=raw --show-notes >output && - test_cmp expect output + strip_then_cmp expect output ' test_expect_success 'git log --no-notes' '
@@ -220,10 +211,7 @@ do done test_expect_success 'create -m notes (setup)' ' - : > a5 && - git add a5 && - test_tick && - git commit -m 5th && + test_commit 5th && git notes add -m spam -m "foo bar baz"
@@ -231,7 +219,6 @@ baz" whitespace=" " cat > expect-m << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d Author: A U Thor <[email protected]> Date: Thu Apr 7 15:17:13 2005 -0700
@@ -250,7 +237,7 @@ cat expect-F >> expect-m test_expect_success 'show -m notes' ' git log -4 > output && - test_cmp expect-m output + strip_then_cmp expect-m output ' test_expect_success 'remove note with add -f -F /dev/null (setup)' '
@@ -258,7 +245,6 @@ test_expect_success 'remove note with add -f -F /dev/null (setup)' ' ' cat > expect-rm-F << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d Author: A U Thor <[email protected]> Date: Thu Apr 7 15:17:13 2005 -0700
@@ -270,7 +256,7 @@ cat expect-F >> expect-rm-F test_expect_success 'verify note removal with -F /dev/null' ' git log -4 > output && - test_cmp expect-rm-F output && + strip_then_cmp expect-rm-F output && ! git notes show '
@@ -280,7 +266,7 @@ test_expect_success 'do not create empty note with -m "" (setup)' ' test_expect_success 'verify non-creation of note with -m ""' ' git log -4 > output && - test_cmp expect-rm-F output && + strip_then_cmp expect-rm-F output && ! git notes show '
@@ -301,7 +287,7 @@ test_expect_success 'create note with combination of -m and -F' ' echo "zyxxy" > note_b && git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" && git notes show > output && - test_cmp expect-combine_m_and_F output + strip_then_cmp expect-combine_m_and_F output ' test_expect_success 'remove note with "git notes remove" (setup)' '
@@ -310,13 +296,11 @@ test_expect_success 'remove note with "git notes remove" (setup)' ' ' cat > expect-rm-remove << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d Author: A U Thor <[email protected]> Date: Thu Apr 7 15:17:13 2005 -0700 5th -commit 15023535574ded8b1a89052b32673f84cf9582b8 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:16:13 2005 -0700
@@ -328,13 +312,13 @@ cat expect-multiline >> expect-rm-remove test_expect_success 'verify note removal with "git notes remove"' ' git log -4 > output && - test_cmp expect-rm-remove output && + strip_then_cmp expect-rm-remove output && ! git notes show HEAD^ ' cat > expect << EOF -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 +c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691 +c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290 EOF test_expect_success 'list notes with "git notes list"' '
@@ -401,15 +385,11 @@ test_expect_success 'appending empty string to non-existing note does not create ' test_expect_success 'create other note on a different notes ref (setup)' ' - : > a6 && - git add a6 && - test_tick && - git commit -m 6th && + test_commit 6th && GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" ' cat > expect-other << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:18:13 2005 -0700
@@ -420,7 +400,6 @@ Notes: EOF cat > expect-not-other << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:18:13 2005 -0700
@@ -429,23 +408,23 @@ EOF test_expect_success 'Do not show note on other ref by default' ' git log -1 > output && - test_cmp expect-not-other output + strip_then_cmp expect-not-other output ' test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' GIT_NOTES_REF="refs/notes/other" git log -1 > output && - test_cmp expect-other output + strip_then_cmp expect-other output ' test_expect_success 'Do show note when ref is given in core.notesRef config' ' git config core.notesRef "refs/notes/other" && git log -1 > output && - test_cmp expect-other output + strip_then_cmp expect-other output ' test_expect_success 'Do not show note when core.notesRef is overridden' ' GIT_NOTES_REF="refs/notes/wrong" git log -1 > output && - test_cmp expect-not-other output + strip_then_cmp expect-not-other output ' test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
@@ -466,7 +445,6 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' ' cat > expect << EOF -commit 2ede89468182a62d0bde2583c736089bcf7d7e92 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:19:13 2005 -0700
@@ -477,27 +455,20 @@ Notes: EOF test_expect_success 'create note from other note with "git notes add -C"' ' - : > a7 && - git add a7 && - test_tick && - git commit -m 7th && + test_commit 7th && git notes add -C $(git notes list HEAD^) && git log -1 > actual && - test_cmp expect actual && + strip_then_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' - : > a8 && - git add a8 && - test_tick && - git commit -m 8th && + test_commit 8th && test_must_fail git notes add -C deadbeef && test_must_fail git notes list HEAD ' cat > expect << EOF -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b Author: A U Thor <[email protected]> Date: Thu Apr 7 15:21:13 2005 -0700
@@ -508,26 +479,19 @@ Notes: EOF test_expect_success 'create note from other note with "git notes add -c"' ' - : > a9 && - git add a9 && - test_tick && - git commit -m 9th && + test_commit 9th && MSG="yet another note" git notes add -c $(git notes list HEAD^^) && git log -1 > actual && - test_cmp expect actual + strip_then_cmp expect actual ' test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' - : > a10 && - git add a10 && - test_tick && - git commit -m 10th && + test_commit 10th && test_must_fail MSG="yet another note" git notes add -c deadbeef && test_must_fail git notes list HEAD ' cat > expect << EOF -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b Author: A U Thor <[email protected]> Date: Thu Apr 7 15:21:13 2005 -0700
@@ -542,11 +506,10 @@ EOF test_expect_success 'append to note from other note with "git notes append -C"' ' git notes append -C $(git notes list HEAD^) HEAD^ && git log -1 HEAD^ > actual && - test_cmp expect actual + strip_then_cmp expect actual ' cat > expect << EOF -commit ffed603236bfa3891c49644257a83598afe8ae5a Author: A U Thor <[email protected]> Date: Thu Apr 7 15:22:13 2005 -0700
@@ -559,11 +522,10 @@ EOF test_expect_success 'create note from other note with "git notes append -c"' ' MSG="other note" git notes append -c $(git notes list HEAD^) && git log -1 > actual && - test_cmp expect actual + strip_then_cmp expect actual ' cat > expect << EOF -commit ffed603236bfa3891c49644257a83598afe8ae5a Author: A U Thor <[email protected]> Date: Thu Apr 7 15:22:13 2005 -0700
@@ -578,11 +540,10 @@ EOF test_expect_success 'append to note from other note with "git notes append -c"' ' MSG="yet another note" git notes append -c $(git notes list HEAD) && git log -1 > actual && - test_cmp expect actual + strip_then_cmp expect actual ' cat > expect << EOF -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be Author: A U Thor <[email protected]> Date: Thu Apr 7 15:23:13 2005 -0700
@@ -595,25 +556,21 @@ $whitespace EOF test_expect_success 'copy note with "git notes copy"' ' - : > a11 && - git add a11 && - test_tick && - git commit -m 11th && + test_commit 11th && git notes copy HEAD^ HEAD && git log -1 > actual && - test_cmp expect actual && + strip_then_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' test_expect_success 'prevent overwrite with "git notes copy"' ' test_must_fail git notes copy HEAD~2 HEAD && git log -1 > actual && - test_cmp expect actual && + strip_then_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' cat > expect << EOF -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be Author: A U Thor <[email protected]> Date: Thu Apr 7 15:23:13 2005 -0700
@@ -628,19 +585,13 @@ EOF test_expect_success 'allow overwrite with "git notes copy -f"' ' git notes copy -f HEAD~2 HEAD && git log -1 > actual && - test_cmp expect actual && + strip_then_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" ' test_expect_success 'cannot copy note from object without notes' ' - : > a12 && - git add a12 && - test_tick && - git commit -m 12th && - : > a13 && - git add a13 && - test_tick && - git commit -m 13th && + test_commit 12th && + test_commit 13th && test_must_fail git notes copy HEAD^ HEAD '
Signature · 1 line
1.7.0.53.g5c2e6.dirty
Re: [RFC PATCH v2 05/11] notes: clean up t3301
Quoted 17 lines · Thomas Rast
The existing tests handrolled
test_commit, so use that instead.Unfortunately this changes all sha1's. Since we're not supposed to unneccessarily rely on them anyway, introduce a small helper that filters out the commit headers before comparing, and remove them from the expected outputs.
Signed-off-by Thomas Rast <[email protected]>--- t/t3301-notes.sh | 141 ++++++++++++++++++------------------------------------ 1 files changed, 46 insertions(+), 95 deletions(-)t/t3301-notes.sh +0
-0
t/t3301-notes.sh test_description='Test commit notes' · line 12
Quoted 6 lines
t/t3301-notes.sh +3
-0@@ -7,6 +7,15 @@ test_description='Test commit notes' . ./test-lib.sh +strip_header () { + sed -i '/^\(commit\|tree\|parent\) /d' "$@" +}
I do not think -i is portable. Neither the use of ERE elements by quoting them with backslash (which is a non-POSIX GNU extension IIRC).
You use this only for one side of test_cmp, so you should be able to do something like:
strip_then_cmp () {
sed -e "/^[ctp][a-z]* $x40$/d" "$2" |
test_cmp "$1" -
}But because you are using test_commit to freeze the time and get stable output, and because you still have something like this anyway:
t/t3301-notes.sh cat expect-multiline >> expect-rm-remove · line 322
Quoted 6 lines
t/t3301-notes.sh +2
-2cat > expect << EOF -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 +c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691 +c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290 EOF
it might be easier to do without such a niceness.
RFC PATCH v2 6/11 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
--- Documentation/git-notes.txt | 12 ++++++++- builtin-notes.c | 57 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 21 ++++++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 32 ++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -55,6 +55,16 @@ copy:: objects has none. (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin-notes.c +56 -1
83 lines not on this page · raw message
notes.c +21 -0
@@ -1030,3 +1030,24 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,free (msg); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note; + + note =get_note (t, from_obj); +if (!force) { +const unsigned char *existing_note =get_note (t, to_obj); +if (existing_note) +return 1 ; + } + +if (note) +add_note (t, to_obj, note, combine_fn); +else +remove_note (t, to_obj); + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +32 -0
@@ -595,4 +595,36 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes: + yet another note +$whitespace + yet another note + +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes: + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + strip_then_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 7/11 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
--- Documentation/config.txt | 13 ++++++ Documentation/git-notes.txt | 4 ++ Documentation/githooks.txt | 4 ++ builtin-notes.c | 89 +++++++++++++++++++++++++++++++++++--- builtin.h | 15 ++++++ t/t3301-notes.sh | 100 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 219 insertions(+), 6 deletions(-)
Documentation/config.txt +13 -0
@@ -1300,6 +1300,19 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `false`. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -34,6 +34,10 @@ the empty string. Alternatively, you can set it to a different ref, something like "refs/notes/bugzilla". This setting can be overridden by the environment variable "GIT_NOTES_REF". +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin-notes.c +83 -6
135 lines not on this page · raw message
builtin.h +15 -0
@@ -20,6 +20,21 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree *tree; +const char *cmd; +int enabled; +combine_notes_fn *combine; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
t/t3301-notes.sh +100 -0
104 lines not on this page · raw message
Signature · 1 line
1.7.0.53.g5c2e6.dirty
Re: [RFC PATCH v2 07/11] notes: implement helpers needed for note copying during rewrite
Quoted 2 lines · Thomas Rast
Implement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
I find it somewhat unnerving that this series is a bit overengineered to have fancier and facier handling of notes, while at the same time still sticking to the "only one default notes tree" mode of operation. Are you digging a deep hole that you will find hard to get out of when you finally need to support copying/rewriting notes from multiple trees at the same time?
Re: [RFC PATCH v2 07/11] notes: implement helpers needed for note copying during rewrite
Quoted 11 lines · On Wednesday 17 February 2010 00:58:18 Junio C Hamano wrote:
Quoted 2 lines · Thomas Rast
Implement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
I find it somewhat unnerving that this series is a bit overengineered to have fancier and facier handling of notes, while at the same time still sticking to the "only one default notes tree" mode of operation. Are you digging a deep hole that you will find hard to get out of when you finally need to support copying/rewriting notes from multiple trees at the same time?
Hmm, very good point.
I believe the code in this patch is fairly well-prepared to deal with it. It would merely need to learn to store a list of trees in the notes_rewrite_cfg, provided that it's ok to load them all simultaneously.
However, I haven't really thought about having several notes trees. Is this automatic copying the only operation that needs this feature, or were you thinking of others too? Is it enough to, say, introduce a way of configuring it at the branch level, or declaring that we rewrite everything in refs/notes, or some such?
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [RFC PATCH v2 07/11] notes: implement helpers needed for note copying during rewrite
Quoted 4 lines · Thomas Rast
I believe the code in this patch is fairly well-prepared to deal with it. It would merely need to learn to store a list of trees in the
notes_rewrite_cfg, provided that it's ok to load them all simultaneously.
I was mentally handwaving to myself that all will be well in the end ;-) but thought that it would never hurt to ask if you have thought things through.
Quoted 3 lines
However, I haven't really thought about having several notes trees. Is this automatic copying the only operation that needs this feature, or were you thinking of others too?
I was envisioning that most of the time people would want to read from (and probably concatenate, or output with the origin information tagged in) multiple notes but want to create into a single one. But updating for rewritten commits fundamentally need to happen in all of these multiple notes trees they would want to read from.
For example, if I have amlog notes to record the message-id of the original message I ran "am" to queue people's patches, I would want to carry that even after I make typofixes in the commit log message or in the code using "commit --amend". If you have buildlog notes to record the output from continuously running build-test-bot, you probably do not want these notes to get carried forward when you rebase a branch.
In "log --show-notes=amlog --show-notes=buildlog" output, we will see notes from both amlog and buildlog in the original history, but only the notes from amlog will be shown in the rebased history.
RFC PATCH v2 8/11 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
--- git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 16 ++++++++++++++++ t/t3404-rebase-interactive.sh | 10 ++++++++++ 5 files changed, 35 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -782,8 +782,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi git gc --auto
git-rebase--interactive.sh +4 -0
@@ -570,6 +570,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +16 -0
@@ -151,4 +151,20 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +10 -0
@@ -553,4 +553,14 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 9/11 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
--- builtin-commit.c | 6 ++++++ t/t7501-commit.sh | 11 +++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
builtin-commit.c +6 -0
@@ -1341,9 +1341,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) {struct commit *commit; +struct notes_rewrite_cfg *cfg; commit =lookup_commit (head_sha1);if (!commit ||parse_commit (commit))die ("HEAD commit disappeared right under my eyes?" ); + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, commit->object.sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (commit->object.sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +11 -0
@@ -425,4 +425,15 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 10/11 filter-branch: invoke post-rewrite hook
In reply to Thomas RastWith a twist: since this is supposed to be the be-all end-all of rewriting, we give the user the chance to override the hook.
--- Documentation/git-filter-branch.txt | 7 ++++++- git-filter-branch.sh | 21 +++++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletions(-)
Documentation/git-filter-branch.txt +6 -1
@@ -12,7 +12,7 @@ SYNOPSIS [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] - [--prune-empty] + [--prune-empty] [--post-rewrite <command>] [--original <namespace>] [-d <directory>] [-f | --force] [--] [<rev-list options>...]
@@ -182,6 +182,11 @@ the nearest ancestor that was not excluded. of the `git commit-tree "$@"` idiom in your commit filter to make that happen. +--post-rewrite <command>:: + Overrides the post-rewrite hook (if you have one). To bypass + the hook for this invocation, pass `:`. See + linkgit:githooks[1]. + --original <namespace>:: Use this option to set the namespace where the original commits will be stored. The default value is 'refs/original'.
git-filter-branch.sh +21 -0
@@ -101,6 +101,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] + [--post-rewrite <command>] [--original <namespace>] [-d <directory>] [-f | --force] [<rev-list options>...]"
@@ -126,6 +127,13 @@ orig_namespace=refs/original/ force= prune_empty= remap_to_ancestor= + +if test -x "$GIT_DIR"/hooks/post-rewrite; then + post_rewrite=$(git rev-parse --sq-quote "$GIT_DIR"/hooks/post-rewrite) +else + post_rewrite=: +fi + while : do case "$1" in
@@ -190,6 +198,10 @@ do filter_subdir="$OPTARG" remap_to_ancestor=t ;; + --post-rewrite) + post_rewrite="$OPTARG" + post_rewrite_given=t + ;; --original) orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/ ;;
@@ -358,6 +370,10 @@ while read commit parents; do @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \ $(git write-tree) $parentstr < ../message > ../map/$commit || die "could not write rewritten commit" + new_commit=$(map $commit) + if test $commit != $new_commit; then + echo $commit $new_commit >> "$workdir"/../rewritten + fi done <../revs # If we are filtering for paths, as in the case of a subdirectory
@@ -484,6 +500,11 @@ if [ "$filter_tag_name" ]; then fi cd ../.. + +if test -s "$workdir"/../rewritten; then + eval "$post_rewrite" 'filter-branch < "$workdir"/../rewritten' +fi + rm -rf "$tempdir" trap - 0
t/t5407-post-rewrite-hook.sh +28 -0
@@ -157,4 +157,32 @@ EOF verify_hook_input ' +test_expect_success 'git filter-branch' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f --tree-filter "touch newfile" B..HEAD && + echo filter-branch >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git filter-branch (no-op)' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f B..HEAD && + test ! -f post-rewrite.args && + test ! -f post-rewrite.data +' + +test_expect_success 'git filter-branch --post-rewrite :' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f --post-rewrite : --tree-filter "touch newfile" B..HEAD && + test ! -f post-rewrite.args && + test ! -f post-rewrite.data +' + test_done
Signature · 1 line
1.7.0.53.g5c2e6.dirty
RFC PATCH v2 11/11 filter-branch: learn how to filter notes
In reply to Thomas RastTeach filter-branch a new option --notes-filter that acts as a pipe filter (much like --msg-filter) for the commit notes. For consistency with the note copying support in amend/rebase, it defaults to 'cat' if notes.rewrite.filter-branch is set.
--- Documentation/config.txt | 12 ++++++++---- Documentation/git-filter-branch.txt | 13 +++++++++++++ Documentation/githooks.txt | 8 ++++---- git-filter-branch.sh | 18 +++++++++++++++++- t/t7003-filter-branch.sh | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-)
Documentation/config.txt +8 -4
@@ -1301,10 +1301,10 @@ mergetool.prompt:: Prompt before each invocation of the merge resolution program. notes.rewrite.<command>:: - When rewriting commits with <command> (currently `amend` or - `rebase`) and this variable is set to `true`, git - automatically copies your notes from the original to the - rewritten commit. Defaults to `false`. + When rewriting commits with <command> (currently `amend`, + `rebase` or `filter-branch`) and this variable is set to + `true`, git automatically copies your notes from the original + to the rewritten commit. Defaults to `false`. notes.rewriteMode:: When copying notes during a rewrite (see the
@@ -1312,6 +1312,10 @@ notes.rewriteMode:: the target commit already has a note. Must be one of `overwrite`, `concatenate`, or `ignore`. Defaults to `concatenate`. ++ +Note that 'git-filter-branch' ignores this setting and always +overwrites; see the description of `--notes-filter` in +linkgit:git-filter-branch[1]. pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no
Documentation/git-filter-branch.txt +13 -0
@@ -161,6 +161,19 @@ to other tags will be rewritten to point to the underlying commit. The result will contain that directory (and only that) as its project root. Implies --remap-to-ancestor. +--notes-filter <command>:: + This filter rewrites the notes (see linkgit:git-notes[1]). It + gets the old notes on standard input, and its standard output + is written as the new note (overwriting any existing notes). ++ +Defaults to doing nothing, unless the `notes.rewrite.filter-branch` +option is set, in which case it copies the notes (i.e., defaults to +`cat`). ++ +In addition to the usual variables, GIT_NEW_COMMIT is set to the +result of the rewriting so that the filter can get at the existing +notes, if any. + --remap-to-ancestor:: Rewrite refs to the nearest rewritten ancestor instead of ignoring them.
Documentation/githooks.txt +4 -4
@@ -350,11 +350,11 @@ rebase:: filter-branch:: Commits that were processed by 'git-filter-branch', but not changed, are not included in the list. If the list is empty - after this filtering, the hook is not invoked at all. + after this filtering, the hook is not invoked at all. Also + see the `--post-rewrite` option in + linkgit:git-filter-branch[1]. -There is no default 'post-rewrite' hook, but see the -`post-receive-copy-notes` script in `contrib/hooks` for an example -that copies your git-notes to the rewritten commits. +There is no default 'post-rewrite' hook. GIT
git-filter-branch.sh +17 -1
@@ -101,7 +101,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] - [--post-rewrite <command>] + [--post-rewrite <command>] [--notes-filter <command>] [--original <namespace>] [-d <directory>] [-f | --force] [<rev-list options>...]"
@@ -134,6 +134,12 @@ else post_rewrite=: fi +if test "$(git config --bool notes.rewrite.filter-branch)"; then + filter_notes=cat +else + filter_notes= +fi + while : do case "$1" in
@@ -198,6 +204,9 @@ do filter_subdir="$OPTARG" remap_to_ancestor=t ;; + --notes-filter) + filter_notes="$OPTARG" + ;; --post-rewrite) post_rewrite="$OPTARG" post_rewrite_given=t
@@ -374,6 +383,13 @@ while read commit parents; do if test $commit != $new_commit; then echo $commit $new_commit >> "$workdir"/../rewritten fi + if test -n "$filter_notes"; then + if git notes show $commit >../note 2>/dev/null; then + export GIT_NEW_COMMIT="$new_commit" + eval "$filter_notes" <../note | + git notes add -F- -f $new_commit + fi + fi done <../revs # If we are filtering for paths, as in the case of a subdirectory
t/t7003-filter-branch.sh +22 -0
@@ -306,6 +306,28 @@ test_expect_success '--remap-to-ancestor with filename filters' ' test $orig_invariant = $(git rev-parse invariant) ' +test_expect_success '--notes-filter off' ' + git checkout master && + test_commit notes-foo && + git notes add -mtestnote && + git filter-branch -f --tree-filter "touch notes-1" HEAD^.. && + test_must_fail git notes show +' + +test_expect_success '--notes-filter manually' ' + git reset --hard notes-foo && + git filter-branch -f --notes-filter "sed s/test/foo/" \ + --tree-filter "touch notes-2" HEAD^.. && + test foonote = "$(git notes show)" +' + +test_expect_success '--notes-filter implicit' ' + git reset --hard notes-foo && + git config notes.rewrite.filter-branch true && + git filter-branch -f --tree-filter "touch notes-3" HEAD^.. && + test testnote = "$(git notes show)" +' + test_expect_success 'setup submodule' ' rm -fr ?* .git && git init &&
Signature · 1 line
1.7.0.53.g5c2e6.dirty
Re: [RFC PATCH v2 11/11] filter-branch: learn how to filter notes
Documentation/git-filter-branch.txt to other tags will be rewritten to point to the underlying commit. · line 175
Quoted 12 lines · Thomas Rast
+--notes-filter <command>::
Documentation/git-filter-branch.txt +11
-0+ This filter rewrites the notes (see linkgit:git-notes[1]). It + gets the old notes on standard input, and its standard output + is written as the new note (overwriting any existing notes). ++ +Defaults to doing nothing, unless the `notes.rewrite.filter-branch` +option is set, in which case it copies the notes (i.e., defaults to +`cat`). ++ +In addition to the usual variables, GIT_NEW_COMMIT is set to the +result of the rewriting so that the filter can get at the existing +notes, if any.
I think that this form of --notes-filter is not flexible enough.
1. There is no possibility for the filter to decide whether the note should be attached to the rewritten commit or not.
2. The implementation is not concerned about different notes namespaces (IIUC).
3. There is probably more.
One use-case that comes to mind is to move notes from one particular namespace to a different one (and I mean move, not just copy). Don't know if 'git notes' itself has such a feature.
I am not a 'git notes' user at this time, nor do I know anything about the implementation, nor did I follow any discussions about notes, hence, I'm not in the position to judge what --notes-filter could be useful for. I know I talked you into implementing it, but that is just because I dislike that filter-branch calls a post-rewrite hook (that just doesn't sound right to me, given the one-shot nature of filter-branch), and your intention obviously was to transfer notes.
-- Hannes
Re: [RFC PATCH v2 11/11] filter-branch: learn how to filter notes
Quoted 4 lines · On Wednesday 17 February 2010 20:59:26 Johannes Sixt wrote:
I think that this form of --notes-filter is not flexible enough.
1. There is no possibility for the filter to decide whether the note should be attached to the rewritten commit or not.
That's not 100% correct, but it's not your fault for not knowing: if you add an empty note, that's the same as removing it.
Quoted 5 lines
2. The implementation is not concerned about different notes namespaces (IIUC).
3. There is probably more.
Quoted 8 lines
One use-case that comes to mind is to move notes from one particular namespace to a different one (and I mean move, not just copy). Don't know if 'git notes' itself has such a feature.
I am not a 'git notes' user at this time, nor do I know anything about the implementation, nor did I follow any discussions about notes, hence, I'm not in the position to judge what --notes-filter could be useful for.
I'm currently leaning towards declaring this the realm of --post-rewrite, not --notes-filter. I'm not saying that the former is the perfect / most convenient format in which such a hook could be specified, but I believe its input should just be pre and post rewrite sha1. Using it to move notes, or whatever, should be up to the user.
That's not to say that there shouldn't be some convenient interface to manage several notes trees, which I'm not yet clear on.
Quoted 4 lines
I know I talked you into implementing it, but that is just because I dislike that filter-branch calls a post-rewrite hook (that just doesn't sound right to me, given the one-shot nature of filter-branch), and your intention obviously was to transfer notes.
No (as I said in the original series leader) my original motivation was to have a hook that can record the pre-write sha1 in a note on the rewritten commit. I noticed that it could also be used to transfer the notes to the rewritten commit, which was part of the reason why I implemented it.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH 1/1 Support showing notes from more than one notes tree
In reply to Junio C HamanoWith this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
---
I'm running out of git time today, so I'm floating this weatherbaloon to demonstrate how I would like to get around the limitations discussed by Junio:
Quoted 5 lines
I was envisioning that most of the time people would want to read from (and probably concatenate, or output with the origin information tagged in) multiple notes but want to create into a single one. But updating for rewritten commits fundamentally need to happen in all of these multiple notes trees they would want to read from.
This patch is the display-several-trees bit. I'm assuming that it's ok to load all notes trees at once. (Obviously it lacks docs, and it also breaks test because of the new formatting that shows 'Notes from notes/someref'. Please ignore those for now.)
My actual intent was to allow more than one notes.displayref config setting, and loading all of them. But this doesn't seem to work; a debugging print confirms that notes_display_config sees the entry, but another debugging print shows that it only ever loads one of them. What am I doing wrong?
I plan on having another set of configs called notes.rewriteRef that gives the list of refs that should have their notes rewritten automatically along with their commits. [The rewriteMode setting could become '<mode> for <ref>' if we want to let the user configure it on a per-ref/glob basis.]
Finally, git-notes should probably grow a --ref option that serves as a more convenient way of setting GIT_NOTES_REF.
notes.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- notes.h | 1 + pretty.c | 6 ++-- 3 files changed, 80 insertions(+), 9 deletions(-)
notes.c +76 -6
@@ -5,6 +5,8 @@#include "utf8.h" #include "strbuf.h" #include "tree-walk.h" +#include "string-list.h" +#include "refs.h" /* * Use a non-balancing simple 16-tree structure with struct int_node as
@@ -68,6 +70,9 @@ struct non_note {struct notes_tree default_notes_tree; +struct string_list display_notes_refs; +struct notes_tree **display_notes_trees; +static void load_subtree (struct notes_tree *t,struct leaf_node *subtree,struct int_node *node,unsigned int n);
@@ -828,6 +833,36 @@ int combine_notes_ignore(unsigned char *cur_sha1,return 0 ; } +static int read_one_display_ref (const char *path,const unsigned char *sha1, +int flag,void *cb) +{ +string_list_insert (path, &display_notes_refs); +return 0 ; +} + + +static int notes_display_config (const char *k,const char *v,void *cb) +{ +if (!strcmp (k,"notes.displayref" )) { +for_each_glob_ref (read_one_display_ref, v,NULL ); +return 0 ; + } + +return 0 ; +} + +static const char *default_notes_ref () +{ +const char *notes_ref =NULL ; +if (!notes_ref) + notes_ref =getenv (GIT_NOTES_REF_ENVIRONMENT ); +if (!notes_ref) + notes_ref = notes_ref_name;/* value of core.notesRef config */ +if (!notes_ref) + notes_ref =GIT_NOTES_DEFAULT_REF ; +return notes_ref; +} +void init_notes (struct notes_tree *t,const char *notes_ref,combine_notes_fn combine_notes,int flags) {
@@ -840,11 +875,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,assert (!t->initialized);if (!notes_ref) - notes_ref =getenv (GIT_NOTES_REF_ENVIRONMENT ); -if (!notes_ref) - notes_ref = notes_ref_name;/* value of core.notesRef config */ -if (!notes_ref) - notes_ref =GIT_NOTES_DEFAULT_REF ; + notes_ref =default_notes_ref ();if (!combine_notes) combine_notes = combine_notes_concatenate;
@@ -868,6 +899,29 @@ void init_notes(struct notes_tree *t, const char *notes_ref,load_subtree (t, &root_tree, t->root,0 ); } +static int load_one_display_note_ref (struct string_list_item *item, +void *cb_data) +{ +int *counter = cb_data; +struct notes_tree *t =xcalloc (1 ,sizeof (struct notes_tree )); +init_notes (t, item->string, combine_notes_ignore,0 ); + display_notes_trees[(*counter)++] = t; +return 0 ; +} + +void init_display_notes () +{ +int cb_counter =0 ; +string_list_insert (default_notes_ref (), &display_notes_refs); + display_notes_refs.strdup_strings =1 ; +git_config (notes_display_config,NULL ); + display_notes_trees =xmalloc ((display_notes_refs.nr+1 ) + *sizeof (struct notes_tree *)); +for_each_string_list (load_one_display_note_ref, + &display_notes_refs, &cb_counter); + display_notes_trees[cb_counter] =NULL ; +} +void add_note (struct notes_tree *t,const unsigned char *object_sha1,const unsigned char *note_sha1,combine_notes_fn combine_notes) {
@@ -1016,7 +1070,12 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,if (msglen && msg[msglen -1 ] =='\n' ) msglen--; -if (flags &NOTES_SHOW_HEADER ) +if (flags &NOTES_SHOW_HEADER_WITH_REF && t->ref) { +const char *ref = t->ref; +if (!prefixcmp (ref,"refs/" )) + ref +=5 ; +strbuf_addf (sb,"\nNotes from %s:\n" , ref); + }else if (flags & (NOTES_SHOW_HEADER |NOTES_SHOW_HEADER_WITH_REF ))strbuf_addstr (sb,"\nNotes:\n" );for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen +1 ) {
@@ -1031,6 +1090,17 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,free (msg); } +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags) +{ +int i; +if (!display_notes_trees) +init_display_notes (); +for (i =0 ; display_notes_trees[i]; i++) +format_note (display_notes_trees[i], object_sha1, sb, + output_encoding, flags); +} +int copy_note (struct notes_tree *t,const unsigned char *from_obj,const unsigned char *to_obj,int force,combine_notes_fn combine_fn)
notes.h +1 -0
@@ -193,6 +193,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,/* Flags controlling how notes are formatted */ #define NOTES_SHOW_HEADER 1#define NOTES_INDENT 2 +#define NOTES_SHOW_HEADER_WITH_REF 4/* * Fill the given strbuf with the notes associated with the given object.
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER_WITH_REF |NOTES_INDENT );free (reencoded); }
Signature · 1 line
1.7.0.143.gbf2a7.dirty
Re: [WIP/RFC PATCH] Support showing notes from more than one notes tree
Quoted 5 lines · On Saturday 20 February 2010 15:58:47 Thomas Rast wrote:
My actual intent was to allow more than one notes.displayref config setting, and loading all of them. But this doesn't seem to work; a debugging print confirms that
notes_display_configsees the entry, but another debugging print shows that it only ever loads one of them. What am I doing wrong?
Ah, figured that out myself: for_each_glob_ref has the logic of --glob to attach /* if there are no globbing characters. So I'll add some code to skip for_each_ref and enter it in the list directly if there is nothing to glob.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chv3 cover several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 1 line
I'm running out of git time today
I should repeat that incantation more often, it mysteriously freed up more time.
Brief overview of changes since v2, with some inline questions about things that need to be settled:
* new [1/12] "Support showing notes from more than one notes tree" that teaches a "notes.displayRef" option which can glob for notes that should be shown, and can be specified more than once.
- maybe we should default this to "refs/notes/*"?
- currently git-notes and the configs don't agree on what is a valid notes ref. git-notes refuses even *showing* outside of refs/notes/. I tend towards changing git-notes at least as far as reading notes is concerned (show/list), so that remote notes work.
* dropped [5/11] "notes: clean up t3301" as per Junio's comments
* changed [7/12] "notes: implement helpers needed for note copying during rewrite" to support "notes.rewriteRef" as announced earlier. "notes.rewrite.<cmd>" now default to true, so that you only need to enable one, namely set notes.rewriteRef = refs/notes/*.
- do we want a default?
- do we want the rewriteRefs to also implicitly be displayRefs?
- the "notes.rewriteMode = overwrite for notes/volatile/*" hinted at earlier is missing. Does anyone need that?
* new [12/12] "notes: add shorthand --ref to override GIT_NOTES_REF"
I haven't changed [10/12] & [11/12] "filter-branch..." yet, as I'm not really sure what the best format of such a filter would be.
The existing code is probably a neat way of editing the notes, but it creates a new commit to the notes ref for every rewritten commit. If I change the default --notes-filter to cope with multi-rewriting, this means a new notes commit per rewritten commit. Seems rather wasteful just to salvage your notes across an otherwise unrelated filter-branch.
So the obvious fix would seem to be a --post-rewrite addition that just pipes through 'git notes copy --for-rewrite=filter-branch', but that's again not very customizable short of reinventing the whole thing. Any ideas?
Thomas Rast (12):
Support showing notes from more than one notes tree
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
filter-branch: invoke post-rewrite hook
filter-branch: learn how to filter notes
notes: add shorthand --ref to override GIT_NOTES_REF
Documentation/config.txt | 40 +++++++- Documentation/git-filter-branch.txt | 20 +++- Documentation/git-notes.txt | 20 +++- Documentation/githooks.txt | 40 +++++++ builtin-commit.c | 49 ++++++++ builtin-notes.c | 168 +++++++++++++++++++++++++++- builtin.h | 16 +++ git-am.sh | 13 ++ git-filter-branch.sh | 37 ++++++ git-rebase--interactive.sh | 45 +++++++- git-rebase.sh | 6 + notes.c | 125 +++++++++++++++++++- notes.h | 16 +++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + t/t3301-notes.sh | 213 ++++++++++++++++++++++++++++++++-- t/t3306-notes-prune.sh | 6 +- t/t3400-rebase.sh | 17 +++ t/t3404-rebase-interactive.sh | 11 ++ t/t5407-post-rewrite-hook.sh | 188 ++++++++++++++++++++++++++++++ t/t7003-filter-branch.sh | 22 ++++ t/t7501-commit.sh | 12 ++ 23 files changed, 1046 insertions(+), 33 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
RFC PATCH v3 1/12 Support showing notes from more than one notes tree
With this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
--- Documentation/config.txt | 13 +++++- notes.c | 104 +++++++++++++++++++++++++++++++++++++++++++--- notes.h | 7 +++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 ++ t/t3301-notes.sh | 65 +++++++++++++++++++++++------ t/t3306-notes-prune.sh | 6 +- 8 files changed, 181 insertions(+), 29 deletions(-)
Documentation/config.txt +12 -1
@@ -517,7 +517,7 @@ core.notesRef:: after the full SHA-1 of the commit they annotate. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes from <refname>:" line. If the given ref itself does not exist, it is not an error, but means that no notes should be printed. +
@@ -1300,6 +1300,17 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + When showing commit messages, also show notes which are stored + in the given ref. The ref may also be a glob, in which case + notes from all matching refs will be shown. You may also + specify this configuration variable several times. If a ref + does not exist, it will be skipped silently. ++ +The effective value of "core.notesRef" (possibly overridden by +GIT_NOTES_REF) is also implicitly added to the list of refs to be +displayed. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
notes.c +98 -6
143 lines not on this page · raw message
notes.h +7 -0
@@ -184,6 +184,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,/* Flags controlling how notes are formatted */ #define NOTES_SHOW_HEADER 1#define NOTES_INDENT 2 +#define NOTES_SHOW_HEADER_WITH_REF 4/* * Fill the given strbuf with the notes associated with the given object.
@@ -198,4 +199,10 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,void format_note (struct notes_tree *t,const unsigned char *object_sha1,struct strbuf *sb,const char *output_encoding,int flags); +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags); + +struct notes_tree **load_notes_trees (struct string_list *refs); +void string_list_add_refs_by_glob (struct string_list *list,const char *glob); +#endif
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER_WITH_REF |NOTES_INDENT );free (reencoded); }
refs.c +1 -3
@@ -695,7 +695,6 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, {struct strbuf real_pattern =STRBUF_INIT ;struct ref_filter filter; -const char *has_glob_specials;int ret;if (!prefix &&prefixcmp (pattern,"refs/" ))
@@ -704,8 +703,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,strbuf_addstr (&real_pattern, prefix);strbuf_addstr (&real_pattern, pattern); - has_glob_specials =strpbrk (pattern,"?*[" ); -if (!has_glob_specials) { +if (!has_glob_specials (pattern)) {/* Append impiled '/' '*' if not present. */ if (real_pattern.buf[real_pattern.len -1 ] !='/' )strbuf_addch (&real_pattern,'/' );
refs.h +5 -0
@@ -28,6 +28,11 @@ struct ref_lock {extern int for_each_glob_ref (each_ref_fn ,const char *pattern,void *);extern int for_each_glob_ref_in (each_ref_fn ,const char *pattern,const char * prefix,void *); +static inline const char *has_glob_specials (const char *pattern) +{ +return strpbrk (pattern,"?*[" ); +} +/* can be used to learn about broken ref and symref */ extern int for_each_rawref (each_ref_fn ,void *);
t/t3301-notes.sh +52 -13
150 lines not on this page · raw message
t/t3306-notes-prune.sh +3 -3
@@ -30,7 +30,7 @@ Date: Thu Apr 7 15:15:13 2005 -0700 3rd -Notes: +Notes from notes/commits: Note #3 commit 08341ad9e94faa089d60fd3f523affb25c6da189
@@ -39,7 +39,7 @@ Date: Thu Apr 7 15:14:13 2005 -0700 2nd -Notes: +Notes from notes/commits: Note #2 commit ab5f302035f2e7aaf04265f08b42034c23256e1f
@@ -48,7 +48,7 @@ Date: Thu Apr 7 15:13:13 2005 -0700 1st -Notes: +Notes from notes/commits: Note #1 END_OF_LOG
Signature · 1 line
1.7.0.59.g783f8
Re: [RFC PATCH v3 01/12] Support showing notes from more than one notes tree
Documentation/config.txt core.notesRef:: · line 520
Quoted 10 lines · Thomas Rast
Documentation/config.txt +1
-1@@ -517,7 +517,7 @@ core.notesRef:: after the full SHA-1 of the commit they annotate. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes from <refname>:" line. If the
I haven't looked at your code, but I think the output should be kept the same when <refname> is "refs/notes/commits", and it probably is a good idea to omit "refs/notes/" part. E.g. "Notes (amlog):" for notes stored in the refs/notes/amlog hierarchy.
Documentation/config.txt mergetool.keepTemporaries:: · line 1305
Quoted 7 lines
Documentation/config.txt +3
-0@@ -1300,6 +1300,17 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + When showing commit messages, also show notes which are stored + in the given ref. The ref may also be a glob, in which case
If this were a description that follows an example
[notes] displayRef = <ref>
then the above sentences make sense, but otherwise "in the given ref" does not make much sense. "The ref may also be a glob" is a lot worse. A "ref" is never be a glob. You can specify what refs to display by setting the _value_ of this variable to a glob.
notes.displayRef::
The refname in the notes namespace from which to show notes when showing commit messages. The value of this variable can be set to a glob, in whch case ...
Documentation/config.txt mergetool.keepTemporaries:: · line 1307
Quoted 2 lines
Documentation/config.txt +2
-0+ ... If a ref + does not exist, it will be skipped silently.
Hmph... Even when it is not a globbing specification? If I said
[notes] displayRef = refs/notes/tr/*
and there is no notes in the tr/ hierarchy yet, I would appreciate if the code doesn't complain, but if I said a more concrete
[notes] displayRef = refs/notes/anlog
and there is no "anlog", because I meant "amlog" and the above was a typo, I would appreciate if the code somehow lets me know about it.
Documentation/config.txt mergetool.keepTemporaries:: · line 1311
Quoted 4 lines
Documentation/config.txt +4
-0+static int notes_display_config(const char *k, const char *v, void *cb) +{ + if (!strcmp(k, "notes.displayref")) { + string_list_add_refs_by_glob(&display_notes_refs, v);
Somebody in the callchain should say
if (!v)
config_error_nonbool(k)before you use v here.
I don't think string_list_insert() has a desirable property for this. If I wrote
[notes]
displayRef = refs/notes/commit
displayRef = refs/notes/amlog
I would expect that the normal notes come first and then notes from the amlog tree, not in the alphabetical "amlog happens to sort before commit" order. If I used a glob, e.g. "refs/notes/tr/*", I am saying "all notes in the tr/ namespace, I do not care about the particular order among them. Just use something sensible", and it would make sense to use some stable ordering, e.g. the order for_each_glob_ref() calls you back, but receiving the data and calling string_list_insert() will destroy the order the user gave you the configuration, no?
t/t3301-notes.sh Date: Thu Apr 7 15:14:13 2005 -0700 · line 101
Quoted 10 lines
t/t3301-notes.sh +1
-1@@ -98,7 +98,7 @@ Date: Thu Apr 7 15:14:13 2005 -0700 2nd -Notes: +Notes from notes/commits:
Please don't.
RFC PATCH v3 2/12 Documentation: document post-rewrite hook
In reply to Thomas RastThis defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
--- Documentation/githooks.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
Documentation/githooks.txt +36 -0
@@ -317,6 +317,42 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase', 'git-filter-branch'). Its first argument +denotes the command it was invoked by: currently one of `amend`, +`rebase`, or `filter-branch`. Further command-dependent arguments may +be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. + +filter-branch:: + Commits that were processed by 'git-filter-branch', but not + changed, are not included in the list. If the list is empty + after this filtering, the hook is not invoked at all. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 3/12 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
--- builtin-commit.c | 43 ++++++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin-commit.c +43 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +struct commit *commit; + commit =lookup_commit (head_sha1); +if (!commit ||parse_commit (commit)) +die ("HEAD commit disappeared right under my eyes?" ); +run_rewrite_hook (commit->object.sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -445,7 +445,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.59.g783f8
Re: [RFC PATCH v3 03/12] commit --amend: invoke post-rewrite hook
Quoted 12 lines · Thomas Rast
builtin-commit.c +8
-0+static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +... +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
builtin-commit.c int cmd_commit(int argc, const char **argv, const char *prefix) · line 1347
Quoted 9 lines
builtin-commit.c +6
-0@@ -1303,6 +1339,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +struct commit *commit; + commit =lookup_commit (head_sha1); +if (!commit ||parse_commit (commit)) +die ("HEAD commit disappeared right under my eyes?" ); +run_rewrite_hook (commit->object.sha1, commit_sha1);
Why aren't you passing head_sha1 to run_rewrite_hook() in the first place, and instead run lookup_commit() only to get its object.sha1?
This is merely a "post" hook, so failure to run it should not cause the main program to fail. By not looking it up you do not even have to check and call die(). Let the dying be done in the hook instead ;-).
Re: [RFC PATCH v3 00/12] several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 8 lines · Thomas Rast
Brief overview of changes since v2, with some inline questions about things that need to be settled:
* new [1/12] "Support showing notes from more than one notes tree" that teaches a "notes.displayRef" option which can glob for notes that should be shown, and can be specified more than once.
- maybe we should default this to "refs/notes/*"?
Probably not.
I like the general direction in which this series is going, but a config that does not have any command line counterpart is a design mistake.
When adding a feature, always start from the command line option, and then add configuration mechanism purely as a convenience (so that users do not have to give the same option every time they run the command). By forcing yourself to stick to that design pattern, it is easier to ensure that any new feature can be disabled by people who do not want it from the command line.
Quoted 1 line
* new [12/12] "notes: add shorthand --ref to override
GIT_NOTES_REF"
Hmm; if this will _always_ be limited to "git notes" command and no other commands will _ever_ learn a command line option to override what notes namespace to use in the future, then "--ref" is perfectly a good name. But otherwise, "git log --ref=notes/amlog" would look _very wrong_, and would end up being called "git log --notes-ref=notes/amlog" instead. When that happens, "git notes --ref=notes/amlog" would look inconsistent and people will complain, no?
Re: [RFC PATCH v3 00/12] several notes refs, post-rewrite, notes rewriting
Quoted 3 lines · On Sunday 21 February 2010 04:47:37 Junio C Hamano wrote:
I like the general direction in which this series is going, but a config that does not have any command line counterpart is a design mistake.
I hate[1] to point out that according to the same criterion, the *current* notes are a design mistake. Unless you count GIT_NOTES_REF, in which case in my opinion...
Quoted 7 lines
Hmm; if this will _always_ be limited to "git notes" command and no other commands will _ever_ learn a command line option to override what notes namespace to use in the future, then "--ref" is perfectly a good name. But otherwise, "git log --ref=notes/amlog" would look
_verywrong_, and would end up being called "git log --notes-ref=notes/amlog" instead. When that happens, "git notes --ref=notes/amlog" would look inconsistent and people will complain, no?
... the obvious extension of the same would be GIT_NOTES_DISPLAY_REF (colon separated list of globs), GIT_NOTES_REWRITE_REF, GIT_NOTES_REWRITE_MODE, and whatnot.
Which could still be made into a "global" option along the same lines as GIT_WORK_TREE.
I don't really want to go the other way and patch every command that could conceivably have notes in its output.
[1] No I don't, that just sounded nice.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [RFC PATCH v3 00/12] several notes refs, post-rewrite, notes rewriting
Quoted 8 lines · Thomas Rast
Quoted 3 lines · On Sunday 21 February 2010 04:47:37 Junio C Hamano wrote:
I like the general direction in which this series is going, but a config that does not have any command line counterpart is a design mistake.
I hate[1] to point out that according to the same criterion, the *current* notes are a design mistake. Unless you count
GIT_NOTES_REF, in which case in my opinion...
With "--no-notes" the caller can explicitly say "please do not show any notes at all" to the log family. "git notes" command itself is about manipluating the notes, and at least with GIT_NOTES_REF the caller can explicitly say what notes tree to work with even when configured value is not appropriate. I also thought there was a work in progress to allow overriding GIT_NOTES_REF from the command line?
Having _only_ configuration option is practically no better than having only hardcoded defaults with _no_ way to override it per invocation. What if a user wants to usually see notes from set A (hence it is configured as the value to display-notes-ref configuration) but wants to see notes from a different (maybe overlapping, maybe not) set B during another task? As far as I can see, the _only_ way the current round of RFC lets me do this is by resetting the configuration in the repository.
It is not a contrived example. I've been adding the info about the original mailing list message with a patch to commits made with "am" in notes/amlog, and would want to keep test result summary in notes/test. I'd want to see the test notes just before merging topics to integration branches as a final safety check but not all the time. I'd want to see amlog notes when bisect points at a commit in not so near future to be able to dig up the archive with, but not all the time. There needs a per-invocation way to specify which sets of notes to show, and a command line option is the usual way for commands to allow users to do so [*1*].
Quoted 2 lines
I don't really want to go the other way and patch every command that could conceivably have notes in its output.
It is Ok that the series may not be perfect during the RFC period (which the patches were clearly marked as), but I've already said "I like the general direction", wanted to see this series advance from RFC to 'next' material sooner rather than later, and was pointing out what needs to happen for that.
[Footnote]
*1* We could also use an environment variable, but that is an inferiour alternative to options and configuration variables from the point of view of UI design. Users can export GIT_AUTHOR_NAME, which can serve as an alternative to user.name. This can be overridden per-invocation by "GIT_AUTHOR_NAME=myothername git commit", which can serve as an alternative to --author option.
RFC PATCH v3 4/12 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
--- git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -575,6 +575,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -582,6 +583,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -768,6 +770,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -776,6 +782,10 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + git gc --auto rm -fr "$dotest"
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 5/12 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
--- git-rebase--interactive.sh | 39 +++++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 0 deletions(-)
git-rebase--interactive.sh +39 -0
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/conflicted-sha make_patch "$1" git rerere die "$2"
@@ -348,6 +356,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -425,6 +434,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -438,6 +467,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -446,6 +476,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -454,6 +485,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" make_patch $sha1 + record_in_rewritten "$sha1" git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest" warn "You can amend the commit now, with"
@@ -509,6 +541,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -537,6 +570,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -685,6 +723,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/conflicted-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +78 -0
82 lines not on this page · raw message
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 6/12 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
--- Documentation/git-notes.txt | 12 ++++++++- builtin-notes.c | 57 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 21 ++++++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 32 ++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -55,6 +55,16 @@ copy:: objects has none. (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin-notes.c +56 -1
83 lines not on this page · raw message
notes.c +21 -0
@@ -1122,3 +1122,24 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note; + + note =get_note (t, from_obj); +if (!force) { +const unsigned char *existing_note =get_note (t, to_obj); +if (existing_note) +return 1 ; + } + +if (note) +add_note (t, to_obj, note, combine_fn); +else +remove_note (t, to_obj); + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +32 -0
@@ -683,4 +683,36 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes from notes/other: + yet another note +$whitespace + yet another note + +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes from notes/other: + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + strip_then_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.59.g783f8
Re: [RFC PATCH v3 06/12] notes: implement 'git notes copy --stdin'
t/t3301-notes.sh test_expect_success 'cannot copy note from object without notes' ' · line 713
Quoted 12 lines · Thomas Rast
t/t3301-notes.sh +6
-0@@ -683,4 +683,36 @@ test_expect_success 'cannot copy note from object without notes' ' +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + strip_then_cmp expect output &&
Huh?
RFC PATCH v3 7/12 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
--- Documentation/config.txt | 23 ++++++++ Documentation/git-notes.txt | 4 ++ Documentation/githooks.txt | 4 ++ builtin-notes.c | 121 ++++++++++++++++++++++++++++++++++++++++--- builtin.h | 16 ++++++ t/t3301-notes.sh | 118 +++++++++++++++++++++++++++++++++++++++++- 6 files changed, 277 insertions(+), 9 deletions(-)
Documentation/config.txt +23 -0
@@ -1311,6 +1311,29 @@ The effective value of "core.notesRef" (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `true`, but see + "notes.rewriteRef" below. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. + +notes.rewriteRef:: + When copying notes during a rewrite, specifies the ref whose + notes should be copied. The ref may be a glob, in which case + notes in all matching refs will be copied. You may also + specify this configuration several times. ++ +Does not have a default value; you must configure this variable to +enable note rewriting. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -34,6 +34,10 @@ the empty string. Alternatively, you can set it to a different ref, something like "refs/notes/bugzilla". This setting can be overridden by the environment variable "GIT_NOTES_REF". +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin-notes.c +113 -8
179 lines not on this page · raw message
builtin.h +16 -0
@@ -20,6 +20,22 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree **trees; +const char *cmd; +int enabled; +combine_notes_fn *combine; +struct string_list *refs; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
t/t3301-notes.sh +117 -1
138 lines not on this page · raw message
Signature · 1 line
1.7.0.59.g783f8
Re: [RFC PATCH v3 07/12] notes: implement helpers needed for note copying during rewrite
builtin-notes.c int commit_notes(struct notes_tree *t, const char *msg) · line 293
Quoted 11 lines · Thomas Rast
builtin-notes.c +11
-0+combine_notes_fn *parse_combine_notes_fn (const char *v) +{ +if (!strcasecmp (v,"overwrite" )) +return combine_notes_overwrite; +else if (!strcasecmp (v,"ignore" )) +return combine_notes_ignore; +else if (!strcasecmp (v,"concatenate" )) +return combine_notes_concatenate; +else +return NULL ; +}
Somebody in the call chain should have made sure v != NULL and called config_error_nonbool() if v is NULL.
Quoted 21 lines
t/t3301-notes.sh +2
-0@@ -684,6 +684,7 @@ test_expect_success 'cannot copy note from object without notes' ' ' cat > expect << EOF +commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:25:13 2005 -0700@@ -694,6 +695,7 @@ Notes from notes/other: $whitespace yet another note +commit 7038787dfe22a14c3867ce816dbba39845359719 Author: A U Thor <[email protected]> Date: Thu Apr 7 15:24:13 2005 -0700
t/t3301-notes.sh test_expect_success 'git notes copy --stdin' ' · line 718
Quoted 8 lines
t/t3301-notes.sh +1
-1@@ -710,9 +712,123 @@ test_expect_success 'git notes copy --stdin' ' echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | git notes copy --stdin && git log -2 > output && - strip_then_cmp expect output && + test_cmp expect output && test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" '
I think the above piece should have been squashed to the previous patch.
v4 cover several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastThanks Junio for your big batch of feedback. Yet another round...
Since this topic already has three different goals, I decided to try and get it in at least 'pu' shapes to have an agreed-upon basis for what's next. To that end, I ejected the filter-branch commits for now, and hopefully addressed all comments on the existing patches. I still need to make up my mind (and would still appreciate input) on the filter-branch part, but if I'm not mistaken the rest of the series has been on Junio's wishlist. I also already have a patch to make format-patch fill the comment region from a notes ref that has textual dependencies on this, which IIRC has also been mentioned as a wishlist item once or twice.
I used the entire series plus the format-patch feature mentioned above fairly heavily during its own development, which unearthed a few more bugs. If there is a comment after the --- line in every patch, it worked ;-)
Quoted 9 lines · On Sunday 21 February 2010 04:06:52 Junio C Hamano wrote:
If I wrote
[notes]
displayRef = refs/notes/commit
displayRef = refs/notes/amlogI would expect that the normal notes come first and then notes from the amlog tree, not in the alphabetical "amlog happens to sort before commit" order. [v3 always sorted the displayRef entries for display]
I considered this a feature, but changed it anyway since I don't care much. My original rationale was: core.notesRef should be in that list implicitly, and I think the natural position if it is unsorted would
be: first. However, that means that changing core.notesRef or GIT_NOTES_REF can shuffle around your notes, which I thought would be confusing.
Thomas Rast (11):
test-lib: unset GIT_NOTES_REF to stop it from influencing tests Support showing notes from more than one notes tree
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
notes: add shorthand --ref to override GIT_NOTES_REF
Documentation/config.txt | 49 ++++++- Documentation/git-notes.txt | 20 +++- Documentation/githooks.txt | 40 +++++ builtin-commit.c | 45 ++++++ builtin-notes.c | 195 +++++++++++++++++++++++- builtin.h | 18 ++ cache.h | 3 + git-am.sh | 13 ++ git-rebase--interactive.sh | 52 ++++++- git-rebase.sh | 6 + notes.c | 173 ++++++++++++++++++++- notes.h | 17 ++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + t/t3301-notes.sh | 344 ++++++++++++++++++++++++++++++++++++++++- t/t3400-rebase.sh | 17 ++ t/t3404-rebase-interactive.sh | 24 +++ t/t5407-post-rewrite-hook.sh | 172 ++++++++++++++++++++ t/t7501-commit.sh | 12 ++ t/test-lib.sh | 4 + 21 files changed, 1194 insertions(+), 25 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
PATCH v4 1/11 test-lib: unset GIT_NOTES_REF to stop it from influencing tests
---
New in this round.
t/test-lib.sh | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
t/test-lib.sh +1 -0
@@ -54,6 +54,7 @@ unset GIT_OBJECT_DIRECTORY unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY +unset GIT_NOTES_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 2/11 Support showing notes from more than one notes tree
In reply to Thomas RastWith this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular.
---
Changes since v3:
* introduce GIT_NOTES_DISPLAY_REF
* the notes refs are kept in the order the user provided them
* the header is now 'Notes (refname):' or 'Notes:' in the case of refs/notes/commits
* fixes as per Junio's comments
Documentation/config.txt | 19 ++++++- cache.h | 1 + notes.c | 153 ++++++++++++++++++++++++++++++++++++++++++++-- notes.h | 7 ++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 ++ t/t3301-notes.sh | 115 ++++++++++++++++++++++++++++++++--- t/test-lib.sh | 1 + 9 files changed, 290 insertions(+), 21 deletions(-)
Documentation/config.txt +18 -1
@@ -517,7 +517,7 @@ core.notesRef:: after the full SHA-1 of the commit they annotate. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes from <refname>:" line. If the given ref itself does not exist, it is not an error, but means that no notes should be printed. +
@@ -1300,6 +1300,23 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + The refname in the notes namespace from which to show notes + when showing commit messages. The value of this variable can + be set to a glob, in which case notes from all matching refs + will be shown. You may also specify this configuration + variable several times. A warning will be issued for refs + that do not exist, but a glob that does not match any refs is + silently ignored. ++ +This setting can be overridden with the `GIT_NOTES_DISPLAY_REF` +environment variable, which must be a colon (or semicolon) separated +list of refs or globs. ++ +The effective value of "core.notesRef" (possibly overridden by +GIT_NOTES_REF) is also implicitly added to the list of refs to be +displayed. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
cache.h +1 -0
@@ -387,6 +387,7 @@ static inline enum object_type object_type(unsigned int mode)#define ATTRIBUTE_MACRO_PREFIX "[attr]"#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"extern int is_bare_repository_cfg;extern int is_bare_repository (void );
notes.c +147 -6
192 lines not on this page · raw message
notes.h +7 -0
@@ -184,6 +184,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,/* Flags controlling how notes are formatted */ #define NOTES_SHOW_HEADER 1#define NOTES_INDENT 2 +#define NOTES_SHOW_HEADER_WITH_REF 4/* * Fill the given strbuf with the notes associated with the given object.
@@ -198,4 +199,10 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,void format_note (struct notes_tree *t,const unsigned char *object_sha1,struct strbuf *sb,const char *output_encoding,int flags); +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags); + +struct notes_tree **load_notes_trees (struct string_list *refs); +void string_list_add_refs_by_glob (struct string_list *list,const char *glob); +#endif
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER_WITH_REF |NOTES_INDENT );free (reencoded); }
refs.c +1 -3
@@ -695,7 +695,6 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, {struct strbuf real_pattern =STRBUF_INIT ;struct ref_filter filter; -const char *has_glob_specials;int ret;if (!prefix &&prefixcmp (pattern,"refs/" ))
@@ -704,8 +703,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,strbuf_addstr (&real_pattern, prefix);strbuf_addstr (&real_pattern, pattern); - has_glob_specials =strpbrk (pattern,"?*[" ); -if (!has_glob_specials) { +if (!has_glob_specials (pattern)) {/* Append impiled '/' '*' if not present. */ if (real_pattern.buf[real_pattern.len -1 ] !='/' )strbuf_addch (&real_pattern,'/' );
refs.h +5 -0
@@ -28,6 +28,11 @@ struct ref_lock {extern int for_each_glob_ref (each_ref_fn ,const char *pattern,void *);extern int for_each_glob_ref_in (each_ref_fn ,const char *pattern,const char * prefix,void *); +static inline const char *has_glob_specials (const char *pattern) +{ +return strpbrk (pattern,"?*[" ); +} +/* can be used to learn about broken ref and symref */ extern int for_each_rawref (each_ref_fn ,void *);
t/t3301-notes.sh +107 -8
170 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -55,6 +55,7 @@ unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF +unset GIT_NOTES_DISPLAY_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 3/11 Documentation: document post-rewrite hook
In reply to Thomas RastThis defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
---
Unchanged from v3
Documentation/githooks.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
Documentation/githooks.txt +36 -0
@@ -317,6 +317,42 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase', 'git-filter-branch'). Its first argument +denotes the command it was invoked by: currently one of `amend`, +`rebase`, or `filter-branch`. Further command-dependent arguments may +be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. + +filter-branch:: + Commits that were processed by 'git-filter-branch', but not + changed, are not included in the list. If the list is empty + after this filtering, the hook is not invoked at all. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 4/11 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
---
Changed since v3: Use head_sha1 without resolving it again to find the same sha1. I must have been drunk when writing that detour.
builtin-commit.c | 39 +++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin-commit.c +39 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +run_rewrite_hook (head_sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -445,7 +445,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 5/11 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
---
Unchanged from v3
git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -575,6 +575,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -582,6 +583,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -768,6 +770,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -776,6 +782,10 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + git gc --auto rm -fr "$dotest"
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 6/11 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
---
Changes since v3: Fixed a bug with the handling of 'edit' that recorded the wrong commit.
* also handle the work done by skip_unneccessary_picks; not doing so meant that in a simple 'pick;squash' rebase, the 'pick' was not shown as rewritten to the squashed commit
git-rebase--interactive.sh | 46 +++++++++++++++++++++- t/t5407-post-rewrite-hook.sh | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +45 -1
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/stopped-sha make_patch "$1" git rerere die "$2"
@@ -348,6 +356,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -425,6 +434,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -438,6 +467,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -446,6 +476,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -453,6 +484,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + echo "$1" > "$DOTEST"/stopped-sha make_patch $sha1 git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest"
@@ -509,6 +541,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -537,6 +570,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -571,7 +609,12 @@ skip_unnecessary_picks () { esac echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd done <"$TODO" >"$TODO.new" 3>>"$DONE" && - mv -f "$TODO".new "$TODO" || + mv -f "$TODO".new "$TODO" && + case "$(peek_next_command)" in + squash|s|fixup|f) + record_in_rewritten "$ONTO" + ;; + esac || die "Could not skip unnecessary pick commands" }
@@ -685,6 +728,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +90 -0
94 lines not on this page · raw message
Signature · 1 line
1.7.0.147.g5aeb9
Re: [PATCH v4 00/11] several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 3 lines · Thomas Rast
core.notesRef should be in that list
implicitly, and I think the natural position if it is unsorted would
be: first.
I think that is a sane thing to do, and then any additional ones can come after that first one, in the order specified by displayRef. Isn't that what you are doing, no?
Re: [PATCH v4 00/11] several notes refs, post-rewrite, notes rewriting
Quoted 9 lines · On Monday 22 February 2010 01:25:02 Junio C Hamano wrote:
Quoted 3 lines · Thomas Rast
core.notesRef should be in that list
implicitly, and I think the natural position if it is unsorted would
be: first.I think that is a sane thing to do, and then any additional ones can come after that first one, in the order specified by displayRef. Isn't that what you are doing, no?
Yes, I just wanted to spell out why I originally decided for the sorted instead of user-ordered way:
Quoted 2 lines
Quoted 2 lines
However, that means that changing core.notesRef or
GIT_NOTES_REFcan shuffle around your notes, which I thought would be confusing.
But that wasn't a strong preference at all, so doing it like you suggested (and like the code is in v4) is fine by me.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH v4 7/11 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
---
Changed since v3: fixed the strip_then_cmp that I removed in the wrong commit when going from v2 to v3.
* Fix bug in copy_note() that always removed the note when the source was empty, even for combine=concatenate or such. A test for this is in the next commit, as with this one we always use combine=overwrite.
Documentation/git-notes.txt | 12 ++++++++- builtin-notes.c | 56 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 20 +++++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 34 ++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -55,6 +55,16 @@ copy:: objects has none. (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin-notes.c +55 -1
82 lines not on this page · raw message
notes.c +20 -0
@@ -1171,3 +1171,23 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note =get_note (t, from_obj); +const unsigned char *existing_note =get_note (t, to_obj); + +if (!force && existing_note) +return 1 ; + +if (note) +add_note (t, to_obj, note, combine_fn); +else if (existing_note) { +add_note (t, to_obj, null_sha1, combine_fn); + }else +remove_note (t, to_obj); + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +34 -0
@@ -743,4 +743,38 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes (other): + yet another note +$whitespace + yet another note + +commit 7038787dfe22a14c3867ce816dbba39845359719 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes (other): + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + test_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 8/11 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
---
Changes since v3: introduced GIT_NOTES_REWRITE_REF and _MODE.
* more tests
Documentation/config.txt | 30 +++++++ Documentation/git-notes.txt | 4 + Documentation/githooks.txt | 4 + builtin-notes.c | 139 +++++++++++++++++++++++++++++-- builtin.h | 18 ++++ cache.h | 2 + notes.h | 1 + t/t3301-notes.sh | 195 +++++++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + 9 files changed, 387 insertions(+), 8 deletions(-)
Documentation/config.txt +30 -0
@@ -1317,6 +1317,36 @@ The effective value of "core.notesRef" (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `true`, but see + "notes.rewriteRef" below. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_REF` +environment variable, which must be a colon (or semicolon) separated +list of refs or globs. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_MODE` +environment variable. + +notes.rewriteRef:: + When copying notes during a rewrite, specifies the ref whose + notes should be copied. The ref may be a glob, in which case + notes in all matching refs will be copied. You may also + specify this configuration several times. ++ +Does not have a default value; you must configure this variable to +enable note rewriting. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -34,6 +34,10 @@ the empty string. Alternatively, you can set it to a different ref, something like "refs/notes/bugzilla". This setting can be overridden by the environment variable "GIT_NOTES_REF". +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin-notes.c +131 -8
196 lines not on this page · raw message
builtin.h +18 -0
@@ -20,6 +20,24 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree **trees; +const char *cmd; +int enabled; +combine_notes_fn *combine; +struct string_list *refs; +int refs_from_env; +int mode_from_env; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
cache.h +2 -0
@@ -388,6 +388,8 @@ static inline enum object_type object_type(unsigned int mode)#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"extern int is_bare_repository_cfg;extern int is_bare_repository (void );
notes.h +1 -0
@@ -213,5 +213,6 @@ void format_display_notes(const unsigned char *object_sha1,struct notes_tree **load_notes_trees (struct string_list *refs);void string_list_add_refs_by_glob (struct string_list *list,const char *glob); +void string_list_add_refs_from_glob_list (struct string_list *list,const char *globs);#endif
t/t3301-notes.sh +195 -0
199 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -56,6 +56,8 @@ unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF unset GIT_NOTES_DISPLAY_REF +unset GIT_NOTES_REWRITE_REF +unset GIT_NOTES_REWRITE_MODE GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 9/11 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
---
Changed from v3: more tests
git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 17 +++++++++++++++++ t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -782,8 +782,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi git gc --auto
git-rebase--interactive.sh +4 -0
@@ -570,6 +570,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +17 -0
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +24 -0
@@ -553,4 +553,28 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +cat >expect <<EOF +an earlier note +a note +EOF + +test_expect_success 'rebase -i can copy notes over a fixup' ' + git reset --hard n3 && + git notes add -m"an earlier note" n2 && + GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && + git notes show > output && + test_cmp expect output +' + test_done
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 10/11 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
---
Unchanged from v3
builtin-commit.c | 6 ++++++ t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
builtin-commit.c +6 -0
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) { +struct notes_rewrite_cfg *cfg; + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, head_sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (head_sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +12 -0
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + git config notes.rewriteRef "refs/notes/*" && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.147.g5aeb9
PATCH v4 11/11 notes: add shorthand --ref to override GIT_NOTES_REF
In reply to Thomas RastAdds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix.
---
Changed since v3: refs/notes/ is now implied, instead of erroring out if it is not there.
Documentation/git-notes.txt | 4 ++++ builtin-notes.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +4 -0
@@ -115,6 +115,10 @@ OPTIONS Like '-C', but with '-c' the editor is invoked, so that the user can further edit the note message. +--ref <ref>:: + Manipulate the notes tree in <ref>. This overrides both + GIT_NOTES_REF and the "core.notesRef" configuration. + Author ------ Written by Johannes Schindelin <[email protected]> and
builtin-notes.c +16 -0
@@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)int given_object =0 , i =1 , retval =0 ;struct msg_arg msg = {0 ,0 ,STRBUF_INIT };const char *rewrite_cmd =NULL ; +const char *override_notes_ref =NULL ;struct option options[] = {OPT_GROUP ("Notes options" ), OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix) "reuse specified note object", parse_reuse_arg),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ),OPT_BOOLEAN (0 ,"stdin" , &from_stdin,"read objects from stdin" ), +OPT_STRING (0 ,"ref" , &override_notes_ref,"notes_ref" , +"use notes from <notes_ref>" ),OPT_STRING (0 ,"for-rewrite" , &rewrite_cmd,"command" ,"load rewriting config for <command> (implies --stdin)" ),OPT_END ()
@@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, git_notes_usage,0 ); +if (override_notes_ref) { +struct strbuf sb =STRBUF_INIT ; +if (!prefixcmp (override_notes_ref,"refs/notes/" )) +/* we're happy */ ; +else if (!prefixcmp (override_notes_ref,"notes/" )) +strbuf_addstr (&sb,"refs/" ); +else +strbuf_addstr (&sb,"refs/notes/" ); +strbuf_addstr (&sb, override_notes_ref); +setenv ("GIT_NOTES_REF" , sb.buf,1 ); +strbuf_release (&sb); + } +if (argc && !strcmp (argv[0 ],"list" )) list =1 ;else if (argc && !strcmp (argv[0 ],"add" ))
Signature · 1 line
1.7.0.147.g5aeb9
RFC PATCH v3 8/12 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
--- git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 17 +++++++++++++++++ t/t3404-rebase-interactive.sh | 11 +++++++++++ 5 files changed, 37 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -782,8 +782,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi git gc --auto
git-rebase--interactive.sh +4 -0
@@ -570,6 +570,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +17 -0
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +11 -0
@@ -553,4 +553,15 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 9/12 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
--- builtin-commit.c | 6 ++++++ t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
builtin-commit.c +6 -0
@@ -1341,9 +1341,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) {struct commit *commit; +struct notes_rewrite_cfg *cfg; commit =lookup_commit (head_sha1);if (!commit ||parse_commit (commit))die ("HEAD commit disappeared right under my eyes?" ); + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, commit->object.sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (commit->object.sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +12 -0
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + git config notes.rewriteRef "refs/notes/*" && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 10/12 filter-branch: invoke post-rewrite hook
In reply to Thomas RastWith a twist: since this is supposed to be the be-all end-all of rewriting, we give the user the chance to override the hook.
--- Documentation/git-filter-branch.txt | 7 ++++++- git-filter-branch.sh | 21 +++++++++++++++++++++ t/t5407-post-rewrite-hook.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletions(-)
Documentation/git-filter-branch.txt +6 -1
@@ -12,7 +12,7 @@ SYNOPSIS [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] - [--prune-empty] + [--prune-empty] [--post-rewrite <command>] [--original <namespace>] [-d <directory>] [-f | --force] [--] [<rev-list options>...]
@@ -182,6 +182,11 @@ the nearest ancestor that was not excluded. of the `git commit-tree "$@"` idiom in your commit filter to make that happen. +--post-rewrite <command>:: + Overrides the post-rewrite hook (if you have one). To bypass + the hook for this invocation, pass `:`. See + linkgit:githooks[1]. + --original <namespace>:: Use this option to set the namespace where the original commits will be stored. The default value is 'refs/original'.
git-filter-branch.sh +21 -0
@@ -101,6 +101,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] + [--post-rewrite <command>] [--original <namespace>] [-d <directory>] [-f | --force] [<rev-list options>...]"
@@ -126,6 +127,13 @@ orig_namespace=refs/original/ force= prune_empty= remap_to_ancestor= + +if test -x "$GIT_DIR"/hooks/post-rewrite; then + post_rewrite=$(git rev-parse --sq-quote "$GIT_DIR"/hooks/post-rewrite) +else + post_rewrite=: +fi + while : do case "$1" in
@@ -190,6 +198,10 @@ do filter_subdir="$OPTARG" remap_to_ancestor=t ;; + --post-rewrite) + post_rewrite="$OPTARG" + post_rewrite_given=t + ;; --original) orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/ ;;
@@ -358,6 +370,10 @@ while read commit parents; do @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \ $(git write-tree) $parentstr < ../message > ../map/$commit || die "could not write rewritten commit" + new_commit=$(map $commit) + if test $commit != $new_commit; then + echo $commit $new_commit >> "$workdir"/../rewritten + fi done <../revs # If we are filtering for paths, as in the case of a subdirectory
@@ -484,6 +500,11 @@ if [ "$filter_tag_name" ]; then fi cd ../.. + +if test -s "$workdir"/../rewritten; then + eval "$post_rewrite" 'filter-branch < "$workdir"/../rewritten' +fi + rm -rf "$tempdir" trap - 0
t/t5407-post-rewrite-hook.sh +28 -0
@@ -157,4 +157,32 @@ EOF verify_hook_input ' +test_expect_success 'git filter-branch' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f --tree-filter "touch newfile" B..HEAD && + echo filter-branch >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git filter-branch (no-op)' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f B..HEAD && + test ! -f post-rewrite.args && + test ! -f post-rewrite.data +' + +test_expect_success 'git filter-branch --post-rewrite :' ' + git reset --hard D && + clear_hook_input && + git filter-branch -f --post-rewrite : --tree-filter "touch newfile" B..HEAD && + test ! -f post-rewrite.args && + test ! -f post-rewrite.data +' + test_done
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 11/12 filter-branch: learn how to filter notes
In reply to Thomas RastTeach filter-branch a new option --notes-filter that acts as a pipe filter (much like --msg-filter) for the commit notes. For consistency with the note copying support in amend/rebase, it defaults to 'cat' if notes.rewrite.filter-branch is set.
--- Documentation/config.txt | 8 ++++++-- Documentation/git-filter-branch.txt | 13 +++++++++++++ Documentation/githooks.txt | 8 ++++---- git-filter-branch.sh | 18 +++++++++++++++++- t/t7003-filter-branch.sh | 22 ++++++++++++++++++++++ 5 files changed, 62 insertions(+), 7 deletions(-)
Documentation/config.txt +6 -2
@@ -1312,8 +1312,8 @@ GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. notes.rewrite.<command>:: - When rewriting commits with <command> (currently `amend` or - `rebase`) and this variable is set to `true`, git + When rewriting commits with <command> (currently `amend`, + `rebase` or `filter-branch`) and this variable is set to `true`, git automatically copies your notes from the original to the rewritten commit. Defaults to `true`, but see "notes.rewriteRef" below.
@@ -1324,6 +1324,10 @@ notes.rewriteMode:: the target commit already has a note. Must be one of `overwrite`, `concatenate`, or `ignore`. Defaults to `concatenate`. ++ +Note that 'git-filter-branch' ignores this setting and always +overwrites; see the description of `--notes-filter` in +linkgit:git-filter-branch[1]. notes.rewriteRef:: When copying notes during a rewrite, specifies the ref whose
Documentation/git-filter-branch.txt +13 -0
@@ -161,6 +161,19 @@ to other tags will be rewritten to point to the underlying commit. The result will contain that directory (and only that) as its project root. Implies --remap-to-ancestor. +--notes-filter <command>:: + This filter rewrites the notes (see linkgit:git-notes[1]). It + gets the old notes on standard input, and its standard output + is written as the new note (overwriting any existing notes). ++ +Defaults to doing nothing, unless the `notes.rewrite.filter-branch` +option is set, in which case it copies the notes (i.e., defaults to +`cat`). ++ +In addition to the usual variables, GIT_NEW_COMMIT is set to the +result of the rewriting so that the filter can get at the existing +notes, if any. + --remap-to-ancestor:: Rewrite refs to the nearest rewritten ancestor instead of ignoring them.
Documentation/githooks.txt +4 -4
@@ -350,11 +350,11 @@ rebase:: filter-branch:: Commits that were processed by 'git-filter-branch', but not changed, are not included in the list. If the list is empty - after this filtering, the hook is not invoked at all. + after this filtering, the hook is not invoked at all. Also + see the `--post-rewrite` option in + linkgit:git-filter-branch[1]. -There is no default 'post-rewrite' hook, but see the -`post-receive-copy-notes` script in `contrib/hooks` for an example -that copies your git-notes to the rewritten commits. +There is no default 'post-rewrite' hook. GIT
git-filter-branch.sh +17 -1
@@ -101,7 +101,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] [--index-filter <command>] [--parent-filter <command>] [--msg-filter <command>] [--commit-filter <command>] [--tag-name-filter <command>] [--subdirectory-filter <directory>] - [--post-rewrite <command>] + [--post-rewrite <command>] [--notes-filter <command>] [--original <namespace>] [-d <directory>] [-f | --force] [<rev-list options>...]"
@@ -134,6 +134,12 @@ else post_rewrite=: fi +if test "$(git config --bool notes.rewrite.filter-branch)"; then + filter_notes=cat +else + filter_notes= +fi + while : do case "$1" in
@@ -198,6 +204,9 @@ do filter_subdir="$OPTARG" remap_to_ancestor=t ;; + --notes-filter) + filter_notes="$OPTARG" + ;; --post-rewrite) post_rewrite="$OPTARG" post_rewrite_given=t
@@ -374,6 +383,13 @@ while read commit parents; do if test $commit != $new_commit; then echo $commit $new_commit >> "$workdir"/../rewritten fi + if test -n "$filter_notes"; then + if git notes show $commit >../note 2>/dev/null; then + export GIT_NEW_COMMIT="$new_commit" + eval "$filter_notes" <../note | + git notes add -F- -f $new_commit + fi + fi done <../revs # If we are filtering for paths, as in the case of a subdirectory
t/t7003-filter-branch.sh +22 -0
@@ -306,6 +306,28 @@ test_expect_success '--remap-to-ancestor with filename filters' ' test $orig_invariant = $(git rev-parse invariant) ' +test_expect_success '--notes-filter off' ' + git checkout master && + test_commit notes-foo && + git notes add -mtestnote && + git filter-branch -f --tree-filter "touch notes-1" HEAD^.. && + test_must_fail git notes show +' + +test_expect_success '--notes-filter manually' ' + git reset --hard notes-foo && + git filter-branch -f --notes-filter "sed s/test/foo/" \ + --tree-filter "touch notes-2" HEAD^.. && + test foonote = "$(git notes show)" +' + +test_expect_success '--notes-filter implicit' ' + git reset --hard notes-foo && + git config notes.rewrite.filter-branch true && + git filter-branch -f --tree-filter "touch notes-3" HEAD^.. && + test testnote = "$(git notes show)" +' + test_expect_success 'setup submodule' ' rm -fr ?* .git && git init &&
Signature · 1 line
1.7.0.59.g783f8
RFC PATCH v3 12/12 notes: add shorthand --ref to override GIT_NOTES_REF
In reply to Thomas RastAdds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated.
--- Documentation/git-notes.txt | 4 ++++ builtin-notes.c | 6 ++++++ 2 files changed, 10 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +4 -0
@@ -115,6 +115,10 @@ OPTIONS Like '-C', but with '-c' the editor is invoked, so that the user can further edit the note message. +--ref <ref>:: + Manipulate the notes tree in <ref>. This overrides both + GIT_NOTES_REF and the "core.notesRef" configuration. + Author ------ Written by Johannes Schindelin <[email protected]> and
builtin-notes.c +6 -0
@@ -430,6 +430,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)int given_object =0 , i =1 , retval =0 ;struct msg_arg msg = {0 ,0 ,STRBUF_INIT };const char *rewrite_cmd =NULL ; +const char *override_notes_ref =NULL ;struct option options[] = {OPT_GROUP ("Notes options" ), OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -442,6 +443,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix) "reuse specified note object", parse_reuse_arg),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ),OPT_BOOLEAN (0 ,"stdin" , &from_stdin,"read objects from stdin" ), +OPT_STRING (0 ,"ref" , &override_notes_ref,"notes_ref" , +"use notes from <notes_ref>" ),OPT_STRING (0 ,"for-rewrite" , &rewrite_cmd,"command" ,"load rewriting config for <command> (implies --stdin)" ),OPT_END ()
@@ -451,6 +454,9 @@ int cmd_notes(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, git_notes_usage,0 ); +if (override_notes_ref) +setenv ("GIT_NOTES_REF" , override_notes_ref,1 ); +if (argc && !strcmp (argv[0 ],"list" )) list =1 ;else if (argc && !strcmp (argv[0 ],"add" ))
Signature · 1 line
1.7.0.59.g783f8
Re: [PATCH v4 02/11] Support showing notes from more than one notes tree
In reply to Thomas RastDocumentation/config.txt core.notesRef:: · line 520
Quoted 10 lines · Thomas Rast
Documentation/config.txt +1
-1@@ -517,7 +517,7 @@ core.notesRef:: after the full SHA-1 of the commit they annotate. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes from <refname>:" line. If the
Hmm...
notes.c struct non_note { · line 74
Quoted 10 lines
notes.c +2
-0@@ -68,6 +70,9 @@ struct non_note {struct notes_tree default_notes_tree; +struct string_list display_notes_refs; +struct notes_tree **display_notes_trees;
Do these need to be extern?
Quoted 7 lines
notes.c +7
-0+void string_list_add_refs_from_glob_list (struct string_list *list, +const char *globs) +{ +struct strbuf globbuf =STRBUF_INIT ; +struct strbuf **split; +int i; +
notes.c int combine_notes_ignore(unsigned char *cur_sha1, · line 874
Quoted 10 lines
notes.c +10
-0+strbuf_addstr (&globbuf, globs); + split =strbuf_split (&globbuf,':' ); + +for (i =0 ; split[i]; i++) { +if (!split[i]->len) +continue ; +if (split[i]->buf[split[i]->len-1 ] ==':' ) +strbuf_setlen (split[i], split[i]->len-1 ); +string_list_add_refs_by_glob (list, split[i]->buf); + }
Nice use of strbuf_split(). I wonder if we should automatically add "refs/" and/or "refs/notes/" when the input is missing the prefix. I don't have strong preference myself but the users might make noises.
Either way it needs to be documented in the final version before the series goes to 'master'.
notes.c int combine_notes_ignore(unsigned char *cur_sha1, · line 884
Quoted 5 lines
notes.c +5
-0+static int notes_display_config (const char *k,const char *v,void *cb) +{ +/* Warning! This is currently not executed if +* GIT_NOTES_DISPLAY_REF is set. Move the git_config() call +* outside the test if you add more options. */
Yuck. If you know what needs to be done, do that before other poeple add more options, please.
Quoted 8 lines
notes.c +3
-1@@ -1016,7 +1135,18 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,if (msglen && msg[msglen -1 ] =='\n' ) msglen--; -if (flags &NOTES_SHOW_HEADER ) +if (flags &NOTES_SHOW_HEADER_WITH_REF && t->ref) { +const char *ref = t->ref; +if (!strcmp (ref,GIT_NOTES_DEFAULT_REF )) {
notes.c void format_note(struct notes_tree *t, const unsigned char *object_sha1, · line 1150
Quoted 10 lines
notes.c +9
-0+strbuf_addstr (sb,"\nNotes:\n" ); + }else { +if (!prefixcmp (ref,"refs/" )) + ref +=5 ; +if (!prefixcmp (ref,"notes/" )) + ref +=6 ; +strbuf_addf (sb,"\nNotes (%s):\n" , ref); + } + }else if (flags & (NOTES_SHOW_HEADER |NOTES_SHOW_HEADER_WITH_REF ))strbuf_addstr (sb,"\nNotes:\n" );
It is not clear what the distinction between NOTES_SHOW_HEADER and NOTES_SHOW_HEADER_WITH_REF. Does anybody still call this function with NOTES_SHOW_HEADER alone without NOTES_SHOW_HEADER_WITH_REF?
I expected to see "Notes:\n" regardless of the mode if the notes is coming from the default refs/notes/commits tree, but it probably is better to say "Notes (commits):\n" like your patch does.
Re: [PATCH v4 02/11] Support showing notes from more than one notes tree
Umm, since I'm currently working on another reroll that has pretty args to add notes refs for display...
Quoted 10 lines · On Tuesday 23 February 2010 00:20:06 Junio C Hamano wrote:
Quoted 9 lines · Thomas Rast
notes.c +9
-0+if (flags &NOTES_SHOW_HEADER_WITH_REF && t->ref) { +const char *ref = t->ref; +if (!strcmp (ref,GIT_NOTES_DEFAULT_REF )) { +strbuf_addstr (sb,"\nNotes:\n" ); + }else { +if (!prefixcmp (ref,"refs/" )) + ref +=5 ; +if (!prefixcmp (ref,"notes/" )) + ref +=6 ;
Quoted 8 lines
notes.c void format_note(struct notes_tree *t, const unsigned char *object_sha1, · line 1150
Quoted 4 lines
notes.c +3
-0+strbuf_addf (sb,"\nNotes (%s):\n" , ref); + } + }else if (flags & (NOTES_SHOW_HEADER |NOTES_SHOW_HEADER_WITH_REF ))strbuf_addstr (sb,"\nNotes:\n" );It is not clear what the distinction between
NOTES_SHOW_HEADERandNOTES_SHOW_HEADER_WITH_REF. Does anybody still call this function withNOTES_SHOW_HEADERalone withoutNOTES_SHOW_HEADER_WITH_REF?
No.
Quoted 3 lines
I expected to see "Notes:\n" regardless of the mode if the notes is coming from the default refs/notes/commits tree, but it probably is better to say "Notes (commits):\n" like your patch does.
I special-cased GIT_NOTES_DEFAULT_REF (which is "refs/notes/commits") above *at your request* to not change the output in the default case. So which way do you want it?
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH v4 02/11] Support showing notes from more than one notes tree
Quoted 23 lines · Thomas Rast
Umm, since I'm currently working on another reroll that has pretty args to add notes refs for display...
Quoted 10 lines · On Tuesday 23 February 2010 00:20:06 Junio C Hamano wrote:
Quoted 9 lines · Thomas Rast
notes.c +9
-0+if (flags &NOTES_SHOW_HEADER_WITH_REF && t->ref) { +const char *ref = t->ref; +if (!strcmp (ref,GIT_NOTES_DEFAULT_REF )) { +strbuf_addstr (sb,"\nNotes:\n" ); + }else { +if (!prefixcmp (ref,"refs/" )) + ref +=5 ; +if (!prefixcmp (ref,"notes/" )) + ref +=6 ;Quoted 8 lines
notes.c void format_note(struct notes_tree *t, const unsigned char *object_sha1, · line 1150
Quoted 4 lines
notes.c +3
-0+strbuf_addf (sb,"\nNotes (%s):\n" , ref); + } + }else if (flags & (NOTES_SHOW_HEADER |NOTES_SHOW_HEADER_WITH_REF ))strbuf_addstr (sb,"\nNotes:\n" );It is not clear what the distinction between
NOTES_SHOW_HEADERandNOTES_SHOW_HEADER_WITH_REF. Does anybody still call this function withNOTES_SHOW_HEADERalone withoutNOTES_SHOW_HEADER_WITH_REF?
Quoted 1 line
No.
Meaning nobody will go through the latter "Notes:\n" codepath? Then what is that else clause for?
Perhaps I am not reading your code right in which case this part needs a bit more commenting?
Quoted 8 lines
Quoted 3 lines
I expected to see "Notes:\n" regardless of the mode if the notes is coming from the default refs/notes/commits tree, but it probably is better to say "Notes (commits):\n" like your patch does.
I special-cased
GIT_NOTES_DEFAULT_REF(which is "refs/notes/commits") above *at your request* to not change the output in the default case.So which way do you want it?
I don't have strong preference anymore with the above code.
If some caller called the latter "always show Notes:" codepath, i.e. SHOW_HEADER is given but without HEADER_WITH_REF, then my preference would have been more clear. A caller that gives HEADER_WITH_REF clearly wants to show more than one notes (perhaps the user used displayref mechanism) and it would be better to always say which one in order to disambiguate, and the special case would not be a good idea. A caller would not give HEADER_WITH_REF when the user has refs/notes/commits hierarchy and nothing else, and the user didn't ask for multiple notes trees shown; in such a case we should show the good-old "Notes:".
But if everybody calls with HEADER_WITH_REF, no matter what the end user preference is, then it becomes unclear what the right answer would be.
v5 cover several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 2 lines · On Tuesday 23 February 2010 00:20:06 Junio C Hamano wrote:
Quoted 1 line · Thomas Rast
notes.c +0
-0
[...]
Quoted 4 lines
notes.c
Quoted 2 lines
notes.c +2
-0+struct string_list display_notes_refs; +struct notes_tree **display_notes_trees;Do these need to be extern?
Don't think so? After all it's in the .c and just another static variable.
Quoted 6 lines
Nice use of
strbuf_split(). I wonder if we should automatically add "refs/" and/or "refs/notes/" when the input is missing the prefix. I don't have strong preference myself but the users might make noises.Either way it needs to be documented in the final version before the series goes to 'master'.
I decided to do such dwimmery only on the command line, but not for the config. This is consistent with what's currently happening for core.notesRef. I also documented this.
Quoted 8 lines
notes.c
Quoted 5 lines
notes.c +5
-0+static int notes_display_config (const char *k,const char *v,void *cb) +{ +/* Warning! This is currently not executed if +* GIT_NOTES_DISPLAY_REF is set. Move the git_config() call +* outside the test if you add more options. */ Yuck. If you know what needs to be done, do that before other poeple add more options, please.
*shrug*
I was trying to be smart and save a call to git_config() when we know we don't care about the config anyway. After all it does read a bunch of files.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +1
-0+ if (flags & NOTES_SHOW_HEADER_WITH_REF && t->ref) {
[...]
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ } else if (flags & (NOTES_SHOW_HEADER|NOTES_SHOW_HEADER_WITH_REF)) strbuf_addstr(sb, "\nNotes:\n");Meaning nobody will go through the latter "Notes:\n" codepath? Then what is that else clause for?
Perhaps I am not reading your code right in which case this part needs a bit more commenting?
The catch is in the '&& t->ref'. Again I'm just trying to be a bit defensive. Anyway, I ripped out the old formatting and put the NULL test first this time.
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
I expected to see "Notes:\n" regardless of the mode if the notes is coming from the default refs/notes/commits tree, but it probably is better to say "Notes (commits):\n" like your patch does.
I special-cased
GIT_NOTES_DEFAULT_REF(which is "refs/notes/commits") above *at your request* to not change the output in the default case.So which way do you want it?
I don't have strong preference anymore with the above code.
[...]
Quoted 2 lines
But if everybody calls with
HEADER_WITH_REF, no matter what the end user preference is, then it becomes unclear what the right answer would be.
Well, I think we're into bikeshedding territory now, so I just left it as it was.
The rest of the changes are listed in each email.
Thomas Rast (11):
test-lib: unset GIT_NOTES_REF to stop it from influencing tests Support showing notes from more than one notes tree
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
notes: add shorthand --ref to override GIT_NOTES_REF
Documentation/config.txt | 53 +++++- Documentation/git-notes.txt | 21 ++- Documentation/githooks.txt | 38 ++++ Documentation/pretty-options.txt | 11 +- builtin-commit.c | 45 +++++ builtin-log.c | 2 + builtin-notes.c | 195 +++++++++++++++++++- builtin.h | 18 ++ cache.h | 3 + git-am.sh | 13 ++ git-rebase--interactive.sh | 52 +++++- git-rebase.sh | 6 + notes.c | 191 +++++++++++++++++++- notes.h | 27 +++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 ++ revision.h | 5 + t/t3301-notes.sh | 377 +++++++++++++++++++++++++++++++++++++- t/t3400-rebase.sh | 17 ++ t/t3404-rebase-interactive.sh | 24 +++ t/t5407-post-rewrite-hook.sh | 172 +++++++++++++++++ t/t7501-commit.sh | 12 ++ t/test-lib.sh | 4 + 25 files changed, 1294 insertions(+), 28 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
Re: [PATCH v5 00/11] several notes refs, post-rewrite, notes rewriting
Please ignore until I post a replacement for 2/11. I managed to mis-edit *and* forget to test during the last round of fixups, and now it doesn't even compile. I'll just go to bed and try again tomorrow.
Sorry.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH v5 1/11 test-lib: unset GIT_NOTES_REF to stop it from influencing tests
In reply to Thomas Rast---
t/test-lib.sh | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
t/test-lib.sh +1 -0
@@ -54,6 +54,7 @@ unset GIT_OBJECT_DIRECTORY unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY +unset GIT_NOTES_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 2/11 Support showing notes from more than one notes tree
In reply to Thomas RastWith this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular.
---
Changes since v4:
* introduce --show-notes=<ref> and --[no-]standard-notes
* remove NOTES_SHOW_HEADER_WITH_REF distinction
* parse config even if we don't care about it
* fix misallocation in load_notes_trees()
* doc tweaks
Documentation/config.txt | 23 +++++- Documentation/pretty-options.txt | 11 ++- builtin-log.c | 2 + cache.h | 1 + notes.c | 171 ++++++++++++++++++++++++++++++++++++-- notes.h | 18 ++++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 +++++ revision.h | 5 + t/t3301-notes.sh | 148 +++++++++++++++++++++++++++++++-- t/test-lib.sh | 1 + 13 files changed, 392 insertions(+), 24 deletions(-)
Documentation/config.txt +21 -2
@@ -519,10 +519,12 @@ check that makes sure that existing object files will not get overwritten. core.notesRef:: When showing commit messages, also show notes which are stored in the given ref. This ref is expected to contain files named - after the full SHA-1 of the commit they annotate. + after the full SHA-1 of the commit they annotate. The ref + must be fully qualified. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes (<refname>):" +line (shortened to "Notes:" in the case of "refs/notes/commits"). If the given ref itself does not exist, it is not an error, but means that no notes should be printed. +
@@ -1305,6 +1307,23 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + The (fully qualified) refname from which to show notes when + showing commit messages. The value of this variable can be set + to a glob, in which case notes from all matching refs will be + shown. You may also specify this configuration variable + several times. A warning will be issued for refs that do not + exist, but a glob that does not match any refs is silently + ignored. ++ +This setting can be overridden with the `GIT_NOTES_DISPLAY_REF` +environment variable, which must be a colon separated list of refs or +globs. ++ +The effective value of "core.notesRef" (possibly overridden by +GIT_NOTES_REF) is also implicitly added to the list of refs to be +displayed. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/pretty-options.txt +10 -1
@@ -30,9 +30,18 @@ people using 80-column terminals. defaults to UTF-8. --no-notes:: ---show-notes:: +--show-notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. This is the default for `git log`, `git show` and `git whatchanged` commands when there is no `--pretty`, `--format` nor `--oneline` option is given on the command line. ++ +With an optional argument, add this ref to the list of notes. The ref +is taken to be in `refs/notes/` if it is not qualified. + +--[no-]standard-notes:: + Enable or disable populating the notes ref list from the + 'core.notesRef' and 'notes.displayRef' variables (or + corresponding environment overrides). See + linkgit:git-config[1].
builtin-log.c +2 -0
@@ -60,6 +60,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,if (!rev->show_notes_given && !rev->pretty_given) rev->show_notes =1 ; +if (rev->show_notes) +init_display_notes (&rev->notes_opt);if (rev->diffopt.pickaxe || rev->diffopt.filter) rev->always_show_header =0 ;
cache.h +1 -0
@@ -387,6 +387,7 @@ static inline enum object_type object_type(unsigned int mode)#define ATTRIBUTE_MACRO_PREFIX "[attr]"#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"extern int is_bare_repository_cfg;extern int is_bare_repository (void );
notes.c +164 -7
210 lines not on this page · raw message
notes.h +18 -0
@@ -198,4 +198,22 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,void format_note (struct notes_tree *t,const unsigned char *object_sha1,struct strbuf *sb,const char *output_encoding,int flags); + +struct string_list ; + +struct display_notes_opt +{ +int suppress_default_notes :1 ; +struct string_list *extra_notes_refs; +}; + +void init_display_notes (struct display_notes_opt *opt); +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags); + +struct notes_tree **load_notes_trees (struct string_list *refs); +void string_list_add_refs_by_glob (struct string_list *list,const char *glob); +void string_list_add_refs_from_colon_sep (struct string_list *list, +const char *globs); +#endif
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER_WITH_REF |NOTES_INDENT );free (reencoded); }
refs.c +1 -3
@@ -695,7 +695,6 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, {struct strbuf real_pattern =STRBUF_INIT ;struct ref_filter filter; -const char *has_glob_specials;int ret;if (!prefix &&prefixcmp (pattern,"refs/" ))
@@ -704,8 +703,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,strbuf_addstr (&real_pattern, prefix);strbuf_addstr (&real_pattern, pattern); - has_glob_specials =strpbrk (pattern,"?*[" ); -if (!has_glob_specials) { +if (!has_glob_specials (pattern)) {/* Append implied '/' '*' if not present. */ if (real_pattern.buf[real_pattern.len -1 ] !='/' )strbuf_addch (&real_pattern,'/' );
refs.h +5 -0
@@ -28,6 +28,11 @@ struct ref_lock {extern int for_each_glob_ref (each_ref_fn ,const char *pattern,void *);extern int for_each_glob_ref_in (each_ref_fn ,const char *pattern,const char * prefix,void *); +static inline const char *has_glob_specials (const char *pattern) +{ +return strpbrk (pattern,"?*[" ); +} +/* can be used to learn about broken ref and symref */ extern int for_each_rawref (each_ref_fn ,void *);
revision.c +21 -0
@@ -12,6 +12,7 @@#include "patch-ids.h" #include "decorate.h" #include "log-tree.h" +#include "string-list.h" volatile show_early_output_fn_t show_early_output;
@@ -1191,9 +1192,29 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg }else if (!strcmp (arg,"--show-notes" )) { revs->show_notes =1 ; revs->show_notes_given =1 ; + }else if (!prefixcmp (arg,"--show-notes=" )) { +struct strbuf buf =STRBUF_INIT ; + revs->show_notes =1 ; + revs->show_notes_given =1 ; +if (!revs->notes_opt.extra_notes_refs) + revs->notes_opt.extra_notes_refs =xcalloc (1 ,sizeof (struct string_list )); +if (!prefixcmp (arg+13 ,"refs/" )) +/* happy */ ; +else if (!prefixcmp (arg+13 ,"notes/" )) +strbuf_addstr (&buf,"refs/" ); +else +strbuf_addstr (&buf,"refs/notes/" ); +strbuf_addstr (&buf, arg+13 ); +string_list_append (strbuf_detach (&buf,NULL ), + revs->notes_opt.extra_notes_refs); }else if (!strcmp (arg,"--no-notes" )) { revs->show_notes =0 ; revs->show_notes_given =1 ; + }else if (!strcmp (arg,"--standard-notes" )) { + revs->show_notes_given =1 ; + revs->notes_opt.suppress_default_notes =0 ; + }else if (!strcmp (arg,"--no-standard-notes" )) { + revs->notes_opt.suppress_default_notes =1 ; }else if (!strcmp (arg,"--oneline" )) { revs->verbose_header =1 ;get_commit_format ("oneline" , revs);
revision.h +5 -0
@@ -3,6 +3,7 @@#include "parse-options.h" #include "grep.h" +#include "notes.h" #define SEEN (1u<<0)#define UNINTERESTING (1u<<1)
@@ -20,6 +21,7 @@struct rev_info ;struct log_info ; +struct string_list ;struct rev_info {/* Starting list */
@@ -126,6 +128,9 @@ struct rev_info {struct reflog_walk_info *reflog_info;struct decoration children;struct decoration merge_simplification; + +/* notes-specific options: which refs to show */ +struct display_notes_opt notes_opt; };#define REV_TREE_SAME 0
t/t3301-notes.sh +140 -8
203 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -55,6 +55,7 @@ unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF +unset GIT_NOTES_DISPLAY_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH v5 02/11] Support showing notes from more than one notes tree
Quoted 2 lines · Thomas Rast
Changes since v4:
* introduce --show-notes=<ref> and --[no-]standard-notes
Nicer, much nicer.
Quoted 1 line
* remove
NOTES_SHOW_HEADER_WITH_REFdistinction
Note that there is a leftover caller that uses the symbol without noticing that it has been retired. I'll fix it up locally when I queue the series to 'pu'.
Quoted 1 line
* parse config even if we don't care about it
Parsing is good, and not reading trees is very good.
It is silly to put yourself down after doing both of these very well by saying "even if we don't care about it"---you obviously do care about making it earier for other people to build on top of your code. Otherwise you would have left the code unchanged from the previous round ;-).
Quoted 14 lines
notes.c +2
-0@@ -5,6 +5,8 @@#include "utf8.h" #include "strbuf.h" #include "tree-walk.h" +#include "string-list.h" +#include "refs.h" /* * Use a non-balancing simple 16-tree structure with struct int_node as
notes.c struct non_note { · line 74
Quoted 5 lines
notes.c +2
-0@@ -68,6 +70,9 @@ struct non_note {struct notes_tree default_notes_tree; +struct string_list display_notes_refs; +struct notes_tree **display_notes_trees;
Unlike default_notes_tree, the above two can become static, as you made the new logic better contained to this file and accessible only via accessor functions.
notes.c int combine_notes_ignore(unsigned char *cur_sha1, · line 894
Quoted 3 lines
notes.c +1
-0@@ -828,6 +833,76 @@ int combine_notes_ignore(unsigned char *cur_sha1, +static const char *default_notes_ref ()
I'll s/_ref()/_ref(void)/ here.
Quoted 11 lines
notes.h +3
-0@@ -198,4 +198,22 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,void format_note (struct notes_tree *t,const unsigned char *object_sha1,struct strbuf *sb,const char *output_encoding,int flags); + +struct string_list ; +
notes.h int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, · line 213
Quoted 10 lines
notes.h +10
-0+struct display_notes_opt +{ +int suppress_default_notes :1 ; +struct string_list *extra_notes_refs; +}; + +void init_display_notes (struct display_notes_opt *opt); +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags); +
As you are retiring format_note() as a public interface, and instead making format_display_notes() as the primary API for the callers, the former should be made static to notes.c along with the large comment describing how to call it. It may also be worth telling people how to call this new public interface with similar comment here.
notes.h void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, · line 1100
Quoted 8 lines
notes.h +2
-2@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER_WITH_REF |NOTES_INDENT );
I'll s/_WITH_REF// here.
Quoted 13 lines
revision.c +5
-0@@ -1191,9 +1192,29 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg }else if (!strcmp (arg,"--show-notes" )) { revs->show_notes =1 ; revs->show_notes_given =1 ; + }else if (!prefixcmp (arg,"--show-notes=" )) { +struct strbuf buf =STRBUF_INIT ; + revs->show_notes =1 ; + revs->show_notes_given =1 ; +if (!revs->notes_opt.extra_notes_refs)
revision.c static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg · line 1209
Quoted 10 lines
revision.c +10
-0+ revs->notes_opt.extra_notes_refs =xcalloc (1 ,sizeof (struct string_list )); +if (!prefixcmp (arg+13 ,"refs/" )) +/* happy */ ; +else if (!prefixcmp (arg+13 ,"notes/" )) +strbuf_addstr (&buf,"refs/" ); +else +strbuf_addstr (&buf,"refs/notes/" ); +strbuf_addstr (&buf, arg+13 ); +string_list_append (strbuf_detach (&buf,NULL ), + revs->notes_opt.extra_notes_refs);
Nice; multiple --show-notes=... will accumulate in the order given. I knew you won't be stupid to make this a colon separated string, but I had to double check ;-).
Re: [PATCH v5 02/11] Support showing notes from more than one notes tree
Quoted 6 lines · On Tuesday 23 February 2010 02:47:40 Junio C Hamano wrote:
Quoted 1 line · Thomas Rast
* remove
NOTES_SHOW_HEADER_WITH_REFdistinctionNote that there is a leftover caller that uses the symbol without noticing that it has been retired. I'll fix it up locally when I queue the series to 'pu'.
Thanks. That was the breakage I hinted at in the last mail last night; since it (hopefully) was the only problem with the series, I'll dispense with the replacement for now.
Quoted 10 lines
notes.c struct non_note { · line 74
Quoted 6 lines
notes.c +2
-0@@ -68,6 +70,9 @@ struct non_note {struct notes_tree default_notes_tree; +struct string_list display_notes_refs; +struct notes_tree **display_notes_trees;Unlike
default_notes_tree, the above two can become static, as you made the new logic better contained to this file and accessible only via accessor functions.
Oh, so that's what you hinted at with the 'extern' question...
Quoted 2 lines
As you are retiring
format_note()as a public interface, and instead makingformat_display_notes()as the primary API for the callers, the
I still need it for the "format-patch from notes" patch, to be posted soonish. So unless someone comes up with an alternative for that, it stays a public interface.
Quoted 3 lines
former should be made static to
notes.calong with the large comment describing how to call it. It may also be worth telling people how to call this new public interface with similar comment here.
You caught me on my comment laziness... I suspect even the ones I can add won't match Johan's excellent comments :-)
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH 1/1 format-patch: learn to fill comment section of email from notes
Teach git-format-patch a new option --comment-notes (with config format.commentNotes) which takes a notes ref argument. These notes are then added to the patch email between the --- separator and the diffstat/diff.
This is somewhat tricky because the pretty-printing code has no control whatsoever over the --- and the diffstat, and there be dragons in the newline-producing code inside show_log(). Try not to disturb them, and patch around only outside show_log().
To ensure correctness of the resulting email, extend the existing rule (separator if not 'oneline' format and --patch-with-stat) to also include a separator if there are notes and a patch will be included.
---
So here's the promised patch. This is sort-of-RFC; it's not part of the series because I don't want the latter to block on this one if anyone suggests changes.
I'll follow up with a broken version to prove the point about the dragons I made above, if anyone wants to try fixing it.
Documentation/config.txt | 6 ++ Documentation/git-format-patch.txt | 10 ++++ builtin-log.c | 12 +++++ log-tree.c | 14 +++++- pretty.c | 2 +- t/t4014-format-patch.sh | 91 ++++++++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 2 deletions(-)
Documentation/config.txt +6 -0
@@ -886,6 +886,12 @@ format.signoff:: the rights to submit this work under the same open source license. Please see the 'SubmittingPatches' document for further discussion. +format.commentNotes:: + The default notes reference that is used for the comment + section with --pretty=email and for 'git-format-patch'. (The + comment section is the area between the `\---` separator and + the patch, which also holds the diffstat.) + gc.aggressiveWindow:: The window size parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
Documentation/git-format-patch.txt +10 -0
@@ -198,6 +198,16 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. range are always formatted as creation patches, independently of this flag. +--comment-notes=<ref>:: + Use the notes from <ref> to fill the comment section of the + email, i.e., the part between the `\---` separator and the + patch. See linkgit:git-notes[1]. ++ +Warning: the code currently does not guard against a line in the notes +that starts with `diff`, which will be treated as the start of the +patch by 'git-am'. + + CONFIGURATION ------------- You can specify extra mail header lines to be added to each message,
builtin-log.c +12 -0
@@ -19,6 +19,7 @@#include "remote.h" #include "string-list.h" #include "parse-options.h" +#include "notes.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode =NULL ;
@@ -495,6 +496,7 @@ static void add_header(const char *value)#define THREAD_DEEP 2static int thread =0 ;static int do_signoff =0 ; +static const char *comment_notes =NULL ;static int git_format_config (const char *var,const char *value,void *cb) {
@@ -548,6 +550,9 @@ static int git_format_config(const char *var, const char *value, void *cb) do_signoff =git_config_bool (var, value);return 0 ; } +if (!strcmp (var,"format.commentnotes" )) { +return git_config_string (&comment_notes, var, value); + }return git_log_config (var, value, cb); }
@@ -955,6 +960,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) {OPTION_CALLBACK ,0 ,"thread" , &thread,"style" ,"enable message threading, styles: shallow, deep" , PARSE_OPT_OPTARG, thread_callback }, +OPT_STRING (0 ,"comment-notes" , &comment_notes, +"ref" ,"use notes from <ref> for comment section" ),OPT_END () };
@@ -1039,6 +1046,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)if (keep_subject && subject_prefix)die ("--subject-prefix and -k are mutually exclusive." ); +if (comment_notes) { +init_notes (NULL , comment_notes, combine_notes_ignore,0 ); + rev.show_notes =1 ; + } + argc =setup_revisions (argc, argv, &rev,"HEAD" );if (argc >1 )die ("unrecognized argument: %s" , argv[1 ]);
log-tree.c +13 -1
@@ -7,6 +7,7 @@#include "reflog-walk.h" #include "refs.h" #include "string-list.h" +#include "notes.h" struct decoration name_decoration = {"object names" };
@@ -457,6 +458,7 @@ int log_tree_diff_flush(struct rev_info *opt) }if (opt->loginfo && !opt->no_commit_id) { +const unsigned char *sha1 = opt->loginfo->commit->object.sha1;/* When showing a verbose header (i.e. log message), * and not in --pretty=oneline format, we would want * an extra newline between the end of log and the
@@ -467,10 +469,20 @@ int log_tree_diff_flush(struct rev_info *opt) opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) {int pch =DIFF_FORMAT_DIFFSTAT |DIFF_FORMAT_PATCH ; -if ((pch & opt->diffopt.output_format) == pch) +if ((pch & opt->diffopt.output_format) == pch + || (opt->commit_format ==CMIT_FMT_EMAIL + && opt->show_notes))printf ("---" );putchar ('\n' ); } +if (opt->commit_format ==CMIT_FMT_EMAIL && opt->show_notes) { +struct strbuf sb =STRBUF_INIT ; +putchar ('\n' ); +format_note (NULL , sha1, &sb,NULL ,0 ); +fwrite (sb.buf,1 , sb.len, stdout); +strbuf_release (&sb); +putchar ('\n' ); + } }diff_flush (&opt->diffopt);return 1 ;
pretty.c +1 -1
@@ -1095,7 +1095,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,if (fmt ==CMIT_FMT_EMAIL && sb->len <= beginning_of_body)strbuf_addch (sb,'\n' ); -if (context->show_notes) +if (context->show_notes && fmt !=CMIT_FMT_EMAIL )format_display_notes (commit->object.sha1, sb, encoding,NOTES_SHOW_HEADER |NOTES_INDENT );
t/t4014-format-patch.sh +91 -0
95 lines not on this page · raw message
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH] format-patch: learn to fill comment section of email from notes
Quoted 4 lines · Thomas Rast
Teach git-format-patch a new option --comment-notes (with config format.commentNotes) which takes a notes ref argument. These notes are then added to the patch email between the --- separator and the diffstat/diff.
Hmmm, why do I find this an ugly hack?
You already have a nice "format_display_notes()" infrastructure to allow users to get notes from arbitrary notes namespaces, yet this limits the user to a single notes namespace. What was the infrastructure built for if not used in places like this uniformly?
If the answer is "because notes.displayref is a configuration and it is cumbersome to change every time", then I don't have a sympathy ;-) as that is exactly why I said config without command line override is a bad thing.
Quoted 6 lines
Documentation/git-format-patch.txt +0
-0@@ -198,6 +198,16 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. range are always formatted as creation patches, independently
Documentation/git-format-patch.txt you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. · line 208
Quoted 10 lines
Documentation/git-format-patch.txt +8
-0of this flag. +--comment-notes=<ref>:: + Use the notes from <ref> to fill the comment section of the + email, i.e., the part between the `\---` separator and the + patch. See linkgit:git-notes[1]. ++ +Warning: the code currently does not guard against a line in the notes +that starts with `diff`, which will be treated as the start of the +patch by 'git-am'.
It is customary to indent the material after --- by one place (or more) so it probably is a good idea to do that for notes as well, if we are going to put it after the three dash lines. Notice that diffstat output is already indented that way ;-).
Quoted 9 lines
Documentation/git-format-patch.txt +1
-0@@ -457,6 +458,7 @@ int log_tree_diff_flush(struct rev_info *opt) } if (opt->loginfo && !opt->no_commit_id) { + const unsigned char *sha1 = opt->loginfo->commit->object.sha1; /* When showing a verbose header (i.e. log message), * and not in --pretty=oneline format, we would want * an extra newline between the end of log and the
Documentation/git-format-patch.txt int log_tree_diff_flush(struct rev_info *opt) · line 474
Quoted 7 lines
Documentation/git-format-patch.txt +3
-1@@ -467,10 +469,20 @@ int log_tree_diff_flush(struct rev_info *opt) opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) { int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; - if ((pch & opt->diffopt.output_format) == pch) + if ((pch & opt->diffopt.output_format) == pch + || (opt->commit_format == CMIT_FMT_EMAIL + && opt->show_notes))
This adds a lot of logic to a code that used to be simple "if we have more stuff to add after message, delimit with "---\n"". Perhaps the whole body of the "if" statement ll. 460- should be made into a static helper function with a single callsite that a clever compiler would inline.
Also I think you would emit "---" even if the commit in question does not happen to have note with this code.
I've attached a "how about doing it this way" weatherbaloon patch to be applied on top of this patch at the end---I didn't bother to indent the notes text nor change it to use format_display_notes(), but hopefully you will agree the code structure would be easier to follow this way.
pretty.c void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, · line 1100
Quoted 12 lines
pretty.c +1
-1@@ -1095,7 +1095,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,if (fmt ==CMIT_FMT_EMAIL && sb->len <= beginning_of_body)strbuf_addch (sb,'\n' ); -if (context->show_notes) +if (context->show_notes && fmt !=CMIT_FMT_EMAIL )format_display_notes (commit->object.sha1, sb, encoding,NOTES_SHOW_HEADER |NOTES_INDENT );
This is a good fix to prevent notes from getting injected above the separator line, regardless of your series, I think.
log-tree.c | 71 +++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 47 insertions(+), 24 deletions(-)
log-tree.c +47 -24
@@ -445,6 +445,52 @@ void show_log(struct rev_info *opt)strbuf_release (&msgbuf); } +static void log_tree_after_message (struct rev_info *opt) +{ +const int pch = (DIFF_FORMAT_DIFFSTAT |DIFF_FORMAT_PATCH ); +struct strbuf sb =STRBUF_INIT ; + +/* +* When showing a verbose header (i.e. log message), +* and not in --pretty=oneline format, we would want +* an extra newline between the end of log and the +* output for readability. +*/ +if (! ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT ) && + opt->verbose_header && + opt->commit_format !=CMIT_FMT_ONELINE ) ) +return ; + +/* +* Prepare notes if any... +*/ +if (opt->commit_format ==CMIT_FMT_EMAIL && opt->show_notes) +format_note (NULL , opt->loginfo->commit->object.sha1, + &sb,NULL ,0 ); + +/* +* Will we have something other than the message itself? If +* so we would need three-dashes. +*/ +if (((pch & opt->diffopt.output_format) == pch) || sb.len) +printf ("---" ); + +/* +* Then the promised newline... +*/ +putchar ('\n' ); + +/* +* And finally the notes... +*/ +if (sb.len) { +putchar ('\n' ); +fwrite (sb.buf,1 , sb.len, stdout); +strbuf_release (&sb); +putchar ('\n' ); + } +} +int log_tree_diff_flush (struct rev_info *opt) {diffcore_std (&opt->diffopt);
@@ -458,31 +504,8 @@ int log_tree_diff_flush(struct rev_info *opt) }if (opt->loginfo && !opt->no_commit_id) { -const unsigned char *sha1 = opt->loginfo->commit->object.sha1; -/* When showing a verbose header (i.e. log message), -* and not in --pretty=oneline format, we would want -* an extra newline between the end of log and the -* output for readability. -*/ show_log (opt); -if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT ) && - opt->verbose_header && - opt->commit_format !=CMIT_FMT_ONELINE ) { -int pch =DIFF_FORMAT_DIFFSTAT |DIFF_FORMAT_PATCH ; -if ((pch & opt->diffopt.output_format) == pch - || (opt->commit_format ==CMIT_FMT_EMAIL - && opt->show_notes)) -printf ("---" ); -putchar ('\n' ); - } -if (opt->commit_format ==CMIT_FMT_EMAIL && opt->show_notes) { -struct strbuf sb =STRBUF_INIT ; -putchar ('\n' ); -format_note (NULL , sha1, &sb,NULL ,0 ); -fwrite (sb.buf,1 , sb.len, stdout); -strbuf_release (&sb); -putchar ('\n' ); - } +log_tree_after_message (opt); }diff_flush (&opt->diffopt);return 1 ;
PATCH 1/1 BROKEN -- format-patch: learn to fill comment section of email from notes
In reply to Thomas RastTeach git-format-patch a new option --comment-notes (with config format.commentNotes) which takes a notes ref argument. These notes are then added to the patch email between the --- separator and the diffstat/diff.
This is somewhat tricky because the pretty-printing code has no control whatsoever over the --- and the diffstat. To fix that, move the associated code down into show_log(), which can set options in the pretty_print_context. Extend the latter with fields for an arbitrary string, to be inserted after commit message and after notes. Use those to place the --- appropriately.
To ensure correctness of the resulting email, extend the existing rule (separator if not 'oneline' format and --patch-with-stat) to also include a separator if there are notes and a patch will be included.
---
Documentation/config.txt | 6 ++ Documentation/git-format-patch.txt | 10 ++++ builtin-log.c | 12 +++++ commit.h | 2 + log-tree.c | 38 ++++++++++----- pretty.c | 19 ++++++- t/t4014-format-patch.sh | 91 ++++++++++++++++++++++++++++++++++++ 7 files changed, 162 insertions(+), 16 deletions(-)
Documentation/config.txt +6 -0
@@ -886,6 +886,12 @@ format.signoff:: the rights to submit this work under the same open source license. Please see the 'SubmittingPatches' document for further discussion. +format.commentNotes:: + The default notes reference that is used for the comment + section with --pretty=email and for 'git-format-patch'. (The + comment section is the area between the `\---` separator and + the patch, which also holds the diffstat.) + gc.aggressiveWindow:: The window size parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
Documentation/git-format-patch.txt +10 -0
@@ -198,6 +198,16 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. range are always formatted as creation patches, independently of this flag. +--comment-notes=<ref>:: + Use the notes from <ref> to fill the comment section of the + email, i.e., the part between the `\---` separator and the + patch. See linkgit:git-notes[1]. ++ +Warning: the code currently does not guard against a line in the notes +that starts with `diff`, which will be treated as the start of the +patch by 'git-am'. + + CONFIGURATION ------------- You can specify extra mail header lines to be added to each message,
builtin-log.c +12 -0
@@ -19,6 +19,7 @@#include "remote.h" #include "string-list.h" #include "parse-options.h" +#include "notes.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode =NULL ;
@@ -495,6 +496,7 @@ static void add_header(const char *value)#define THREAD_DEEP 2static int thread =0 ;static int do_signoff =0 ; +static const char *comment_notes =NULL ;static int git_format_config (const char *var,const char *value,void *cb) {
@@ -548,6 +550,9 @@ static int git_format_config(const char *var, const char *value, void *cb) do_signoff =git_config_bool (var, value);return 0 ; } +if (!strcmp (var,"format.commentnotes" )) { +return git_config_string (&comment_notes, var, value); + }return git_log_config (var, value, cb); }
@@ -955,6 +960,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) {OPTION_CALLBACK ,0 ,"thread" , &thread,"style" ,"enable message threading, styles: shallow, deep" , PARSE_OPT_OPTARG, thread_callback }, +OPT_STRING (0 ,"comment-notes" , &comment_notes, +"ref" ,"use notes from <ref> for comment section" ),OPT_END () };
@@ -1039,6 +1046,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)if (keep_subject && subject_prefix)die ("--subject-prefix and -k are mutually exclusive." ); +if (comment_notes) { +init_notes (NULL , comment_notes, combine_notes_ignore,0 ); + rev.show_notes =1 ; + } + argc =setup_revisions (argc, argv, &rev,"HEAD" );if (argc >1 )die ("unrecognized argument: %s" , argv[1 ]);
commit.h +2 -0
@@ -68,6 +68,8 @@ struct pretty_print_contextint abbrev;const char *subject;const char *after_subject; +const char *after_message; +const char *after_notes;enum date_mode date_mode;int need_8bit_cte;int show_notes;
log-tree.c +25 -13
@@ -7,6 +7,7 @@#include "reflog-walk.h" #include "refs.h" #include "string-list.h" +#include "notes.h" struct decoration name_decoration = {"object names" };
@@ -413,6 +414,30 @@ void show_log(struct rev_info *opt) ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; ctx.reflog_info = opt->reflog_info; + + ctx.after_message =NULL ; +/* +* In formats other than 'oneline', add an extra newline. In +* addition, add the triple-dash separator between message and +* diff if there is a diffstat coming or we are showing notes +* in 'email' format. Otherwise, 'git am' would include the +* diffstat or notes in the commit message when applying the +* commit. +*/ +if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT ) && + opt->verbose_header && + opt->commit_format !=CMIT_FMT_ONELINE ) { +int pch =DIFF_FORMAT_DIFFSTAT |DIFF_FORMAT_PATCH ; +int patch_with_stat = (pch & opt->diffopt.output_format) == pch; +if (opt->commit_format ==CMIT_FMT_EMAIL + && (opt->show_notes || patch_with_stat)) + ctx.after_message ="---\n" ; +else if (opt->commit_format !=CMIT_FMT_EMAIL && patch_with_stat) + ctx.after_notes ="---\n" ; +else + ctx.after_notes ="\n" ; + } +pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)
@@ -457,20 +482,7 @@ int log_tree_diff_flush(struct rev_info *opt) }if (opt->loginfo && !opt->no_commit_id) { -/* When showing a verbose header (i.e. log message), -* and not in --pretty=oneline format, we would want -* an extra newline between the end of log and the -* output for readability. -*/ show_log (opt); -if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT ) && - opt->verbose_header && - opt->commit_format !=CMIT_FMT_ONELINE ) { -int pch =DIFF_FORMAT_DIFFSTAT |DIFF_FORMAT_PATCH ; -if ((pch & opt->diffopt.output_format) == pch) -printf ("---" ); -putchar ('\n' ); - } }diff_flush (&opt->diffopt);return 1 ;
pretty.c +16 -3
@@ -1095,9 +1095,22 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,if (fmt ==CMIT_FMT_EMAIL && sb->len <= beginning_of_body)strbuf_addch (sb,'\n' ); -if (context->show_notes) -format_display_notes (commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +if (context->after_message) +strbuf_addstr (sb, context->after_message); + +if (context->show_notes) { +if (fmt ==CMIT_FMT_EMAIL ) { +strbuf_addch (sb,'\n' ); +format_note (NULL , commit->object.sha1, sb, encoding,0 ); +strbuf_addch (sb,'\n' ); + }else { +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER |NOTES_INDENT ); + } + } + +if (context->after_notes) +strbuf_addstr (sb, context->after_notes);free (reencoded); }
t/t4014-format-patch.sh +91 -0
95 lines not on this page · raw message
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH] BROKEN -- format-patch: learn to fill comment section of email from notes
Quoted 1 line · On Tuesday 23 February 2010 18:34:56 Thomas Rast wrote:
[PATCH] BROKEN -- format-patch: learn to fill comment section of email from notes
BTW, I forgot to say: the breakage is visible in either t4013 or t4014, depending which way you tweak the newlines.
IIRC there's also a problem with this patch and Signed-off-by handling, which I didn't bother fixing because I couldn't get the newlines right.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH] BROKEN -- format-patch: learn to fill comment section of email from notes
Quoted 5 lines · Thomas Rast
Quoted 1 line · On Tuesday 23 February 2010 18:34:56 Thomas Rast wrote:
[PATCH] BROKEN -- format-patch: learn to fill comment section of email from notes
BTW, I forgot to say: the breakage is visible in either t4013 or t4014, depending which way you tweak the newlines.
Last time I tried to touch the code in this area I gave up. It looks like you're experiencing the same problem where pretty formats cause problems in the tests. I would love to see this sorted out so I can resurrect my dead topic "log-tree: always add --- marker when options are patch and a stat".
Good luck!
PATCH v5 3/11 Documentation: document post-rewrite hook
In reply to Thomas RastThis defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
---
* adapt docs to the fact that git-filter-branch doesn't call the hook in this series
* specify commit ordering for rebase
Documentation/githooks.txt | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
Documentation/githooks.txt +34 -0
@@ -317,6 +317,40 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call +it!). Its first argument denotes the command it was invoked by: +currently one of `amend` or `rebase`. Further command-dependent +arguments may be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. ++ +The commits are guaranteed to be listed in the order that they were +processed by rebase. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 4/11 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
---
builtin-commit.c | 39 +++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin-commit.c +39 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +run_rewrite_hook (head_sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -445,7 +445,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH v5 00/11] several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 8 lines · Thomas Rast
Quoted 2 lines
Yuck. If you know what needs to be done, do that before other poeple add more options, please.
*shrug*
I was trying to be smart and save a call to
git_config()when we know we don't care about the config anyway. After all it does read a bunch of files.
You can set a flag to skip reading the trees (which is the expensive part) you know you are not going to use to optimize out the expensive part of the code, no?
Quoted 4 lines
Quoted 2 lines
Perhaps I am not reading your code right in which case this part needs a bit more commenting?
The catch is in the '&&
t->ref'.
Ahh, Ok, so that was what I didn't see. Perhaps it needs to say t->ref is set only under such and such conditions. I am reasonably sure the next person who needs to change this part of the code would appreciate such a comment and that person may even be you 3 months from now.
PATCH v5 5/11 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
---
git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -575,6 +575,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -582,6 +583,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -765,6 +767,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -773,6 +779,10 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + git gc --auto rm -fr "$dotest"
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 6/11 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
---
git-rebase--interactive.sh | 46 +++++++++++++++++++++- t/t5407-post-rewrite-hook.sh | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +45 -1
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/stopped-sha make_patch "$1" git rerere die "$2"
@@ -348,6 +356,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -425,6 +434,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -438,6 +467,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -446,6 +476,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -453,6 +484,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + echo "$1" > "$DOTEST"/stopped-sha make_patch $sha1 git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest"
@@ -509,6 +541,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -537,6 +570,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -571,7 +609,12 @@ skip_unnecessary_picks () { esac echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd done <"$TODO" >"$TODO.new" 3>>"$DONE" && - mv -f "$TODO".new "$TODO" || + mv -f "$TODO".new "$TODO" && + case "$(peek_next_command)" in + squash|s|fixup|f) + record_in_rewritten "$ONTO" + ;; + esac || die "Could not skip unnecessary pick commands" }
@@ -685,6 +728,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +90 -0
94 lines not on this page · raw message
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH v5 06/11] rebase -i: invoke post-rewrite hook
t/t5407-post-rewrite-hook.sh EOF · line 119
Quoted 4 lines · Thomas Rast
t/t5407-post-rewrite-hook.sh +4
-0+test_expect_success 'git rebase -i (unchanged)' ' + git reset --hard D && + clear_hook_input && + FAKE_LINES="1 2" test_must_fail git rebase -i --onto A B &&
This
t/t5407-post-rewrite-hook.sh EOF · line 134
Quoted 5 lines
...
t/t5407-post-rewrite-hook.sh +4
-0+test_expect_success 'git rebase -i (skip)' ' + git reset --hard D && + clear_hook_input && + FAKE_LINES="2" test_must_fail git rebase -i --onto A B &&
and this
t/t5407-post-rewrite-hook.sh EOF · line 148
Quoted 5 lines
...
t/t5407-post-rewrite-hook.sh +4
-0+test_expect_success 'git rebase -i (squash)' ' + git reset --hard D && + clear_hook_input && + FAKE_LINES="1 squash 2" test_must_fail git rebase -i --onto A B &&
and this need to be fixed to something like
( FAKE_LINES=... &&
export FAKE_LINES &&
test_must_fail git ... ) &&for Bourne-shell portability. test_must_fail is a shell function and the usual one-shot-assignment-to-export rule does not apply.
PATCH v5 7/11 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
---
Documentation/git-notes.txt | 12 ++++++++- builtin-notes.c | 56 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 20 +++++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 34 ++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -55,6 +55,16 @@ copy:: objects has none. (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin-notes.c +55 -1
82 lines not on this page · raw message
notes.c +20 -0
@@ -1187,3 +1187,23 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note =get_note (t, from_obj); +const unsigned char *existing_note =get_note (t, to_obj); + +if (!force && existing_note) +return 1 ; + +if (note) +add_note (t, to_obj, note, combine_fn); +else if (existing_note) { +add_note (t, to_obj, null_sha1, combine_fn); + }else +remove_note (t, to_obj); + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +34 -0
@@ -776,4 +776,38 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes (other): + yet another note +$whitespace + yet another note + +commit 7038787dfe22a14c3867ce816dbba39845359719 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes (other): + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + test_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 8/11 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
---
Changes since v4:
* doc tweaks
* enforce full qualification of refs
Documentation/config.txt | 30 +++++++ Documentation/git-notes.txt | 4 + Documentation/githooks.txt | 4 + builtin-notes.c | 139 +++++++++++++++++++++++++++++-- builtin.h | 18 ++++ cache.h | 2 + t/t3301-notes.sh | 195 +++++++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + 8 files changed, 386 insertions(+), 8 deletions(-)
Documentation/config.txt +30 -0
@@ -1324,6 +1324,36 @@ The effective value of "core.notesRef" (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `true`, but see + "notes.rewriteRef" below. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_REF` +environment variable, which must be a colon separated list of refs or +globs. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_MODE` +environment variable. + +notes.rewriteRef:: + When copying notes during a rewrite, specifies the (fully + qualified) ref whose notes should be copied. The ref may be a + glob, in which case notes in all matching refs will be copied. + You may also specify this configuration several times. ++ +Does not have a default value; you must configure this variable to +enable note rewriting. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -34,6 +34,10 @@ the empty string. Alternatively, you can set it to a different ref, something like "refs/notes/bugzilla". This setting can be overridden by the environment variable "GIT_NOTES_REF". +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin-notes.c +131 -8
196 lines not on this page · raw message
builtin.h +18 -0
@@ -20,6 +20,24 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree **trees; +const char *cmd; +int enabled; +combine_notes_fn *combine; +struct string_list *refs; +int refs_from_env; +int mode_from_env; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
cache.h +2 -0
@@ -388,6 +388,8 @@ static inline enum object_type object_type(unsigned int mode)#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"extern int is_bare_repository_cfg;extern int is_bare_repository (void );
t/t3301-notes.sh +195 -0
199 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -56,6 +56,8 @@ unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF unset GIT_NOTES_DISPLAY_REF +unset GIT_NOTES_REWRITE_REF +unset GIT_NOTES_REWRITE_MODE GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 9/11 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
---
git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 17 +++++++++++++++++ t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -779,8 +779,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi git gc --auto
git-rebase--interactive.sh +4 -0
@@ -570,6 +570,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +17 -0
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +24 -0
@@ -553,4 +553,28 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +cat >expect <<EOF +an earlier note +a note +EOF + +test_expect_success 'rebase -i can copy notes over a fixup' ' + git reset --hard n3 && + git notes add -m"an earlier note" n2 && + GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && + git notes show > output && + test_cmp expect output +' + test_done
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 10/11 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
---
builtin-commit.c | 6 ++++++ t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
builtin-commit.c +6 -0
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) { +struct notes_rewrite_cfg *cfg; + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, head_sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (head_sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +12 -0
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + git config notes.rewriteRef "refs/notes/*" && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.218.g73a398
PATCH v5 11/11 notes: add shorthand --ref to override GIT_NOTES_REF
In reply to Thomas RastAdds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix.
---
Changes since v4:
* doc tweaks
Documentation/git-notes.txt | 5 +++++ builtin-notes.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +5 -0
@@ -115,6 +115,11 @@ OPTIONS Like '-C', but with '-c' the editor is invoked, so that the user can further edit the note message. +--ref <ref>:: + Manipulate the notes tree in <ref>. This overrides both + GIT_NOTES_REF and the "core.notesRef" configuration. The ref + is taken to be in `refs/notes/` if it is not qualified. + Author ------ Written by Johannes Schindelin <[email protected]> and
builtin-notes.c +16 -0
@@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)int given_object =0 , i =1 , retval =0 ;struct msg_arg msg = {0 ,0 ,STRBUF_INIT };const char *rewrite_cmd =NULL ; +const char *override_notes_ref =NULL ;struct option options[] = {OPT_GROUP ("Notes options" ), OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix) "reuse specified note object", parse_reuse_arg),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ),OPT_BOOLEAN (0 ,"stdin" , &from_stdin,"read objects from stdin" ), +OPT_STRING (0 ,"ref" , &override_notes_ref,"notes_ref" , +"use notes from <notes_ref>" ),OPT_STRING (0 ,"for-rewrite" , &rewrite_cmd,"command" ,"load rewriting config for <command> (implies --stdin)" ),OPT_END ()
@@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, git_notes_usage,0 ); +if (override_notes_ref) { +struct strbuf sb =STRBUF_INIT ; +if (!prefixcmp (override_notes_ref,"refs/notes/" )) +/* we're happy */ ; +else if (!prefixcmp (override_notes_ref,"notes/" )) +strbuf_addstr (&sb,"refs/" ); +else +strbuf_addstr (&sb,"refs/notes/" ); +strbuf_addstr (&sb, override_notes_ref); +setenv ("GIT_NOTES_REF" , sb.buf,1 ); +strbuf_release (&sb); + } +if (argc && !strcmp (argv[0 ],"list" )) list =1 ;else if (argc && !strcmp (argv[0 ],"add" ))
Signature · 1 line
1.7.0.218.g73a398
Re: [PATCH v5 09/11] rebase: support automatic notes copying
In reply to Thomas RastQuoted 3 lines · Thomas Rast
Luckily, all the support already happens to be there.
Signed-off-by Thomas Rast <[email protected]>
I did my first "rebase -i / commit --amend / rebase --continue" cycle with this series, and it correctly carried notes I keep track of Message-Id of original patches with. Good job.
After looking at the output from "git log refs/notes/amlog", I have a few observations, though.
- "git notes add" and friends honor GIT_COMMITER_* and GIT_AUTHOR_* as usual. Since I use post-applypatch hook to record the message-id from "git am", I ended up getting my notes written by original submitters.
- The log messages are mostly useless. The scripted implementation said "Annotate 6d8094a8aa32c30ff39c6b8609acb8d057ccb5e5" which was not the most informative, but the new one says "Notes added by 'git notes add'".
I haven't thought things through thoroughly, and I am not complaining, but it may be worth thinking about what the "commit"-ness of generations of notes tree _should_ mean.
As we are recording the history of how the set of my notes have grown over time, I think it is natural to expect that the user can record who is recording this notes tree at what time for what reason, just like a regular commit does.
- "added by 'git notes add'" is just as immaterial as "commit log edited with vi". 'copied via notes.rebase.rewrite hook' would make much more sense.
- "git notes add" already uses -m option to take the text used as note (i.e. payload of the commit); the user may need a way to affect the commit log message to record why the note is added (or modified).
- As to the determination of committer/author identity, I think what the code currently does (i.e. honor the environment and user.* config) is perfectly sane, but at the same time I think it would be surprising for unsuspecting users. We may want to advise users about this in the documentation.
But the above is merely my personal feeling on the "notes history".
The notes implementation (from the scripted one to the one in 'pu') seems to take quite a different view and is designed as if aspects other than the topology and the tree each "commit" object records are not useful at all, and commits are used to implement the notes history only because the ancestry might help when we later implement merges of notes histories. I think that could also be a _valid_ position to take.
Re: [PATCH] format-patch: learn to fill comment section of email from notes
In reply to Thomas RastI accidentally sent out this and the "BROKEN" patch, they're the exact ones I posted on Feb 23 and should be disregarded.
Sorry for the noise...
[And this time I can't even claim it was because I was hacking past midnight :-(]
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chv6 cover several notes refs, post-rewrite, notes rewriting
In reply to Junio C HamanoHi all,
Here's (finally) the reroll. Sorry for the long wait, I was been swamped at work up until yesterday :-(
I hope I collected all changes that Junio requested; of note are
* the new interface in notes.h actually comes with comments,
* doc update to git-notes(1) in the patch that introduces notes.displayRef
I'm not aware of comments by anyone else, so if I missed them please point them out.
I did some other tweaks, including the new patch 12 that in particular avoids creating any new commits for notes refs that exist but did not have anything copied, if you have copying enabled.
Quoted 3 lines · On Thursday 25 February 2010 04:58:45 Junio C Hamano wrote:
- The log messages are mostly useless. The scripted implementation said "Annotate
6d8094a8aa32c30ff39c6b8609acb8d057ccb5e5" which was not the most informative, but the new one says "Notes added by 'git notes add'".
I hesitated making it "more informative" in the direction of "Annotate $sha1" because the same answer can be found with a simple 'git log --stat'. So I consider the "Notes added by '<command>'" to actually be more useful since it conveys something that is not readily available.
That being said, I think
Quoted 3 lines
- "git notes add" already uses -m option to take the text used as note (i.e. payload of the commit); the user may need a way to affect the commit log message to record why the note is added (or modified).
is a good idea, even if only to let people write down which note-adding script recorded this note.
Quoted 3 lines
- "git notes add" and friends honor GIT_COMMITER_* and GIT_AUTHOR_* as usual. Since I use post-applypatch hook to record the message-id from "git am", I ended up getting my notes written by original submitters.
[...]
Quoted 5 lines
- As to the determination of committer/author identity, I think what the code currently does (i.e. honor the environment and user.* config) is perfectly sane, but at the same time I think it would be surprising for unsuspecting users. We may want to advise users about this in the documentation.
I added a small patch that writes this and the history recording down in git-notes(1). However, I'm hesitating to directly say "and this will bite you if you use it in post-applypatch"; isn't the latter an implementation detail of git-am?
Thomas Rast (13):
test-lib: unset GIT_NOTES_REF to stop it from influencing tests Support showing notes from more than one notes tree
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
notes: add shorthand --ref to override GIT_NOTES_REF
notes: track whether notes_trees were changed at all git-notes(1): add a section about the meaning of history
Documentation/config.txt | 53 +++++- Documentation/git-notes.txt | 46 ++++- Documentation/githooks.txt | 38 ++++ Documentation/pretty-options.txt | 11 +- builtin.h | 18 ++ builtin/commit.c | 45 +++++ builtin/log.c | 2 + builtin/notes.c | 197 ++++++++++++++++++++- cache.h | 3 + git-am.sh | 13 ++ git-rebase--interactive.sh | 52 +++++- git-rebase.sh | 6 + notes.c | 195 +++++++++++++++++++- notes.h | 67 +++++++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 ++ revision.h | 5 + t/t3301-notes.sh | 377 +++++++++++++++++++++++++++++++++++++- t/t3400-rebase.sh | 17 ++ t/t3404-rebase-interactive.sh | 24 +++ t/t5407-post-rewrite-hook.sh | 183 ++++++++++++++++++ t/t7501-commit.sh | 12 ++ t/test-lib.sh | 4 + 25 files changed, 1371 insertions(+), 33 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
PATCH v6 1/13 test-lib: unset GIT_NOTES_REF to stop it from influencing tests
---
t/test-lib.sh | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
t/test-lib.sh +1 -0
@@ -54,6 +54,7 @@ unset GIT_OBJECT_DIRECTORY unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY +unset GIT_NOTES_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 2/13 Support showing notes from more than one notes tree
In reply to Thomas RastWith this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular.
---
Changes since v5
* make display_notes_{refs,trees} static
* foo() -> foo(void)
* assert() that init_display_notes() is only called once
* add invocation comments to the new functions in notes.h
* bring git-notes(1) up to date wrt. notes display
Documentation/config.txt | 23 +++++- Documentation/git-notes.txt | 11 ++- Documentation/pretty-options.txt | 11 ++- builtin/log.c | 2 + cache.h | 1 + notes.c | 173 ++++++++++++++++++++++++++++++++++++-- notes.h | 57 +++++++++++++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 +++++ revision.h | 5 + t/t3301-notes.sh | 148 ++++++++++++++++++++++++++++++-- t/test-lib.sh | 1 + 14 files changed, 439 insertions(+), 29 deletions(-)
Documentation/config.txt +21 -2
@@ -519,10 +519,12 @@ check that makes sure that existing object files will not get overwritten. core.notesRef:: When showing commit messages, also show notes which are stored in the given ref. This ref is expected to contain files named - after the full SHA-1 of the commit they annotate. + after the full SHA-1 of the commit they annotate. The ref + must be fully qualified. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes (<refname>):" +line (shortened to "Notes:" in the case of "refs/notes/commits"). If the given ref itself does not exist, it is not an error, but means that no notes should be printed. +
@@ -1341,6 +1343,23 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + The (fully qualified) refname from which to show notes when + showing commit messages. The value of this variable can be set + to a glob, in which case notes from all matching refs will be + shown. You may also specify this configuration variable + several times. A warning will be issued for refs that do not + exist, but a glob that does not match any refs is silently + ignored. ++ +This setting can be overridden with the `GIT_NOTES_DISPLAY_REF` +environment variable, which must be a colon separated list of refs or +globs. ++ +The effective value of "core.notesRef" (possibly overridden by +GIT_NOTES_REF) is also implicitly added to the list of refs to be +displayed. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +6 -5
@@ -27,12 +27,13 @@ A typical use of notes is to extend a commit message without having to change the commit itself. Such commit notes can be shown by `git log` along with the original commit message. To discern these notes from the message stored in the commit object, the notes are indented like the -message, after an unindented line saying "Notes:". +message, after an unindented line saying "Notes (<refname>):" (or +"Notes:" for the default setting). -To disable notes, you have to set the config variable core.notesRef to -the empty string. Alternatively, you can set it to a different ref, -something like "refs/notes/bugzilla". This setting can be overridden -by the environment variable "GIT_NOTES_REF". +This command always manipulates the notes specified in "core.notesRef" +(see linkgit:git-config[1]), which can be overridden by GIT_NOTES_REF. +To change which notes are shown by 'git-log', see the +"notes.displayRef" configuration. SUBCOMMANDS
Documentation/pretty-options.txt +10 -1
@@ -30,9 +30,18 @@ people using 80-column terminals. defaults to UTF-8. --no-notes:: ---show-notes:: +--show-notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. This is the default for `git log`, `git show` and `git whatchanged` commands when there is no `--pretty`, `--format` nor `--oneline` option is given on the command line. ++ +With an optional argument, add this ref to the list of notes. The ref +is taken to be in `refs/notes/` if it is not qualified. + +--[no-]standard-notes:: + Enable or disable populating the notes ref list from the + 'core.notesRef' and 'notes.displayRef' variables (or + corresponding environment overrides). See + linkgit:git-config[1].
builtin/log.c +2 -0
@@ -77,6 +77,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,if (!rev->show_notes_given && !rev->pretty_given) rev->show_notes =1 ; +if (rev->show_notes) +init_display_notes (&rev->notes_opt);if (rev->diffopt.pickaxe || rev->diffopt.filter) rev->always_show_header =0 ;
cache.h +1 -0
@@ -387,6 +387,7 @@ static inline enum object_type object_type(unsigned int mode)#define ATTRIBUTE_MACRO_PREFIX "[attr]"#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"/* * Repository-local GIT_* environment variables
notes.c +166 -7
212 lines not on this page · raw message
notes.h +57 -0
61 lines not on this page · raw message
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER |NOTES_INDENT );free (reencoded); }
refs.c +1 -3
@@ -695,7 +695,6 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, {struct strbuf real_pattern =STRBUF_INIT ;struct ref_filter filter; -const char *has_glob_specials;int ret;if (!prefix &&prefixcmp (pattern,"refs/" ))
@@ -704,8 +703,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,strbuf_addstr (&real_pattern, prefix);strbuf_addstr (&real_pattern, pattern); - has_glob_specials =strpbrk (pattern,"?*[" ); -if (!has_glob_specials) { +if (!has_glob_specials (pattern)) {/* Append implied '/' '*' if not present. */ if (real_pattern.buf[real_pattern.len -1 ] !='/' )strbuf_addch (&real_pattern,'/' );
refs.h +5 -0
@@ -28,6 +28,11 @@ struct ref_lock {extern int for_each_glob_ref (each_ref_fn ,const char *pattern,void *);extern int for_each_glob_ref_in (each_ref_fn ,const char *pattern,const char * prefix,void *); +static inline const char *has_glob_specials (const char *pattern) +{ +return strpbrk (pattern,"?*[" ); +} +/* can be used to learn about broken ref and symref */ extern int for_each_rawref (each_ref_fn ,void *);
revision.c +21 -0
@@ -12,6 +12,7 @@#include "patch-ids.h" #include "decorate.h" #include "log-tree.h" +#include "string-list.h" volatile show_early_output_fn_t show_early_output;
@@ -1191,9 +1192,29 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg }else if (!strcmp (arg,"--show-notes" )) { revs->show_notes =1 ; revs->show_notes_given =1 ; + }else if (!prefixcmp (arg,"--show-notes=" )) { +struct strbuf buf =STRBUF_INIT ; + revs->show_notes =1 ; + revs->show_notes_given =1 ; +if (!revs->notes_opt.extra_notes_refs) + revs->notes_opt.extra_notes_refs =xcalloc (1 ,sizeof (struct string_list )); +if (!prefixcmp (arg+13 ,"refs/" )) +/* happy */ ; +else if (!prefixcmp (arg+13 ,"notes/" )) +strbuf_addstr (&buf,"refs/" ); +else +strbuf_addstr (&buf,"refs/notes/" ); +strbuf_addstr (&buf, arg+13 ); +string_list_append (strbuf_detach (&buf,NULL ), + revs->notes_opt.extra_notes_refs); }else if (!strcmp (arg,"--no-notes" )) { revs->show_notes =0 ; revs->show_notes_given =1 ; + }else if (!strcmp (arg,"--standard-notes" )) { + revs->show_notes_given =1 ; + revs->notes_opt.suppress_default_notes =0 ; + }else if (!strcmp (arg,"--no-standard-notes" )) { + revs->notes_opt.suppress_default_notes =1 ; }else if (!strcmp (arg,"--oneline" )) { revs->verbose_header =1 ;get_commit_format ("oneline" , revs);
revision.h +5 -0
@@ -3,6 +3,7 @@#include "parse-options.h" #include "grep.h" +#include "notes.h" #define SEEN (1u<<0)#define UNINTERESTING (1u<<1)
@@ -20,6 +21,7 @@struct rev_info ;struct log_info ; +struct string_list ;struct rev_info {/* Starting list */
@@ -126,6 +128,9 @@ struct rev_info {struct reflog_walk_info *reflog_info;struct decoration children;struct decoration merge_simplification; + +/* notes-specific options: which refs to show */ +struct display_notes_opt notes_opt; };#define REV_TREE_SAME 0
t/t3301-notes.sh +140 -8
203 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -55,6 +55,7 @@ unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF +unset GIT_NOTES_DISPLAY_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 3/13 Documentation: document post-rewrite hook
In reply to Thomas RastThis defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
---
Documentation/githooks.txt | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
Documentation/githooks.txt +34 -0
@@ -317,6 +317,40 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call +it!). Its first argument denotes the command it was invoked by: +currently one of `amend` or `rebase`. Further command-dependent +arguments may be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. ++ +The commits are guaranteed to be listed in the order that they were +processed by rebase. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 4/13 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
---
builtin/commit.c | 39 +++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin/commit.c +39 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +run_rewrite_hook (head_sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -436,7 +436,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 5/13 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
---
git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -593,6 +593,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -600,6 +601,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -783,6 +785,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -791,5 +797,9 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + rm -fr "$dotest" git gc --auto
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 6/13 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
---
Changes since v5
* work around one-shot export to test_must_fail
git-rebase--interactive.sh | 46 +++++++++++++++++++- t/t5407-post-rewrite-hook.sh | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +45 -1
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/stopped-sha make_patch "$1" git rerere die "$2"
@@ -339,6 +347,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -416,6 +425,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -429,6 +458,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -437,6 +467,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -444,6 +475,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + echo "$1" > "$DOTEST"/stopped-sha make_patch $sha1 git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest"
@@ -500,6 +532,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -528,6 +561,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -562,7 +600,12 @@ skip_unnecessary_picks () { esac echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd done <"$TODO" >"$TODO.new" 3>>"$DONE" && - mv -f "$TODO".new "$TODO" || + mv -f "$TODO".new "$TODO" && + case "$(peek_next_command)" in + squash|s|fixup|f) + record_in_rewritten "$ONTO" + ;; + esac || die "Could not skip unnecessary pick commands" }
@@ -676,6 +719,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +101 -0
105 lines not on this page · raw message
Signature · 1 line
1.7.0.2.407.g21ebda
Re: [PATCH v6 00/13] several notes refs, post-rewrite, notes rewriting
In reply to Thomas RastQuoted 2 lines · Thomas Rast
I'm not aware of comments by anyone else, so if I missed them please point them out.
Yes, please ;-)
Quoted 10 lines
Quoted 3 lines
- "git notes add" and friends honor GIT_COMMITER_* and GIT_AUTHOR_* as usual. Since I use post-applypatch hook to record the message-id from "git am", I ended up getting my notes written by original submitters.
[...]
Quoted 5 lines
- As to the determination of committer/author identity, I think what the code currently does (i.e. honor the environment and user.* config) is perfectly sane, but at the same time I think it would be surprising for unsuspecting users. We may want to advise users about this in the documentation.
Quoted 4 lines
I added a small patch that writes this and the history recording down in git-notes(1). However, I'm hesitating to directly say "and this will bite you if you use it in post-applypatch"; isn't the latter an implementation detail of git-am?
Probably. We haven't documented what can and cannot be used by pre- and post- applypatch, but I think at least post-applypatch should not rely on the authorship information exported from the caller; if it wants to find out, it can parse HEAD, and because it is a post-hook, it should always be correct no matter how git-am implementation will change in the future.
PATCH v6 7/13 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
---
Changes since v5
* don't remove note we know doesn't exist
Documentation/git-notes.txt | 12 ++++++++- builtin/notes.c | 56 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 19 ++++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 34 ++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -56,6 +56,16 @@ copy:: object has none (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin/notes.c +55 -1
82 lines not on this page · raw message
notes.c +19 -0
@@ -1189,3 +1189,22 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note =get_note (t, from_obj); +const unsigned char *existing_note =get_note (t, to_obj); + +if (!force && existing_note) +return 1 ; + +if (note) +add_note (t, to_obj, note, combine_fn); +else if (existing_note) { +add_note (t, to_obj, null_sha1, combine_fn); + } + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +34 -0
@@ -777,4 +777,38 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes (other): + yet another note +$whitespace + yet another note + +commit 7038787dfe22a14c3867ce816dbba39845359719 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes (other): + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + test_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 8/13 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
---
Documentation/config.txt | 30 +++++++ Documentation/git-notes.txt | 4 + Documentation/githooks.txt | 4 + builtin.h | 18 ++++ builtin/notes.c | 139 +++++++++++++++++++++++++++++-- cache.h | 2 + t/t3301-notes.sh | 195 +++++++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + 8 files changed, 386 insertions(+), 8 deletions(-)
Documentation/config.txt +30 -0
@@ -1360,6 +1360,36 @@ The effective value of "core.notesRef" (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `true`, but see + "notes.rewriteRef" below. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_REF` +environment variable, which must be a colon separated list of refs or +globs. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_MODE` +environment variable. + +notes.rewriteRef:: + When copying notes during a rewrite, specifies the (fully + qualified) ref whose notes should be copied. The ref may be a + glob, in which case notes in all matching refs will be copied. + You may also specify this configuration several times. ++ +Does not have a default value; you must configure this variable to +enable note rewriting. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -35,6 +35,10 @@ This command always manipulates the notes specified in "core.notesRef" To change which notes are shown by 'git-log', see the "notes.displayRef" configuration. +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin.h +18 -0
@@ -20,6 +20,24 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree **trees; +const char *cmd; +int enabled; +combine_notes_fn *combine; +struct string_list *refs; +int refs_from_env; +int mode_from_env; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
builtin/notes.c +131 -8
196 lines not on this page · raw message
cache.h +2 -0
@@ -388,6 +388,8 @@ static inline enum object_type object_type(unsigned int mode)#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"/* * Repository-local GIT_* environment variables
t/t3301-notes.sh +195 -0
199 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -56,6 +56,8 @@ unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF unset GIT_NOTES_DISPLAY_REF +unset GIT_NOTES_REWRITE_REF +unset GIT_NOTES_REWRITE_MODE GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 9/13 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
---
git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 17 +++++++++++++++++ t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -797,8 +797,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi rm -fr "$dotest"
git-rebase--interactive.sh +4 -0
@@ -561,6 +561,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +17 -0
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +24 -0
@@ -553,4 +553,28 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +cat >expect <<EOF +an earlier note +a note +EOF + +test_expect_success 'rebase -i can copy notes over a fixup' ' + git reset --hard n3 && + git notes add -m"an earlier note" n2 && + GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && + git notes show > output && + test_cmp expect output +' + test_done
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 10/13 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
---
builtin/commit.c | 6 ++++++ t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
builtin/commit.c +6 -0
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) { +struct notes_rewrite_cfg *cfg; + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, head_sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (head_sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +12 -0
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + git config notes.rewriteRef "refs/notes/*" && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 11/13 notes: add shorthand --ref to override GIT_NOTES_REF
In reply to Thomas RastAdds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix.
---
Documentation/git-notes.txt | 5 +++++ builtin/notes.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +5 -0
@@ -116,6 +116,11 @@ OPTIONS Like '-C', but with '-c' the editor is invoked, so that the user can further edit the note message. +--ref <ref>:: + Manipulate the notes tree in <ref>. This overrides both + GIT_NOTES_REF and the "core.notesRef" configuration. The ref + is taken to be in `refs/notes/` if it is not qualified. + Author ------ Written by Johannes Schindelin <[email protected]> and
builtin/notes.c +16 -0
@@ -438,6 +438,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)int given_object =0 , i =1 , retval =0 ;struct msg_arg msg = {0 ,0 ,STRBUF_INIT };const char *rewrite_cmd =NULL ; +const char *override_notes_ref =NULL ;struct option options[] = {OPT_GROUP ("Notes contents options" ), {OPTION_CALLBACK ,'m' ,"message" , &msg,"MSG" ,
@@ -455,6 +456,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)OPT_GROUP ("Other options" ),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ),OPT_BOOLEAN (0 ,"stdin" , &from_stdin,"read objects from stdin" ), +OPT_STRING (0 ,"ref" , &override_notes_ref,"notes_ref" , +"use notes from <notes_ref>" ),OPT_STRING (0 ,"for-rewrite" , &rewrite_cmd,"command" ,"load rewriting config for <command> (implies --stdin)" ),OPT_END ()
@@ -464,6 +467,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, git_notes_usage,0 ); +if (override_notes_ref) { +struct strbuf sb =STRBUF_INIT ; +if (!prefixcmp (override_notes_ref,"refs/notes/" )) +/* we're happy */ ; +else if (!prefixcmp (override_notes_ref,"notes/" )) +strbuf_addstr (&sb,"refs/" ); +else +strbuf_addstr (&sb,"refs/notes/" ); +strbuf_addstr (&sb, override_notes_ref); +setenv ("GIT_NOTES_REF" , sb.buf,1 ); +strbuf_release (&sb); + } +if (argc && !strcmp (argv[0 ],"list" )) list =1 ;else if (argc && !strcmp (argv[0 ],"add" ))
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 12/13 notes: track whether notes_trees were changed at all
In reply to Thomas RastCurrently, the notes copying is a bit wasteful since it always creates new trees, even if no notes were copied at all.
Teach add_note() and remove_note() to flag the affected notes tree as changed ('dirty'). Then teach builtin/notes.c to use this knowledge and avoid committing trees that weren't changed.
---
New in this iteration
builtin/notes.c | 2 ++ notes.c | 3 +++ notes.h | 1 + 3 files changed, 6 insertions(+), 0 deletions(-)
builtin/notes.c +2 -0
@@ -240,6 +240,8 @@ int commit_notes(struct notes_tree *t, const char *msg) t = &default_notes_tree;if (!t->initialized || !t->ref || !*t->ref)die ("Cannot commit uninitialized/unreferenced notes tree" ); +if (!t->dirty) +return 0 ;/* don't have to commit an unchanged tree */ /* Prepare commit message and reflog message */ strbuf_addstr (&buf,"notes: " );/* commit message starts at index 7 */
notes.c +3 -0
@@ -926,6 +926,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, t->ref = notes_ref ?xstrdup (notes_ref) :NULL ; t->combine_notes = combine_notes; t->initialized =1 ; + t->dirty =0 ;if (flags &NOTES_INIT_EMPTY || !notes_ref ||read_ref (notes_ref, object_sha1))
@@ -1014,6 +1015,7 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,if (!t) t = &default_notes_tree;assert (t->initialized); + t->dirty =1 ;if (!combine_notes) combine_notes = t->combine_notes; l = (struct leaf_node *)xmalloc (sizeof (struct leaf_node ));
@@ -1029,6 +1031,7 @@ void remove_note(struct notes_tree *t, const unsigned char *object_sha1)if (!t) t = &default_notes_tree;assert (t->initialized); + t->dirty =1 ;hashcpy (l.key_sha1, object_sha1);hashclr (l.val_sha1);return note_tree_remove (t, t->root,0 , &l);
notes.h +1 -0
@@ -40,6 +40,7 @@char *ref;combine_notes_fn *combine_notes;int initialized; +int dirty; } default_notes_tree;/*
Signature · 1 line
1.7.0.2.407.g21ebda
PATCH v6 13/13 git-notes(1): add a section about the meaning of history
In reply to Thomas RastTo the displaying code, the only interesting thing about a notes ref is that it has a tree of the required format. However, notes actually have a history since they are recorded as successive commits.
Make a note about the existence of this history in the manpage, but keep some doors open if we want to change the details.
---
New in v6, as per Junio's comment
Quoted 5 lines
- As to the determination of committer/author identity, I think what the code currently does (i.e. honor the environment and user.* config) is perfectly sane, but at the same time I think it would be surprising for unsuspecting users. We may want to advise users about this in the documentation.
(but see the series leader for more discussion about this).
Documentation/git-notes.txt | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +14 -0
@@ -121,6 +121,20 @@ OPTIONS GIT_NOTES_REF and the "core.notesRef" configuration. The ref is taken to be in `refs/notes/` if it is not qualified. + +NOTES +----- + +Every notes change creates a new commit at the specified notes ref. +You can therefore inspect the history of the notes by invoking, e.g., +`git log -p notes/commits`. + +Currently the commit message only records which operation triggered +the update, and the commit authorship is determined according to the +usual rules (see linkgit:git-commit[1]). These details may change in +the future. + + Author ------ Written by Johannes Schindelin <[email protected]> and
Signature · 1 line
1.7.0.2.407.g21ebda
Re: [PATCH v6 01/13] test-lib: unset GIT_NOTES_REF to stop it from influencing tests
In reply to Thomas RastQuoted 11 lines · Thomas Rast
---
t/test-lib.sh | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)t/test-lib.sh +0
-0
t/test-lib.sh unset GIT_OBJECT_DIRECTORY · line 60
Quoted 7 lines
t/test-lib.sh +1
-0@@ -54,6 +54,7 @@ unset GIT_OBJECT_DIRECTORY unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY +unset GIT_NOTES_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
...Johan
Signature · 2 lines
Johan Herland, <[email protected]> www.herland.net
Re: [PATCH v6 02/13] Support showing notes from more than one notes tree
In reply to Thomas RastQuoted 6 lines · Thomas Rast
With this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Quoted 7 lines
Then git-log and friends will show notes from all trees.
Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular.
Signed-off-by Thomas Rast <[email protected]>
...except for the following small niggles:
Quoted 14 lines
(quoted diff) +0
-0
b/Documentation/pretty-options.txtindex aa96cae..1d56926 100644Documentation/pretty-options.txt +1
-1@@ -30,9 +30,18 @@ people using 80-column terminals. defaults to UTF-8. --no-notes:: ---show-notes:: +--show-notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. This is the default for `git log`, `git show` and `git whatchanged` commands when there is no `--pretty`, `--format` nor `--oneline` option is
Documentation/pretty-options.txt people using 80-column terminals. · line 47
Quoted 10 lines
Documentation/pretty-options.txt +9
-0given on the command line. ++ +With an optional argument, add this ref to the list of notes. The ref +is taken to be in `refs/notes/` if it is not qualified. + +--[no-]standard-notes:: + Enable or disable populating the notes ref list from the + 'core.notesRef' and 'notes.displayRef' variables (or + corresponding environment overrides). See + linkgit:git-config[1].
Should probably mention that --standard-notes describes the default behaviour.
notes.c int combine_notes_ignore(unsigned char *cur_sha1, · line 888
Quoted 13 lines
notes.c +9
-0+static int notes_display_config (const char *k,const char *v,void *cb) +{ +int *load_refs = cb; + +if (*load_refs && !strcmp (k,"notes.displayref" )) { +if (!v) +config_error_nonbool (k); +string_list_add_refs_by_glob (&display_notes_refs, v); +return 0 ;
This "return 0" is unnecessary
notes.c void init_notes(struct notes_tree *t, const char *notes_ref, · line 976
Quoted 7 lines
notes.c +7
-0+static int string_list_add_refs_from_list (struct string_list_item *item, +void *cb) +{ +struct string_list *list = cb; +string_list_add_refs_by_glob (list, item->string); +return 0 ; +}
Shouldn't string_list_add_refs_from_list() be placed up with the other string_list_add_* functions?
Quoted 8 lines
notes.c +8
-0+void init_display_notes (struct display_notes_opt *opt) +{ +char *display_ref_env; +int load_config_refs =0 ; + display_notes_refs.strdup_strings =1 ; + +assert (!display_notes_trees); +
notes.c void init_notes(struct notes_tree *t, const char *notes_ref, · line 995
Quoted 10 lines
notes.c +10
-0+if (!opt || !opt->suppress_default_notes) { +string_list_append (default_notes_ref (), &display_notes_refs); + display_ref_env =getenv (GIT_NOTES_DISPLAY_REF_ENVIRONMENT ); +if (display_ref_env) { +string_list_add_refs_from_colon_sep (&display_notes_refs, + display_ref_env); + load_config_refs =0 ; + }else { + load_config_refs =1 ; + }
Drop unnecessary braces in the 'else'
notes.c void format_note(struct notes_tree *t, const · line 1187
Quoted 12 lines
notes.c +7
-0@@ -1030,3 +1178,14 @@ void format_note(struct notes_tree *t, constunsigned char *object_sha1,free (msg ); } + +void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags) +{ +int i; +if (!display_notes_trees) +init_display_notes (NULL );
Not sure I like this "fallback" call to init_display_notes(NULL). There's already a call from builtin/log.c which passes "&rev->notes_opt", and this fallback is at best useless (since init_display_notes() has already been called from builtin/log.c), and at worst confusing, since it would _mask_ a missing init_display_notes(options) call from elsewhere.
I'd rather suggest that format_display_notes() should fail because of a missing init_display_notes(), and not silently compensate for missing initialization by self-initializing with default options (thus disregarding any notes-related options the user might have passed on the command-line).
Quoted 5 lines
notes.h +1
-0+/*
notes.h int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, · line 234
Quoted 10 lines
notes.h +10
-0+* Append notes for the given 'object_sha1' from all trees set up by +* init_display_notes() to 'sb'. The 'flags' are a bitwise +* combination of +* +* - NOTES_SHOW_HEADER: add a 'Notes (refname):' header +* +* - NOTES_INDENT: indent the notes by 4 places +* +* init_display_notes() is called implicitly for you if you haven't +* already.
As I said above, the implicit initialization turns a missing init_display_notes(with_approriate_options) call into a init_display_notes(NULL) call. This makes it harder to pinpoint future bugs in this area (which are likely to crop up as we add notes functionality to more Git commands).
But I don't think this is important enough to hold up the patch series.
notes.h int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, · line 243
Quoted 9 lines
+ */
notes.h +8
-0+void format_display_notes (const unsigned char *object_sha1, +struct strbuf *sb,const char *output_encoding,int flags); + +/* +* Load the notes tree from each ref listed in 'refs'. The output is +* an array of notes_tree*, terminated by a NULL. +*/ +struct notes_tree **load_notes_trees (struct string_list *refs);
Although this looks like a useful utility function, I'm not sure how useful it is in practice: What would you really _do_ with the returned struct notes_tree **? You can't pass it to format_display_notes() (which only uses the internal display_notes_trees)...
notes.h int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, · line 256
Quoted 12 lines
notes.h +4
-0+/* +* Add all refs that match 'glob' to the 'list'. +*/ +void string_list_add_refs_by_glob(struct string_list *list, const char*glob); +
notes.h +7
-0+/* +* Add all refs from a colon-separated glob list 'globs' to the end of +* 'list'. Empty components are ignored. This helper is used to +* parse GIT_NOTES_DISPLAY_REF style environment variables. +*/ +void string_list_add_refs_from_colon_sep (struct string_list *list, +const char *globs);
The same goes for these. Do they have actual outside callers? AFAICS we only ever use the internal display_notes_refs and display_notes_trees lists in notes.c, so there's limited potential for external use.
Otherwise, it all looks good to me. :)
...Johan
Signature · 2 lines
Johan Herland, <[email protected]> www.herland.net
v7 cover tr/display-notes
Here's a hopefully last replacement for the series. I implemented Johan's requests for changes and collected his acks; the only behavioral change is that format_display_notes() no longer calls init_display_notes() implicitly.
Thomas Rast (13):
test-lib: unset GIT_NOTES_REF to stop it from influencing tests Support showing notes from more than one notes tree
Documentation: document post-rewrite hook
commit --amend: invoke post-rewrite hook
rebase: invoke post-rewrite hook
rebase -i: invoke post-rewrite hook
notes: implement 'git notes copy --stdin'
notes: implement helpers needed for note copying during rewrite
rebase: support automatic notes copying
commit --amend: copy notes to the new commit
notes: add shorthand --ref to override GIT_NOTES_REF
notes: track whether notes_trees were changed at all git-notes(1): add a section about the meaning of history
Documentation/config.txt | 53 +++++- Documentation/git-notes.txt | 46 ++++- Documentation/githooks.txt | 38 ++++ Documentation/pretty-options.txt | 11 +- builtin.h | 18 ++ builtin/commit.c | 45 +++++ builtin/log.c | 5 + builtin/notes.c | 197 ++++++++++++++++++++- cache.h | 3 + git-am.sh | 13 ++ git-rebase--interactive.sh | 52 +++++- git-rebase.sh | 6 + notes.c | 191 +++++++++++++++++++- notes.h | 66 +++++++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 ++ revision.h | 5 + t/t3301-notes.sh | 377 +++++++++++++++++++++++++++++++++++++- t/t3400-rebase.sh | 17 ++ t/t3404-rebase-interactive.sh | 24 +++ t/t5407-post-rewrite-hook.sh | 183 ++++++++++++++++++ t/t7501-commit.sh | 12 ++ t/test-lib.sh | 4 + 25 files changed, 1369 insertions(+), 33 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
PATCH v7 1/13 test-lib: unset GIT_NOTES_REF to stop it from influencing tests
---
t/test-lib.sh | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
t/test-lib.sh +1 -0
@@ -54,6 +54,7 @@ unset GIT_OBJECT_DIRECTORY unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY +unset GIT_NOTES_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 2/13 Support showing notes from more than one notes tree
In reply to Thomas RastWith this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g.,
[notes]
displayRef = refs/notes/*
Then git-log and friends will show notes from all trees.
Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular.
---
* don't silently init from format_display_notes
Documentation/config.txt | 23 +++++- Documentation/git-notes.txt | 11 ++- Documentation/pretty-options.txt | 11 ++- builtin/log.c | 5 + cache.h | 1 + notes.c | 170 ++++++++++++++++++++++++++++++++++++-- notes.h | 56 +++++++++++++ pretty.c | 6 +- refs.c | 4 +- refs.h | 5 + revision.c | 21 +++++ revision.h | 5 + t/t3301-notes.sh | 148 +++++++++++++++++++++++++++++++-- t/test-lib.sh | 1 + 14 files changed, 438 insertions(+), 29 deletions(-)
Documentation/config.txt +21 -2
@@ -519,10 +519,12 @@ check that makes sure that existing object files will not get overwritten. core.notesRef:: When showing commit messages, also show notes which are stored in the given ref. This ref is expected to contain files named - after the full SHA-1 of the commit they annotate. + after the full SHA-1 of the commit they annotate. The ref + must be fully qualified. + If such a file exists in the given ref, the referenced blob is read, and -appended to the commit message, separated by a "Notes:" line. If the +appended to the commit message, separated by a "Notes (<refname>):" +line (shortened to "Notes:" in the case of "refs/notes/commits"). If the given ref itself does not exist, it is not an error, but means that no notes should be printed. +
@@ -1341,6 +1343,23 @@ mergetool.keepTemporaries:: mergetool.prompt:: Prompt before each invocation of the merge resolution program. +notes.displayRef:: + The (fully qualified) refname from which to show notes when + showing commit messages. The value of this variable can be set + to a glob, in which case notes from all matching refs will be + shown. You may also specify this configuration variable + several times. A warning will be issued for refs that do not + exist, but a glob that does not match any refs is silently + ignored. ++ +This setting can be overridden with the `GIT_NOTES_DISPLAY_REF` +environment variable, which must be a colon separated list of refs or +globs. ++ +The effective value of "core.notesRef" (possibly overridden by +GIT_NOTES_REF) is also implicitly added to the list of refs to be +displayed. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +6 -5
@@ -27,12 +27,13 @@ A typical use of notes is to extend a commit message without having to change the commit itself. Such commit notes can be shown by `git log` along with the original commit message. To discern these notes from the message stored in the commit object, the notes are indented like the -message, after an unindented line saying "Notes:". +message, after an unindented line saying "Notes (<refname>):" (or +"Notes:" for the default setting). -To disable notes, you have to set the config variable core.notesRef to -the empty string. Alternatively, you can set it to a different ref, -something like "refs/notes/bugzilla". This setting can be overridden -by the environment variable "GIT_NOTES_REF". +This command always manipulates the notes specified in "core.notesRef" +(see linkgit:git-config[1]), which can be overridden by GIT_NOTES_REF. +To change which notes are shown by 'git-log', see the +"notes.displayRef" configuration. SUBCOMMANDS
Documentation/pretty-options.txt +10 -1
@@ -30,9 +30,18 @@ people using 80-column terminals. defaults to UTF-8. --no-notes:: ---show-notes:: +--show-notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. This is the default for `git log`, `git show` and `git whatchanged` commands when there is no `--pretty`, `--format` nor `--oneline` option is given on the command line. ++ +With an optional argument, add this ref to the list of notes. The ref +is taken to be in `refs/notes/` if it is not qualified. + +--[no-]standard-notes:: + Enable or disable populating the notes ref list from the + 'core.notesRef' and 'notes.displayRef' variables (or + corresponding environment overrides). Enabled by default. + See linkgit:git-config[1].
builtin/log.c +5 -0
@@ -77,6 +77,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,if (!rev->show_notes_given && !rev->pretty_given) rev->show_notes =1 ; +if (rev->show_notes) +init_display_notes (&rev->notes_opt);if (rev->diffopt.pickaxe || rev->diffopt.filter) rev->always_show_header =0 ;
@@ -1100,6 +1102,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)if (!DIFF_OPT_TST (&rev.diffopt,TEXT ) && !no_binary_diff)DIFF_OPT_SET (&rev.diffopt,BINARY ); +if (rev.show_notes) +init_display_notes (&rev.notes_opt); +if (!use_stdout) output_directory =set_outdir (prefix, output_directory);
cache.h +1 -0
@@ -387,6 +387,7 @@ static inline enum object_type object_type(unsigned int mode)#define ATTRIBUTE_MACRO_PREFIX "[attr]"#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"/* * Repository-local GIT_* environment variables
notes.c +163 -7
209 lines not on this page · raw message
notes.h +56 -0
60 lines not on this page · raw message
pretty.c +3 -3
@@ -775,7 +775,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -format_note (NULL , commit->object.sha1, sb, +format_display_notes (commit->object.sha1, sb, git_log_output_encoding ? git_log_output_encoding : git_commit_encoding,0 );return 1 ;
@@ -1096,8 +1096,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,strbuf_addch (sb,'\n' );if (context->show_notes) -format_note (NULL , commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +format_display_notes (commit->object.sha1, sb, encoding, +NOTES_SHOW_HEADER |NOTES_INDENT );free (reencoded); }
refs.c +1 -3
@@ -695,7 +695,6 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, {struct strbuf real_pattern =STRBUF_INIT ;struct ref_filter filter; -const char *has_glob_specials;int ret;if (!prefix &&prefixcmp (pattern,"refs/" ))
@@ -704,8 +703,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,strbuf_addstr (&real_pattern, prefix);strbuf_addstr (&real_pattern, pattern); - has_glob_specials =strpbrk (pattern,"?*[" ); -if (!has_glob_specials) { +if (!has_glob_specials (pattern)) {/* Append implied '/' '*' if not present. */ if (real_pattern.buf[real_pattern.len -1 ] !='/' )strbuf_addch (&real_pattern,'/' );
refs.h +5 -0
@@ -28,6 +28,11 @@ struct ref_lock {extern int for_each_glob_ref (each_ref_fn ,const char *pattern,void *);extern int for_each_glob_ref_in (each_ref_fn ,const char *pattern,const char * prefix,void *); +static inline const char *has_glob_specials (const char *pattern) +{ +return strpbrk (pattern,"?*[" ); +} +/* can be used to learn about broken ref and symref */ extern int for_each_rawref (each_ref_fn ,void *);
revision.c +21 -0
@@ -12,6 +12,7 @@#include "patch-ids.h" #include "decorate.h" #include "log-tree.h" +#include "string-list.h" volatile show_early_output_fn_t show_early_output;
@@ -1191,9 +1192,29 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg }else if (!strcmp (arg,"--show-notes" )) { revs->show_notes =1 ; revs->show_notes_given =1 ; + }else if (!prefixcmp (arg,"--show-notes=" )) { +struct strbuf buf =STRBUF_INIT ; + revs->show_notes =1 ; + revs->show_notes_given =1 ; +if (!revs->notes_opt.extra_notes_refs) + revs->notes_opt.extra_notes_refs =xcalloc (1 ,sizeof (struct string_list )); +if (!prefixcmp (arg+13 ,"refs/" )) +/* happy */ ; +else if (!prefixcmp (arg+13 ,"notes/" )) +strbuf_addstr (&buf,"refs/" ); +else +strbuf_addstr (&buf,"refs/notes/" ); +strbuf_addstr (&buf, arg+13 ); +string_list_append (strbuf_detach (&buf,NULL ), + revs->notes_opt.extra_notes_refs); }else if (!strcmp (arg,"--no-notes" )) { revs->show_notes =0 ; revs->show_notes_given =1 ; + }else if (!strcmp (arg,"--standard-notes" )) { + revs->show_notes_given =1 ; + revs->notes_opt.suppress_default_notes =0 ; + }else if (!strcmp (arg,"--no-standard-notes" )) { + revs->notes_opt.suppress_default_notes =1 ; }else if (!strcmp (arg,"--oneline" )) { revs->verbose_header =1 ;get_commit_format ("oneline" , revs);
revision.h +5 -0
@@ -3,6 +3,7 @@#include "parse-options.h" #include "grep.h" +#include "notes.h" #define SEEN (1u<<0)#define UNINTERESTING (1u<<1)
@@ -20,6 +21,7 @@struct rev_info ;struct log_info ; +struct string_list ;struct rev_info {/* Starting list */
@@ -126,6 +128,9 @@ struct rev_info {struct reflog_walk_info *reflog_info;struct decoration children;struct decoration merge_simplification; + +/* notes-specific options: which refs to show */ +struct display_notes_opt notes_opt; };#define REV_TREE_SAME 0
t/t3301-notes.sh +140 -8
203 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -55,6 +55,7 @@ unset GIT_CEILING_DIRECTORIES unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF +unset GIT_NOTES_DISPLAY_REF GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 3/13 Documentation: document post-rewrite hook
In reply to Thomas RastThis defines the behaviour of the post-rewrite hook support, which will be implemented in the following patches.
We deliberately do not document how often the hook will be invoked per rewriting command, but the interface is designed to keep that at "once". This would currently not matter too much, since both rebase and filter-branch are shellscripts and spawn many processes anyway. However, when a fast sequencer in C is implemented, it will be beneficial to only have to run the hook once.
---
Documentation/githooks.txt | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
Documentation/githooks.txt +34 -0
@@ -317,6 +317,40 @@ This hook is invoked by 'git gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git gc --auto' to abort. +post-rewrite +~~~~~~~~~~~~ + +This hook is invoked by commands that rewrite commits (`git commit +--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call +it!). Its first argument denotes the command it was invoked by: +currently one of `amend` or `rebase`. Further command-dependent +arguments may be passed in the future. + +The hook receives a list of the rewritten commits on stdin, in the +format + + <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF + +The 'extra-info' is again command-dependent. If it is empty, the +preceding SP is also omitted. Currently, no commands pass any +'extra-info'. + +The following command-specific comments apply: + +rebase:: + For the 'squash' and 'fixup' operation, all commits that were + squashed are listed as being rewritten to the squashed commit. + This means that there will be several lines sharing the same + 'new-sha1'. ++ +The commits are guaranteed to be listed in the order that they were +processed by rebase. + +There is no default 'post-rewrite' hook, but see the +`post-receive-copy-notes` script in `contrib/hooks` for an example +that copies your git-notes to the rewritten commits. + + GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 4/13 commit --amend: invoke post-rewrite hook
In reply to Thomas RastThe rough structure of run_rewrite_hook() comes from run_receive_hook() in receive-pack.
We introduce a --no-post-rewrite option and use it to avoid the hook when called from git-rebase -i 'edit'. The next patch will add full support in git-rebase, and we only want to invoke the hook once.
---
builtin/commit.c | 39 +++++++++++++++++++++++++++++++ git-rebase--interactive.sh | 2 +- t/t5407-post-rewrite-hook.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletions(-) create mode 100755 t/t5407-post-rewrite-hook.sh
builtin/commit.c +39 -0
@@ -66,6 +66,7 @@static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff;static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; +static int no_post_rewrite;static char *untracked_files_arg, *force_date;/* * The default commit message cleanup mode will remove the lines
@@ -137,6 +138,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('z' ,"null" , &null_termination,"terminate entries with NUL" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), +OPT_BOOLEAN (0 ,"no-post-rewrite" , &no_post_rewrite,"bypass post-rewrite hook" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },OPT_BOOLEAN (0 ,"allow-empty" , &allow_empty,"ok to record an empty change" ), /* end commit contents options */
@@ -1160,6 +1162,40 @@ static int git_commit_config(const char *k, const char *v, void *cb)return git_status_config (k, v, s); } +static const char post_rewrite_hook[] ="hooks/post-rewrite" ; + +static int run_rewrite_hook (const unsigned char *oldsha1, +const unsigned char *newsha1) +{ +/* oldsha1 SP newsha1 LF NUL */ +static char buf[2 *40 +3 ]; +struct child_process proc; +const char *argv[3 ]; +int code; +size_t n; + +if (access (git_path (post_rewrite_hook),X_OK ) <0 ) +return 0 ; + + argv[0 ] =git_path (post_rewrite_hook); + argv[1 ] ="amend" ; + argv[2 ] =NULL ; + +memset (&proc,0 ,sizeof (proc)); + proc.argv = argv; + proc.in =-1 ; + proc.stdout_to_stderr =1 ; + + code =start_command (&proc); +if (code) +return code; + n =snprintf (buf,sizeof (buf),"%s %s\n" , +sha1_to_hex (oldsha1),sha1_to_hex (newsha1)); +write_in_full (proc.in, buf, n); +close (proc.in); +return finish_command (&proc); +} +int cmd_commit (int argc,const char **argv,const char *prefix) {struct strbuf sb =STRBUF_INIT ;
@@ -1303,6 +1339,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL ); +if (amend && !no_post_rewrite) { +run_rewrite_hook (head_sha1, commit_sha1); + }if (!quiet)print_summary (prefix, commit_sha1);
git-rebase--interactive.sh +1 -1
@@ -436,7 +436,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - git commit --amend + git commit --amend --no-post-rewrite ;; edit|e) comment_for_reflog edit
t/t5407-post-rewrite-hook.sh new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 5/13 rebase: invoke post-rewrite hook
In reply to Thomas RastWe have to deal with two separate code paths: a normal rebase, which actually goes through git-am; and rebase {-m|-s}.
The only small issue with both is that they need to remember the original sha1 across a possible conflict resolution. rebase -m already puts this information in $dotest/current, and we just introduce a similar file for git-am.
Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file is guarded by a test for $dotest/rebasing.
---
git-am.sh | 10 ++++++++++ git-rebase.sh | 5 +++++ t/t5407-post-rewrite-hook.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
git-am.sh +10 -0
@@ -593,6 +593,7 @@ do echo "Patch is empty. Was it split wrong?" stop_here $this } + rm -f "$dotest/original-commit" if test -f "$dotest/rebasing" && commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ -e q "$dotest/$msgnum") &&
@@ -600,6 +601,7 @@ do then git cat-file commit "$commit" | sed -e '1,/^$/d' >"$dotest/msg-clean" + echo "$commit" > "$dotest/original-commit" else { sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -783,6 +785,10 @@ do git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this + if test -f "$dotest/original-commit"; then + echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" + fi + if test -x "$GIT_DIR"/hooks/post-applypatch then "$GIT_DIR"/hooks/post-applypatch
@@ -791,5 +797,9 @@ do go_next done +if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten +fi + rm -fr "$dotest" git gc --auto
git-rebase.sh +5 -0
@@ -79,6 +79,7 @@ continue_merge () { then printf "Committed: %0${prec}d " $msgnum fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" else if test -z "$GIT_QUIET" then
@@ -151,6 +152,10 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$dotest"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi rm -r "$dotest" say All done. }
t/t5407-post-rewrite-hook.sh +30 -0
@@ -49,4 +49,34 @@ test_expect_success 'git commit --amend --no-post-rewrite' ' test ! -f post-rewrite.data ' +test_expect_success 'git rebase' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse C) $(git rev-parse HEAD^) +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse D) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_done
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 6/13 rebase -i: invoke post-rewrite hook
In reply to Thomas RastAside from the same issue that rebase also has (remembering the original commit across a conflict resolution), rebase -i brings an extra twist: We need to defer writing the rewritten list in the case of {squash,fixup} because their rewritten result should be the last commit in the squashed group.
---
git-rebase--interactive.sh | 46 +++++++++++++++++++- t/t5407-post-rewrite-hook.sh | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +45 -1
@@ -96,6 +96,13 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # command is processed, this file is deleted. AMEND="$DOTEST"/amend +# For the post-rewrite hook, we make a list of rewritten commits and +# their new sha1s. The rewritten-pending list keeps the sha1s of +# commits that have been processed, but not committed yet, +# e.g. because they are waiting for a 'squash' command. +REWRITTEN_LIST="$DOTEST"/rewritten-list +REWRITTEN_PENDING="$DOTEST"/rewritten-pending + PRESERVE_MERGES= STRATEGY= ONTO=
@@ -198,6 +205,7 @@ make_patch () { } die_with_patch () { + echo "$1" > "$DOTEST"/stopped-sha make_patch "$1" git rerere die "$2"
@@ -339,6 +347,7 @@ pick_one_preserving_merges () { printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi + echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" ;; *) output git cherry-pick "$@" ||
@@ -416,6 +425,26 @@ die_failed_squash() { die_with_patch $1 "" } +flush_rewritten_pending() { + test -s "$REWRITTEN_PENDING" || return + newsha1="$(git rev-parse HEAD^0)" + sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" + rm -f "$REWRITTEN_PENDING" +} + +record_in_rewritten() { + oldsha1="$(git rev-parse $1)" + echo "$oldsha1" >> "$REWRITTEN_PENDING" + + case "$(peek_next_command)" in + squash|s|fixup|f) + ;; + *) + flush_rewritten_pending + ;; + esac +} + do_next () { rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit read command sha1 rest < "$TODO"
@@ -429,6 +458,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + record_in_rewritten $sha1 ;; reword|r) comment_for_reflog reword
@@ -437,6 +467,7 @@ do_next () { pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" git commit --amend --no-post-rewrite + record_in_rewritten $sha1 ;; edit|e) comment_for_reflog edit
@@ -444,6 +475,7 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" + echo "$1" > "$DOTEST"/stopped-sha make_patch $sha1 git rev-parse --verify HEAD > "$AMEND" warn "Stopped at $sha1... $rest"
@@ -500,6 +532,7 @@ do_next () { rm -f "$SQUASH_MSG" "$FIXUP_MSG" ;; esac + record_in_rewritten $sha1 ;; *) warn "Unknown command: $command $sha1 $rest"
@@ -528,6 +561,11 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$REWRITTEN_LIST"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + true # we don't care if this hook failed + fi && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME."
@@ -562,7 +600,12 @@ skip_unnecessary_picks () { esac echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd done <"$TODO" >"$TODO.new" 3>>"$DONE" && - mv -f "$TODO".new "$TODO" || + mv -f "$TODO".new "$TODO" && + case "$(peek_next_command)" in + squash|s|fixup|f) + record_in_rewritten "$ONTO" + ;; + esac || die "Could not skip unnecessary pick commands" }
@@ -676,6 +719,7 @@ first and then run 'git rebase --continue' again." test -n "$amend" && git reset --soft $amend die "Could not commit staged changes." } + record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" fi require_clean_work_tree
t/t5407-post-rewrite-hook.sh +101 -0
105 lines not on this page · raw message
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 7/13 notes: implement 'git notes copy --stdin'
In reply to Thomas RastThis implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The copy_note() function is exposed for everyone's and in particular the next commit's use.
---
Documentation/git-notes.txt | 12 ++++++++- builtin/notes.c | 56 ++++++++++++++++++++++++++++++++++++++++++- notes.c | 18 +++++++++++++ notes.h | 9 +++++++ t/t3301-notes.sh | 34 ++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 2 deletions(-)
Documentation/git-notes.txt +11 -1
@@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list [<object>]] 'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] -'git notes' copy [-f] <from-object> <to-object> +'git notes' copy [-f] ( --stdin | <from-object> <to-object> ) 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] 'git notes' edit [<object>] 'git notes' show [<object>]
@@ -56,6 +56,16 @@ copy:: object has none (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list <from-object>) <to-object>` ++ +In `\--stdin` mode, take lines in the format ++ +---------- +<from-object> SP <to-object> [ SP <rest> ] LF +---------- ++ +on standard input, and copy the notes from each <from-object> to its +corresponding <to-object>. (The optional `<rest>` is ignored so that +the command can read the input given to the `post-rewrite` hook.) append:: Append to the notes of an existing object (defaults to HEAD).
builtin/notes.c +55 -1
82 lines not on this page · raw message
notes.c +18 -0
@@ -1186,3 +1186,21 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note =get_note (t, from_obj); +const unsigned char *existing_note =get_note (t, to_obj); + +if (!force && existing_note) +return 1 ; + +if (note) +add_note (t, to_obj, note, combine_fn); +else if (existing_note) +add_note (t, to_obj, null_sha1, combine_fn); + +return 0 ; +}
notes.h +9 -0
@@ -100,6 +100,15 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *object_sha1);/* +* Copy a note from one object to another in the given notes_tree. +* +* Fails if the to_obj already has a note unless 'force' is true. +*/ +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn); + +/* * Flags controlling behaviour of for_each_note() * * Default behaviour of for_each_note() is to traverse every single note object
t/t3301-notes.sh +34 -0
@@ -777,4 +777,38 @@ test_expect_success 'cannot copy note from object without notes' ' test_must_fail git notes copy HEAD^ HEAD ' +cat > expect << EOF +commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:25:13 2005 -0700 + + 13th + +Notes (other): + yet another note +$whitespace + yet another note + +commit 7038787dfe22a14c3867ce816dbba39845359719 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:24:13 2005 -0700 + + 12th + +Notes (other): + other note +$whitespace + yet another note +EOF + +test_expect_success 'git notes copy --stdin' ' + (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ + echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | + git notes copy --stdin && + git log -2 > output && + test_cmp expect output && + test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && + test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" +' + test_done
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 8/13 notes: implement helpers needed for note copying during rewrite
In reply to Thomas RastImplement helper functions to load the rewriting config, and to actually copy the notes. Also document the config.
Secondly, also implement an undocumented --for-rewrite=<cmd> option to 'git notes copy' which is used like --stdin, but also puts the configuration for <cmd> into effect. It will be needed to support the copying in git-rebase.
---
Documentation/config.txt | 30 +++++++ Documentation/git-notes.txt | 4 + Documentation/githooks.txt | 4 + builtin.h | 18 ++++ builtin/notes.c | 139 +++++++++++++++++++++++++++++-- cache.h | 2 + t/t3301-notes.sh | 195 +++++++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + 8 files changed, 386 insertions(+), 8 deletions(-)
Documentation/config.txt +30 -0
@@ -1360,6 +1360,36 @@ The effective value of "core.notesRef" (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. +notes.rewrite.<command>:: + When rewriting commits with <command> (currently `amend` or + `rebase`) and this variable is set to `true`, git + automatically copies your notes from the original to the + rewritten commit. Defaults to `true`, but see + "notes.rewriteRef" below. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_REF` +environment variable, which must be a colon separated list of refs or +globs. + +notes.rewriteMode:: + When copying notes during a rewrite (see the + "notes.rewrite.<command>" option), determines what to do if + the target commit already has a note. Must be one of + `overwrite`, `concatenate`, or `ignore`. Defaults to + `concatenate`. ++ +This setting can be overridden with the `GIT_NOTES_REWRITE_MODE` +environment variable. + +notes.rewriteRef:: + When copying notes during a rewrite, specifies the (fully + qualified) ref whose notes should be copied. The ref may be a + glob, in which case notes in all matching refs will be copied. + You may also specify this configuration several times. ++ +Does not have a default value; you must configure this variable to +enable note rewriting. + pack.window:: The size of the window used by linkgit:git-pack-objects[1] when no window size is given on the command line. Defaults to 10.
Documentation/git-notes.txt +4 -0
@@ -35,6 +35,10 @@ This command always manipulates the notes specified in "core.notesRef" To change which notes are shown by 'git-log', see the "notes.displayRef" configuration. +See the description of "notes.rewrite.<command>" in +linkgit:git-config[1] for a way of carrying your notes across commands +that rewrite commits. + SUBCOMMANDS -----------
Documentation/githooks.txt +4 -0
@@ -335,6 +335,10 @@ The 'extra-info' is again command-dependent. If it is empty, the preceding SP is also omitted. Currently, no commands pass any 'extra-info'. +The hook always runs after the automatic note copying (see +"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and +thus has access to these notes. + The following command-specific comments apply: rebase::
builtin.h +18 -0
@@ -20,6 +20,24 @@ extern int commit_tree(const char *msg, unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author);extern int commit_notes (struct notes_tree *t,const char *msg); + +struct notes_rewrite_cfg +{ +struct notes_tree **trees; +const char *cmd; +int enabled; +combine_notes_fn *combine; +struct string_list *refs; +int refs_from_env; +int mode_from_env; +}; + +combine_notes_fn *parse_combine_notes_fn (const char *v); +struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd); +int copy_note_for_rewrite (struct notes_rewrite_cfg *c, +const unsigned char *from_obj,const unsigned char *to_obj); +void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); +extern int check_pager_config (const char *cmd);extern int cmd_add (int argc,const char **argv,const char *prefix);
builtin/notes.c +131 -8
196 lines not on this page · raw message
cache.h +2 -0
@@ -388,6 +388,8 @@ static inline enum object_type object_type(unsigned int mode)#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"/* * Repository-local GIT_* environment variables
t/t3301-notes.sh +195 -0
199 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -56,6 +56,8 @@ unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY unset GIT_NOTES_REF unset GIT_NOTES_DISPLAY_REF +unset GIT_NOTES_REWRITE_REF +unset GIT_NOTES_REWRITE_MODE GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 9/13 rebase: support automatic notes copying
In reply to Thomas RastLuckily, all the support already happens to be there.
---
git-am.sh | 5 ++++- git-rebase--interactive.sh | 4 ++++ git-rebase.sh | 1 + t/t3400-rebase.sh | 17 +++++++++++++++++ t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletions(-)
git-am.sh +4 -1
@@ -797,8 +797,11 @@ do go_next done -if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then +if test -s "$dotest"/rewritten; then + git notes copy --for-rewrite=rebase < "$dotest"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten + fi fi rm -fr "$dotest"
git-rebase--interactive.sh +4 -0
@@ -561,6 +561,10 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + { + git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + true # we don't care if this copying failed + } && if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$REWRITTEN_LIST"; then "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
git-rebase.sh +1 -0
@@ -152,6 +152,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch + git notes copy --for-rewrite=rebase < "$dotest"/rewritten if test -x "$GIT_DIR"/hooks/post-rewrite && test -s "$dotest"/rewritten; then "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
t/t3400-rebase.sh +17 -0
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' ' git diff --exit-code file-with-cr:CR HEAD:CR ' +test_expect_success 'rebase can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +test_expect_success 'rebase -m can copy notes' ' + git reset --hard n3 && + git rebase -m --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + test_done
t/t3404-rebase-interactive.sh +24 -0
@@ -553,4 +553,28 @@ test_expect_success 'reword' ' git show HEAD~2 | grep "C changed" ' +test_expect_success 'rebase -i can copy notes' ' + git config notes.rewrite.rebase true && + git config notes.rewriteRef "refs/notes/*" && + test_commit n1 && + test_commit n2 && + test_commit n3 && + git notes add -m"a note" n3 && + git rebase --onto n1 n2 && + test "a note" = "$(git notes show HEAD)" +' + +cat >expect <<EOF +an earlier note +a note +EOF + +test_expect_success 'rebase -i can copy notes over a fixup' ' + git reset --hard n3 && + git notes add -m"an earlier note" n2 && + GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && + git notes show > output && + test_cmp expect output +' + test_done
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 10/13 commit --amend: copy notes to the new commit
In reply to Thomas RastTeaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.
---
builtin/commit.c | 6 ++++++ t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
builtin/commit.c +6 -0
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)rerere (0 );run_hook (get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) { +struct notes_rewrite_cfg *cfg; + cfg =init_copy_notes_for_rewrite ("amend" ); +if (cfg) { +copy_note_for_rewrite (cfg, head_sha1, commit_sha1); +finish_copy_notes_for_rewrite (cfg); + }run_rewrite_hook (head_sha1, commit_sha1); }if (!quiet)
t/t7501-commit.sh +12 -0
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' ' ' +test_expect_success 'amend can copy notes' ' + + git config notes.rewrite.amend true && + git config notes.rewriteRef "refs/notes/*" && + test_commit foo && + git notes add -m"a note" && + test_tick && + git commit --amend -m"new foo" && + test "$(git notes show)" = "a note" + +' + test_done
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 11/13 notes: add shorthand --ref to override GIT_NOTES_REF
In reply to Thomas RastAdds a shorthand option that overrides the GIT_NOTES_REF variable, and hence determines the notes tree that will be manipulated. It also DWIMs a refs/notes/ prefix.
---
Documentation/git-notes.txt | 5 +++++ builtin/notes.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +5 -0
@@ -116,6 +116,11 @@ OPTIONS Like '-C', but with '-c' the editor is invoked, so that the user can further edit the note message. +--ref <ref>:: + Manipulate the notes tree in <ref>. This overrides both + GIT_NOTES_REF and the "core.notesRef" configuration. The ref + is taken to be in `refs/notes/` if it is not qualified. + Author ------ Written by Johannes Schindelin <[email protected]> and
builtin/notes.c +16 -0
@@ -438,6 +438,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)int given_object =0 , i =1 , retval =0 ;struct msg_arg msg = {0 ,0 ,STRBUF_INIT };const char *rewrite_cmd =NULL ; +const char *override_notes_ref =NULL ;struct option options[] = {OPT_GROUP ("Notes contents options" ), {OPTION_CALLBACK ,'m' ,"message" , &msg,"MSG" ,
@@ -455,6 +456,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)OPT_GROUP ("Other options" ),OPT_BOOLEAN ('f' ,"force" , &force,"replace existing notes" ),OPT_BOOLEAN (0 ,"stdin" , &from_stdin,"read objects from stdin" ), +OPT_STRING (0 ,"ref" , &override_notes_ref,"notes_ref" , +"use notes from <notes_ref>" ),OPT_STRING (0 ,"for-rewrite" , &rewrite_cmd,"command" ,"load rewriting config for <command> (implies --stdin)" ),OPT_END ()
@@ -464,6 +467,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, options, git_notes_usage,0 ); +if (override_notes_ref) { +struct strbuf sb =STRBUF_INIT ; +if (!prefixcmp (override_notes_ref,"refs/notes/" )) +/* we're happy */ ; +else if (!prefixcmp (override_notes_ref,"notes/" )) +strbuf_addstr (&sb,"refs/" ); +else +strbuf_addstr (&sb,"refs/notes/" ); +strbuf_addstr (&sb, override_notes_ref); +setenv ("GIT_NOTES_REF" , sb.buf,1 ); +strbuf_release (&sb); + } +if (argc && !strcmp (argv[0 ],"list" )) list =1 ;else if (argc && !strcmp (argv[0 ],"add" ))
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 12/13 notes: track whether notes_trees were changed at all
In reply to Thomas RastCurrently, the notes copying is a bit wasteful since it always creates new trees, even if no notes were copied at all.
Teach add_note() and remove_note() to flag the affected notes tree as changed ('dirty'). Then teach builtin/notes.c to use this knowledge and avoid committing trees that weren't changed.
---
builtin/notes.c | 2 ++ notes.c | 3 +++ notes.h | 1 + 3 files changed, 6 insertions(+), 0 deletions(-)
builtin/notes.c +2 -0
@@ -240,6 +240,8 @@ int commit_notes(struct notes_tree *t, const char *msg) t = &default_notes_tree;if (!t->initialized || !t->ref || !*t->ref)die ("Cannot commit uninitialized/unreferenced notes tree" ); +if (!t->dirty) +return 0 ;/* don't have to commit an unchanged tree */ /* Prepare commit message and reflog message */ strbuf_addstr (&buf,"notes: " );/* commit message starts at index 7 */
notes.c +3 -0
@@ -933,6 +933,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, t->ref = notes_ref ?xstrdup (notes_ref) :NULL ; t->combine_notes = combine_notes; t->initialized =1 ; + t->dirty =0 ;if (flags &NOTES_INIT_EMPTY || !notes_ref ||read_ref (notes_ref, object_sha1))
@@ -1012,6 +1013,7 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,if (!t) t = &default_notes_tree;assert (t->initialized); + t->dirty =1 ;if (!combine_notes) combine_notes = t->combine_notes; l = (struct leaf_node *)xmalloc (sizeof (struct leaf_node ));
@@ -1027,6 +1029,7 @@ void remove_note(struct notes_tree *t, const unsigned char *object_sha1)if (!t) t = &default_notes_tree;assert (t->initialized); + t->dirty =1 ;hashcpy (l.key_sha1, object_sha1);hashclr (l.val_sha1);return note_tree_remove (t, t->root,0 , &l);
notes.h +1 -0
@@ -40,6 +40,7 @@char *ref;combine_notes_fn *combine_notes;int initialized; +int dirty; } default_notes_tree;/*
Signature · 1 line
1.7.0.2.417.gbc354
PATCH v7 13/13 git-notes(1): add a section about the meaning of history
In reply to Thomas RastTo the displaying code, the only interesting thing about a notes ref is that it has a tree of the required format. However, notes actually have a history since they are recorded as successive commits.
Make a note about the existence of this history in the manpage, but keep some doors open if we want to change the details.
---
Documentation/git-notes.txt | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
Documentation/git-notes.txt +14 -0
@@ -121,6 +121,20 @@ OPTIONS GIT_NOTES_REF and the "core.notesRef" configuration. The ref is taken to be in `refs/notes/` if it is not qualified. + +NOTES +----- + +Every notes change creates a new commit at the specified notes ref. +You can therefore inspect the history of the notes by invoking, e.g., +`git log -p notes/commits`. + +Currently the commit message only records which operation triggered +the update, and the commit authorship is determined according to the +usual rules (see linkgit:git-commit[1]). These details may change in +the future. + + Author ------ Written by Johannes Schindelin <[email protected]> and
Signature · 1 line
1.7.0.2.417.gbc354
Re: [PATCH v6 07/13] notes: implement 'git notes copy --stdin'
In reply to Thomas RastQuoted 5 lines · Thomas Rast
This implements a mass-copy command that takes a sequence of lines in the format
<from-sha1> SP <to-sha1> [ SP <rest> ] LF
Quoted 8 lines
on stdin, and copies each <from-sha1>'s notes to the <to-sha1>. The <rest> is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets.
The
copy_note()function is exposed for everyone's and in particular the next commit's use.Signed-off-by Thomas Rast <[email protected]>
Quoted 4 lines
---
Changes since v5
* don't remove note we know doesn't exist
[...]
Quoted 14 lines
notes.c +6
-0@@ -1189,3 +1189,22 @@ void format_display_notes(const unsigned char *object_sha1,format_note (display_notes_trees[i], object_sha1, sb, output_encoding, flags); } + +int copy_note (struct notes_tree *t, +const unsigned char *from_obj,const unsigned char *to_obj, +int force,combine_notes_fn combine_fn) +{ +const unsigned char *note =get_note (t, from_obj);
notes.c void format_display_notes(const unsigned char · line 1207
Quoted 10 lines
notes.c +10
-0+const unsigned char *existing_note =get_note (t, to_obj); + +if (!force && existing_note) +return 1 ; + +if (note) +add_note (t, to_obj, note, combine_fn); +else if (existing_note) { +add_note (t, to_obj, null_sha1, combine_fn); + }
You might want to lose the braces around the second add_note().
...Johan
Signature · 2 lines
Johan Herland, <[email protected]> www.herland.net