plan9fox/sys/lib/git/common.rc
Ori Bernstein d9564c0642 git: separate author and committer
Git has the ability to track the person who
creates a commit separately from the person
who wrote the commit. For git9, we ignored
this feature.

However, as we start using git/import more,
it will be useful to figure out who imported
a commit, as well as who wrote it.

This change adds support for seeing this
information in git, as well as setting the
author and committer separately in git/import.
2021-09-03 02:47:18 +00:00

110 lines
1.7 KiB
Plaintext

nl='
'
fn die{
>[1=2] echo $0: $*
exit $"*
}
fn usage{
>[1=2] echo -n 'usage:' $usage
exit 'usage'
}
fn subst {
awk '
BEGIN{ARGC=0}
{sub(ARGV[1], ARGV[2]); print}
' $*
}
fn drop {
awk '
BEGIN{ARGC=0}
{
if(index($0, ARGV[1]) == 1)
$0=substr($0, length(ARGV[1])+1)
print
}
' $*
}
fn present {
if(~ $1 /dev/null && cmp $2 $3>/dev/null)
status=gone
if not if (~ $3 /dev/null && cmp $1 $2>/dev/null)
status=gone
if not
status=()
}
fn whoami{
name=`$nl{git/conf user.name}
email=`$nl{git/conf user.email}
if(test -f /adm/keys.who){
if(~ $name '')
name=`$nl{awk -F'|' '$1=="'$user'" {x=$3} END{print x}' </adm/keys.who}
if(~ $email '')
email=`$nl{awk -F'|' '$1=="'$user'" {x=$5} END{print x}' </adm/keys.who}
}
if(~ $name '')
name=glenda
if(~ $email '')
email=glenda@9front.local
}
# merge1 out ours base theirs
fn merge1 {@{
rfork e
n=$pid
out=$1
ours=$2
base=$3
theirs=$4
tmp=$out.tmp
while(test -f $tmp){
tmp=$tmp.$n
n=`{echo $n + 1 | hoc}
}
if(! test -f $ours)
ours=/dev/null
if(! test -f $base)
base=/dev/null
if(! test -f $theirs)
theirs=/dev/null
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]
if(present $ours $base $theirs){
mv $tmp $out
git/add $out
}
if not {
rm -f $tmp $out
git/rm $out
}
}}
fn gitup{
gitroot=`{git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitfs=$gitroot/.git/fs
gitrel=`{pwd | drop $gitroot | sed 's@^/@@'}
if(~ $#gitrel 0)
gitrel='.'
cd $gitroot
startfs=()
if(! test -d $gitfs)
mkdir -p $gitfs
if(! test -e $gitfs/ctl)
startfs=true
if(! grep -s '^repo '$gitroot'$' $gitfs/ctl >[2]/dev/null)
startfs=true
if(~ $#startfs 1)
git/fs
if not
status=''
}