summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a7928f8)
raw | patch | inline | side by side (parent: a7928f8)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 28 Sep 2005 01:14:27 +0000 (18:14 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 28 Sep 2005 23:42:44 +0000 (16:42 -0700) |
This uses the git-update-ref command in scripts for safer updates.
Also places where we used to read HEAD ref by using "cat" were fixed
to use git-rev-parse. This will matter when we start using symbolic
references.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Also places where we used to read HEAD ref by using "cat" were fixed
to use git-rev-parse. This will matter when we start using symbolic
references.
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-applypatch.sh | patch | blob | history | |
git-commit.sh | patch | blob | history | |
git-fetch.sh | patch | blob | history | |
git-merge.sh | patch | blob | history | |
git-octopus.sh | patch | blob | history | |
git-pull.sh | patch | blob | history | |
git-rebase.sh | patch | blob | history | |
git-reset.sh | patch | blob | history | |
git-resolve.sh | patch | blob | history |
diff --git a/git-applypatch.sh b/git-applypatch.sh
index fd594ed4e48a1aee7f4e9c0a6bbb3a44f1bb2120..9f5a45bb2bbb330207ea4410a76f5521bdc7b850 100755 (executable)
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
tree=$(git-write-tree) || exit 1
echo Wrote tree $tree
-commit=$(git-commit-tree $tree -p $(cat "$GIT_DIR"/HEAD) < "$final") || exit 1
+parent=$(git-rev-parse --verify HEAD) &&
+commit=$(git-commit-tree $tree -p $parent <"$final") || exit 1
echo Committed: $commit
-echo $commit > "$GIT_DIR"/HEAD
+git-update-ref HEAD $commit $parent || exit
if test -x "$GIT_DIR"/hooks/post-applypatch
then
diff --git a/git-commit.sh b/git-commit.sh
index 18ad36158dad5a2fc542cb9c1daf65b32ba5b4a3..18b259c7086224f70cfd69798dc6332df040a61d 100755 (executable)
--- a/git-commit.sh
+++ b/git-commit.sh
exit 1
fi
PARENTS=""
+ current=
else
+ current=$(git-rev-parse --verify HEAD)
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
fi
then
tree=$(git-write-tree) &&
commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
- echo $commit > "$GIT_DIR/HEAD" &&
+ git-update-ref HEAD $commit $current &&
rm -f -- "$GIT_DIR/MERGE_HEAD"
else
echo >&2 "* no commit message? aborting commit."
diff --git a/git-fetch.sh b/git-fetch.sh
index 82d897231a488d91d5408c7710dd481cf862171d..27407c1d357d8bf9d621875b1a773cef671ddc3d 100755 (executable)
--- a/git-fetch.sh
+++ b/git-fetch.sh
else
echo >&2 "* $1: storing $3"
fi
- echo "$2" >"$GIT_DIR/$1" ;;
+ git-update-ref "$1" "$2"
+ ;;
refs/heads/*)
- # NEEDSWORK: use the same cmpxchg protocol here.
- echo "$2" >"$GIT_DIR/$1.lock"
- if test -f "$GIT_DIR/$1"
+ # $1 is the ref being updated.
+ # $2 is the new value for the ref.
+ local=$(git-rev-parse --verify "$1^0" 2>/dev/null)
+ if test "$local"
then
- local=$(git-rev-parse --verify "$1^0") &&
+ # Require fast-forward.
mb=$(git-merge-base "$local" "$2") &&
case "$2,$mb" in
$local,*)
;;
*,$local)
echo >&2 "* $1: fast forward to $3"
+ git-update-ref "$1" "$2" "$local"
;;
*)
false
;;
esac || {
echo >&2 "* $1: does not fast forward to $3;"
- case "$force,$single_force" in
- t,* | *,t)
+ case ",$force,$single_force," in
+ *,t,*)
echo >&2 " forcing update."
+ git-update-ref "$1" "$2" "$local"
;;
*)
- mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
- echo >&2 " leaving it in '$1.remote'"
+ echo >&2 " not updating."
;;
esac
}
else
- echo >&2 "* $1: storing $3"
+ echo >&2 "* $1: storing $3"
+ git-update-ref "$1" "$2"
fi
- test -f "$GIT_DIR/$1.lock" &&
- mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
;;
esac
}
case "$update_head_ok" in
'')
- orig_head=$(cat "$GIT_DIR/HEAD" 2>/dev/null)
+ orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
;;
esac
rsync://*)
TMP_HEAD="$GIT_DIR/TMP_HEAD"
rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
- head=$(git-rev-parse TMP_HEAD)
+ head=$(git-rev-parse --verify TMP_HEAD)
rm -f "$TMP_HEAD"
test "$rsync_slurped_objects" || {
rsync -av --ignore-existing --exclude info \
*,, | t,* )
;;
*)
- curr_head=$(cat "$GIT_DIR/HEAD" 2>/dev/null)
+ curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
if test "$curr_head" != "$orig_head"
then
- echo "$orig_head" >$GIT_DIR/HEAD
+ git-update-ref HEAD "$orig_head"
die "Cannot fetch into the current branch."
fi
;;
diff --git a/git-merge.sh b/git-merge.sh
index 5890c7b1c038b280e15d95c74700013152ea8959..29e86c695320b3d575314bc7c0be9eea0fd1b04a 100755 (executable)
--- a/git-merge.sh
+++ b/git-merge.sh
# Again the most common case of merging one remote.
echo "Updating from $head to $1."
git-update-index --refresh 2>/dev/null
- git-read-tree -u -m $head "$1" || exit 1
- git-rev-parse --verify "$1^0" > "$GIT_DIR/HEAD"
+ git-read-tree -u -m $head "$1" &&
+ new_head=$(git-rev-parse --verify "$1^0") &&
+ git-update-ref HEAD "$new_head" "$head" || exit 1
summary "$1"
dropsave
exit 0
do
parents="$parents -p $remote"
done
- result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents)
+ result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
echo "Committed merge $result_commit, made by $wt_strategy."
- echo $result_commit >"$GIT_DIR/HEAD"
+ git-update-ref HEAD $result_commit $head
summary $result_commit
dropsave
exit 0
diff --git a/git-octopus.sh b/git-octopus.sh
index abc682025e5316e7d8612e5aa2057a700f618481..d2471af3c8a002c175bf9b1370039b9e7d4ab946 100755 (executable)
--- a/git-octopus.sh
+++ b/git-octopus.sh
result_commit=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD" |
git-commit-tree $MRT $PARENT)
echo "Committed merge $result_commit"
-echo $result_commit >"$GIT_DIR"/HEAD
+git-update-ref HEAD $result_commit $head
git-diff-tree -p $head $result_commit | git-apply --stat
diff --git a/git-pull.sh b/git-pull.sh
index 67c7f9562b54acd08b67c840f508bd20f0879947..1f4a05d09eed7a7ae6be9ce4dcdd92f4e0d75131 100755 (executable)
--- a/git-pull.sh
+++ b/git-pull.sh
. git-sh-setup || die "Not a git archive"
-orig_head=$(cat "$GIT_DIR/HEAD") || die "Pulling into a black hole?"
+orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
git-fetch --update-head-ok "$@" || exit 1
-curr_head=$(cat "$GIT_DIR/HEAD")
+curr_head=$(git-rev-parse --verify HEAD)
if test "$curr_head" != "$orig_head"
then
# The fetch involved updating the current branch.
esac
merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
-git-resolve "$(cat "$GIT_DIR"/HEAD)" $merge_head "$merge_name"
+git-resolve "$curr_head" $merge_head "$merge_name"
diff --git a/git-rebase.sh b/git-rebase.sh
index 49c8f12e51153f5c7ecbdc5a1778c24ba28f428f..fa95009091525eb9ea65bce1e08f293dfd1eddca 100755 (executable)
--- a/git-rebase.sh
+++ b/git-rebase.sh
die "Your working tree does not match $ours_symbolic."
git-read-tree -m -u $ours $upstream &&
-git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit
+new_head=$(git-rev-parse --verify "$upstream^0") &&
+git-update-ref HEAD "$new_head" || exit
tmp=.rebase-tmp$$
fail=$tmp-fail
continue ;;
esac
echo >&2 "* Applying: $msg"
- S=`cat "$GIT_DIR/HEAD"` &&
+ S=$(git-rev-parse --verify HEAD) &&
git-cherry-pick --replay $commit || {
echo >&2 "* Not applying the patch and continuing."
echo $commit >>$fail
diff --git a/git-reset.sh b/git-reset.sh
index dfa9cb8bb17f6f8694d0c639fe8b1663f9ec3c8f..f9995cadf563a7b3b2c1dcdeea3bf862feac2e4b 100755 (executable)
--- a/git-reset.sh
+++ b/git-reset.sh
else
rm -f "$GIT_DIR/ORIG_HEAD"
fi
-echo "$rev" >"$GIT_DIR/HEAD"
+git-update-ref HEAD "$rev"
case "$reset_type" in
--hard )
diff --git a/git-resolve.sh b/git-resolve.sh
index 1f559d8cb91bf88e7ddc0abad55db7ad4550aeef..7d8fb54f952e3f85c8c77b8fd9c67afbe76f0316 100755 (executable)
--- a/git-resolve.sh
+++ b/git-resolve.sh
"$head")
echo "Updating from $head to $merge."
git-read-tree -u -m $head $merge || exit 1
- echo $merge > "$GIT_DIR"/HEAD
+ git-update-ref HEAD "$merge" "$head"
git-diff-tree -p $head $merge | git-apply --stat
dropheads
exit 0
fi
result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
echo "Committed merge $result_commit"
-echo $result_commit > "$GIT_DIR"/HEAD
+git-update-ref HEAD "$result_commit" "$head"
git-diff-tree -p $head $result_commit | git-apply --stat
dropheads