[PATCH 1/2] Minor cleanup and bugfixing in git-notes.sh
The following changes are made:
- Rename $MESSAGE to $MSG_FILE which better describes its purpose
- Make sure not only $MSG_FILE is removed upopn completion, but also
$GIT_INDEX_FILE
- Remove stray "GIT_NOTES_REF=" in front of "git log ..." command
Signed-off-by: Johan Herland <johan@herland.net>
---
git-notes.sh | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/git-notes.sh b/git-notes.sh
index 6ec33c9..7c3b8b9 100755
--- a/git-notes.sh
+++ b/git-notes.sh
@@ -20,15 +20,16 @@ edit)
die "Refusing to edit notes in $GIT_NOTES_REF (outside of refs/notes/)"
fi
- MESSAGE="$GIT_DIR"/new-notes-$COMMIT
+ MSG_FILE="$GIT_DIR/new-notes-$COMMIT"
+ GIT_INDEX_FILE="MSG_FILE.idx"
+ export GIT_INDEX_FILE
+
trap '
- test -f "$MESSAGE" && rm "$MESSAGE"
+ test -f "$MSG_FILE" && rm "$MSG_FILE"
+ test -f "$GIT_INDEX_FILE" && rm "$GIT_INDEX_FILE"
' 0
- GIT_NOTES_REF= git log -1 $COMMIT | sed "s/^/#/" > "$MESSAGE"
-
- GIT_INDEX_FILE="$MESSAGE".idx
- export GIT_INDEX_FILE
+ git log -1 $COMMIT | sed "s/^/#/" > "$MSG_FILE"
CURRENT_HEAD=$(git show-ref "$GIT_NOTES_REF" | cut -f 1 -d ' ')
if [ -z "$CURRENT_HEAD" ]; then
@@ -36,16 +37,16 @@ edit)
else
PARENT="-p $CURRENT_HEAD"
git read-tree "$GIT_NOTES_REF" || die "Could not read index"
- git cat-file blob :$COMMIT >> "$MESSAGE" 2> /dev/null
+ git cat-file blob :$COMMIT >> "$MSG_FILE" 2> /dev/null
fi
core_editor="$(git config core.editor)"
- ${GIT_EDITOR:-${core_editor:-${VISUAL:-${EDITOR:-vi}}}} "$MESSAGE"
+ ${GIT_EDITOR:-${core_editor:-${VISUAL:-${EDITOR:-vi}}}} "$MSG_FILE"
- grep -v ^# < "$MESSAGE" | git stripspace > "$MESSAGE".processed
- mv "$MESSAGE".processed "$MESSAGE"
- if [ -s "$MESSAGE" ]; then
- BLOB=$(git hash-object -w "$MESSAGE") ||
+ grep -v ^# < "$MSG_FILE" | git stripspace > "$MSG_FILE".processed
+ mv "$MSG_FILE".processed "$MSG_FILE"
+ if [ -s "$MSG_FILE" ]; then
+ BLOB=$(git hash-object -w "$MSG_FILE") ||
die "Could not write into object database"
git update-index --add --cacheinfo 0644 $BLOB $COMMIT ||
die "Could not write index"
--
1.6.3.rc0.1.gf800