1#!/bin/sh 2 3CF=CREDITS-FILE 4tip= 5 6tree_search () 7{ 8head=$1 9 tree=$2 10for p in$(git rev-list --parents --max-count=1 $head 2>/dev/null) 11do 12test$tree=$(git rev-parse $p^{tree} 2>/dev/null)&& 13 vn=$(git describe --abbrev=4 $p 2>/dev/null)&& 14case"$vn"in 15 gitgui-[0-9]*)echo$p;break;; 16esac 17done 18} 19 20generate_credits () 21{ 22 tip=$1&& 23rm-f$CF&& 24 git shortlog -n -s$tip|sed's/: .*$//'>$CF||exit 25} 26 27# Always use the tarball credits file if found, just 28# in case we are somehow contained in a larger git 29# repository that doesn't actually track our state. 30# (At least one package manager is doing this.) 31# 32# We may be a subproject, so try looking for the merge 33# commit that supplied this directory content if we are 34# not at the toplevel. We probably will always be the 35# second parent in the commit, but we shouldn't rely on 36# that fact. 37# 38 39iftest -f credits 40then 41rm-f$CF&& 42cp credits $CF||exit 43elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"&& 44test -n"$prefix"&& 45head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null)&& 46 tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null)&& 47 tip=$(tree_search $head $tree)&& 48test -n"$tip" 49then 50 generate_credits $tip||exit 51elif tip="$(git rev-parse --verify HEAD 2>/dev/null)"&& 52test -n"$tip" 53then 54 generate_credits $tip||exit 55else 56echo"error: Cannot locate authorship information.">&2 57exit1 58fi