Update shell scripts to compute empty tree object ID
Several of our shell scripts hard-code the object ID of the empty tree. To avoid any problems when changing hashes, compute this value on startup of the script. For performance, store the value in a variable and reuse it throughout the life of the script. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 2, 2018 at 00:26 UTC
03a7f388dafaee0aa084144efe7a8f9c151e5221
3 files changed
+7
-3
git-filter-branch.sh
+3
-1
@@ -11,6 +11,8 @@
11
# The following functions will also be available in the commit filter:
12
13
functions=$(cat << \EOF
14
+EMPTY_TREE=$(git hash-object -t tree /dev/null)
15
+
16
warn () {
17
echo "$*" >&2
18
}
@@ -46,7 +48,7 @@ git_commit_non_empty_tree()
48
{
49
if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
50
map "$3"
49
- elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
51
+ elif test $# = 1 && test "$1" = $EMPTY_TREE; then
52
:
53
else
54
git commit-tree "$@"
git-rebase--interactive.sh
+3
-1
@@ -81,6 +81,8 @@ rewritten_pending="$state_dir"/rewritten-pending
81
# and leaves CR at the end instead.
82
cr=$(printf "\015")
83
84
+empty_tree=$(git hash-object -t tree /dev/null)
85
+
86
strategy_args=${strategy:+--strategy=$strategy}
87
test -n "$strategy_opts" &&
88
eval '
@@ -238,7 +240,7 @@ is_empty_commit() {
240
die "$(eval_gettext "\$sha1: not a commit that can be picked")"
241
}
242
ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) ||
241
- ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
243
+ ptree=$empty_tree
244
test "$tree" = "$ptree"
245
}
246
templates/hooks--pre-commit.sample
+1
-1
@@ -12,7 +12,7 @@ then
12
against=HEAD
13
else
14
# Initial commit: diff against an empty tree object
15
- against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
15
+ against=$(git hash-object -t tree /dev/null)
16
fi
17
18
# If you want to allow non-ASCII filenames set this variable to true.