Skip to content

Commit 92446ab

Browse files
Junio C Hamanospearce
authored andcommitted
Don't modify CREDITS-FILE if it hasn't changed.
We should always avoid rewriting a built file during `make install` if nothing has changed since `make all`. This is to help support the typical installation process of compiling a package as yourself, then installing it as root. Forcing CREDITS-FILE to be always be rebuilt in the Makefile means that CREDITS-GEN needs to check for a change and only update CREDITS-FILE if the file content actually differs. After all, content is king in Git. Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 9811937 commit 92446ab

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

CREDITS-GEN

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ tree_search ()
2020
generate_credits ()
2121
{
2222
tip=$1 &&
23-
rm -f $CF &&
24-
git shortlog -n -s $tip | sed 's/: .*$//' >$CF || exit
23+
rm -f "$2" &&
24+
git shortlog -n -s $tip | sed 's/: .*$//' >"$2" || exit
2525
}
2626

2727
# Always use the tarball credits file if found, just
@@ -36,23 +36,36 @@ generate_credits ()
3636
# that fact.
3737
#
3838

39+
credits_tmp=/var/tmp/gitgui-credits-$$
40+
trap 'rm -f "$credits_tmp"' 0
41+
42+
orig="$credits_tmp"
43+
3944
if test -f credits
4045
then
41-
rm -f $CF &&
42-
cp credits $CF || exit
46+
orig=credits
4347
elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" &&
4448
test -n "$prefix" &&
4549
head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
4650
tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
4751
tip=$(tree_search $head $tree) &&
4852
test -n "$tip"
4953
then
50-
generate_credits $tip || exit
54+
generate_credits $tip "$orig" || exit
5155
elif tip="$(git rev-parse --verify HEAD 2>/dev/null)" &&
5256
test -n "$tip"
5357
then
54-
generate_credits $tip || exit
58+
generate_credits $tip "$orig" || exit
5559
else
5660
echo "error: Cannot locate authorship information." >&2
5761
exit 1
5862
fi
63+
64+
if test -f "$orig" && cmp -s "$orig" "$CF"
65+
then
66+
: noop
67+
else
68+
rm -f "$CF" &&
69+
cat "$orig" >"$CF"
70+
fi
71+

0 commit comments

Comments
 (0)