@matheusbsbs / matheus-bagliano / commits / 92446aba47
Fork 0

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 <junkio@cox.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Junio C Hamano committed Feb 25, 2007 at 02:18 UTC 92446aba47b0e0db28f7b858ea387efcca30ab44
1 file changed +19 -6
CREDITS-GEN
+19 -6
@@ -20,8 +20,8 @@ tree_search ()
20 generate_credits ()
21 {
22 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
25 }
26
27 # Always use the tarball credits file if found, just
@@ -36,10 +36,14 @@ generate_credits ()
36 # that fact.
37 #
38
39 +credits_tmp=/var/tmp/gitgui-credits-$$
40 +trap 'rm -f "$credits_tmp"' 0
41 +
42 +orig="$credits_tmp"
43 +
44 if test -f credits
45 then
41 - rm -f $CF &&
42 - cp credits $CF || exit
46 + orig=credits
47 elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" &&
48 test -n "$prefix" &&
49 head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
@@ -47,12 +51,21 @@ elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" &&
51 tip=$(tree_search $head $tree) &&
52 test -n "$tip"
53 then
50 - generate_credits $tip || exit
54 + generate_credits $tip "$orig" || exit
55 elif tip="$(git rev-parse --verify HEAD 2>/dev/null)" &&
56 test -n "$tip"
57 then
54 - generate_credits $tip || exit
58 + generate_credits $tip "$orig" || exit
59 else
60 echo "error: Cannot locate authorship information." >&2
61 exit 1
62 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 +