Skip to content

Commit 03a7f38

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1ccd7e commit 03a7f38

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

git-filter-branch.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# The following functions will also be available in the commit filter:
1212

1313
functions=$(cat << \EOF
14+
EMPTY_TREE=$(git hash-object -t tree /dev/null)
15+
1416
warn () {
1517
echo "$*" >&2
1618
}
@@ -46,7 +48,7 @@ git_commit_non_empty_tree()
4648
{
4749
if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
4850
map "$3"
49-
elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
51+
elif test $# = 1 && test "$1" = $EMPTY_TREE; then
5052
:
5153
else
5254
git commit-tree "$@"

git-rebase--interactive.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ rewritten_pending="$state_dir"/rewritten-pending
8181
# and leaves CR at the end instead.
8282
cr=$(printf "\015")
8383

84+
empty_tree=$(git hash-object -t tree /dev/null)
85+
8486
strategy_args=${strategy:+--strategy=$strategy}
8587
test -n "$strategy_opts" &&
8688
eval '
@@ -238,7 +240,7 @@ is_empty_commit() {
238240
die "$(eval_gettext "\$sha1: not a commit that can be picked")"
239241
}
240242
ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) ||
241-
ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
243+
ptree=$empty_tree
242244
test "$tree" = "$ptree"
243245
}
244246

templates/hooks--pre-commit.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ then
1212
against=HEAD
1313
else
1414
# Initial commit: diff against an empty tree object
15-
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
15+
against=$(git hash-object -t tree /dev/null)
1616
fi
1717

1818
# If you want to allow non-ASCII filenames set this variable to true.

0 commit comments

Comments
 (0)