-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.rc
127 lines (117 loc) · 2.1 KB
/
common.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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 mergeperm {
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 {
mergedperms='-x'
if(test -x $2){
if(test -x $1 -a -x $3)
mergedperms='+x'
}
if not{
if(test -x $1 -o -x $3)
mergedperms='+x'
}
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=$user
if(~ $email '')
email=$user@$sysname
status=''
}
# 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(mergeperm $ours $base $theirs){
mkdir -p `{basename -d $tmp}
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]
mv $tmp $out
git/add $out
chmod $mergedperms $out
}
if not {
rm -f $tmp $out
git/rm $out
}
}}
fn gitup{
gitroot=`$nl{git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitwork=`$nl{git/conf work.dir}
if(~ $#gitwork 1)
bind -c $gitwork/objects $gitroot/.git/objects
if(~ $#workdir 1)
bind $workdir .git/objects
gitfs=$gitroot/.git/fs
gitrel=`{pwd | drop $gitroot | sed 's@^/@@'}
if(~ $#gitrel 0)
gitrel='.'
if(! cd $gitroot)
die cd $gitroot: no repo there
startfs=()
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=''
}