From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Alberto Bertogli <albertito@gmail.com>,
git@vger.kernel.org, gitster@pobox.com,
Johan Herland <johan@herland.net>
Subject: Re: [PATCH 3/6] Add git-notes
Date: Sun, 15 Jul 2007 22:11:28 -0700 [thread overview]
Message-ID: <7v8x9h6igv.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: Pine.LNX.4.64.0707160023360.14781@racer.site
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> This script allows you to edit and show commit notes easily.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> .gitignore | 1 +
> Makefile | 2 +-
> git-notes.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 63 insertions(+), 1 deletions(-)
> create mode 100755 git-notes.sh
>
> diff --git a/git-notes.sh b/git-notes.sh
> new file mode 100755
> index 0000000..e0ad0b9
> --- /dev/null
> +++ b/git-notes.sh
> @@ -0,0 +1,61 @@
> +#!/bin/sh
> +
> +USAGE="(edit | show) [commit]"
> +. git-sh-setup
> +
> +test -n "$3" && usage
> +
> +test -z "$GIT_NOTES_REF" && GIT_NOTES_REF="$(git config core.notesref)"
> +test -z "$GIT_NOTES_REF" &&
> + die "No notes ref set."
test -n "${GIT_NOTES_REF=$(git config core.notesref)}" || die
> +COMMIT=$(git rev-parse --verify --default HEAD "$2")
This silently annotates the HEAD commit if $2 is misspelled, I
suspect. Also if HEAD does not exist, COMMIT will be empty and
this whole command will exit with non-zero status, which you
would want to catch here...
> +NAME=$(echo $COMMIT | sed "s/^../&\//")
... or here.
> +case "$1" in
> +edit)
> + MESSAGE="$GIT_DIR"/new-notes
> + GIT_NOTES_REF= git log -1 $COMMIT | sed "s/^/#/" > "$MESSAGE"
$MESSAGE and its associated temporary file needs to be cleaned
up upon command exit; perhaps a trap is in order.
> + GIT_INDEX_FILE="$MESSAGE".idx
> + export GIT_INDEX_FILE
> +
> + CURRENT_HEAD=$(git show-ref $GIT_NOTES_REF | cut -f 1 -d ' ')
> + if [ -z "$CURRENT_HEAD" ]; then
> + PARENT=
> + else
> + PARENT="-p $OLDTIP"
> + git read-tree $GIT_NOTES_REF || die "Could not read index"
> + git cat-file blob :$NAME >> "$MESSAGE" 2> /dev/null
> + fi
I take that OLDTIP is a typo.
if CURRENT_HEAD=$(git show-ref -s "$GIT_NOTES_REF")
then
PARENT="-p $CURRENT_HEAD"
...
else
PARENT=
fi
> +
> + ${VISUAL:-${EDITOR:-vi}} "$MESSAGE"
> +
> + grep -v ^# < "$MESSAGE" | git stripspace > "$MESSAGE".processed
Makes us wonder if we would want to teach hash-stripping to
git-stripspace, doesn't it?
> + mv "$MESSAGE".processed "$MESSAGE"
> + if [ -z "$(cat "$MESSAGE")" ]; then
Make this 'if test -s "$MESSAGE"' and swap then/else clause
around; no reason to slurp the value into your shell.
> + test -z "$CURRENT_HEAD" &&
> + die "Will not initialise with empty tree"
> + git update-index --force-remove $NAME ||
> + die "Could not update index"
> + else
> + BLOB=$(git hash-object -w "$MESSAGE") ||
> + die "Could not write into object database"
> + git update-index --add --cacheinfo 0644 $BLOB $NAME ||
> + die "Could not write index"
> + fi
> +
> + TREE=$(git write-tree) || die "Could not write tree"
> + NEW_HEAD=$(: | git commit-tree $TREE $PARENT) ||
> + die "Could not annotate"
Hmph. How about "echo Annotate $COMMIT | git commit-tree..."?
> + case "$CURRENT_HEAD" in
> + '') git update-ref $GIT_NOTES_REF $NEW_HEAD ;;
> + *) git update-ref $GIT_NOTES_REF $NEW_HEAD $CURRENT_HEAD;;
> + esac
> +;;
There are some places that have "$GIT_NOTES_REF" in dq and some
places you don't. I think GIT_NOTES_REF begins with refs/ and
consists only of valid refname characters, so unless the user
wants to shoot himself in the foot it should be Ok, but we
probably would want to quote it.
Also, as unquoted $CURRENT_HEAD will not even count as a
parameter to update-ref, you do not have to do that case/esac,
but simply do:
git update-ref "$GIT_NOTES_REF" $NEW_HEAD $CURRENT_HEAD
Would we have reflog for this ref? What would we want to see as
the message if we do?
next prev parent reply other threads:[~2007-07-16 5:11 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-15 23:19 [PATCH 0/6] Introduce commit notes Johannes Schindelin
2007-07-15 23:22 ` [PATCH 1/6] Rename git_one_line() to git_line_length() and export it Johannes Schindelin
2007-07-15 23:23 ` [PATCH 2/6] Introduce commit notes Johannes Schindelin
2007-07-15 23:36 ` Junio C Hamano
2007-07-15 23:52 ` Johannes Schindelin
2007-07-16 0:05 ` Junio C Hamano
2007-07-16 5:11 ` Junio C Hamano
2007-07-19 2:30 ` [REVISED PATCH " Johannes Schindelin
2007-07-19 3:28 ` Linus Torvalds
2007-07-19 5:13 ` Junio C Hamano
2007-07-19 9:34 ` Junio C Hamano
2007-07-19 9:57 ` Adam Hayek
2007-07-19 10:58 ` Andy Parkins
2007-07-19 11:10 ` Johannes Schindelin
2007-07-19 14:33 ` Andy Parkins
2007-07-19 17:42 ` Linus Torvalds
2007-07-20 0:20 ` Junio C Hamano
2007-07-20 4:59 ` Shawn O. Pearce
2007-07-19 17:20 ` Linus Torvalds
2007-07-19 9:50 ` Johannes Schindelin
2007-07-19 10:34 ` Olivier Galibert
2007-07-19 17:50 ` Linus Torvalds
2007-07-19 9:05 ` Wincent Colaiuta
2007-07-19 9:24 ` Johannes Schindelin
2007-07-19 9:54 ` Sven Verdoolaege
2007-07-15 23:23 ` [PATCH 3/6] Add git-notes Johannes Schindelin
2007-07-16 5:11 ` Junio C Hamano [this message]
2007-07-19 2:31 ` [REVISED PATCH " Johannes Schindelin
2007-07-19 2:54 ` Johannes Schindelin
2007-07-15 23:24 ` [PATCH 4/6] Add a test script for "git notes" Johannes Schindelin
2007-07-16 5:11 ` Junio C Hamano
2007-07-19 2:32 ` [REVISED PATCH " Johannes Schindelin
2007-07-15 23:24 ` [PATCH 5/6] Document git-notes Johannes Schindelin
2007-07-15 23:26 ` [WIP PATCH 6/6] notes: add notes-index for a substantial speedup Johannes Schindelin
2007-07-15 23:33 ` Johannes Schindelin
2007-07-16 6:01 ` Shawn O. Pearce
2007-07-16 16:29 ` Johannes Schindelin
2007-07-16 7:57 ` [PATCH 0/6] Introduce commit notes Andy Parkins
2007-07-16 8:11 ` Junio C Hamano
2007-07-16 16:26 ` Johannes Schindelin
2007-07-16 17:56 ` Junio C Hamano
2007-07-19 1:34 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v8x9h6igv.fsf@assigned-by-dhcp.cox.net \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=albertito@gmail.com \
--cc=git@vger.kernel.org \
--cc=johan@herland.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.