blob: 76e51b67169d7b84e84eb6edda573860f7f3d9b0 (
plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#!/bin/sh
set -e
fail () { echo >&2 "$0: $*"; exit 1; }
play=.git/tartree-edit-work
git_manip_play () {
local wd=$(pwd)
case "$wd" in
*.edit) fail "bad idea to run gitfetchinfo into a .edit tree!" ;;
esac
rm -rf $play
mkdir $play
}
gitfetchdiff_list () {
git for-each-ref --format '%(refname) %(objectname)' \
refs/remotes/"$1" \
| sed 's/^refs\/remotes\/[^\/]*\///' \
| sort >"$play/$2"
}
gitfetchdiff () {
local how="$1"
local a="$2"
local b="$3"
git_manip_play
rrab=refs/remotes/"$a+$b"
ulf=\
"delete refs/remotes/$a/%l
delete refs/remotes/$b/%l
"
case "$how" in
diff)
git for-each-ref --format 'delete %(refname)' $rrab \
| git update-ref --stdin
;;
merge)
ulf=\
"create $rrab/%l
$ulf"
;;
*)
fail "internal error bad how ($how)"
;;
esac
gitfetchdiff_list "$a" a
gitfetchdiff_list "$b" b
diff --old-line-format='' --new-line-format='' \
--unchanged-line-format="$ulf" \
$play/a $play/b >$play/updates \
|| test $? = 1
git update-ref --stdin <$play/updates
exit 0
}
case "$#.$1" in
2.edit|2.done) mode="$1"; arg="$2" ;;
3.gitfetchinfo) mode="$1"; arg="$2"; remote="$3" ;;
3.gitfetchinfo-diff) gitfetchdiff diff "$2" "$3" ;;
3.gitfetchinfo-merge) gitfetchdiff merge "$2" "$3" ;;
?.-*) fail "no options understood" ;;
*) fail "usage:
tartree-edit edit|done DIRECTORY|TARBALL
tartree-edit gitfetchinfo DIRECTORY|TARBALL REMOTE" ;;
esac
case "$arg" in
*.tar) base=${arg%.tar} ;;
*.edit) base=${arg%.edit} ;;
*) base=${arg} ;;
esac
tryat_pre () {
local b="$1"
rm -rf "$b.tmp"
if test -f "$b.tar" && test -f "$b.edit"; then
echo "$b.edit exists, deleting possibly-obsolete $b.tar"
rm "$b.tar"
fi
}
tryat_edit () {
local b="$1"
if test -d "$b.edit"; then
echo "$b.edit already exists"
exit 0
fi
if test -f "$b.tar"; then
mkdir "$b.tmp"
(set -e; cd "$b.tmp"; tar xf "$b.tar")
mv "$b.tmp" "$b.edit"
rm "$b.tar"
echo "$b.edit ready"
exit 0
fi
}
gitfetchinfo_perhaps_commit () {
local m="$1"
set +e
git diff --cached --quiet --exit-code HEAD
local rc=$?
set -e
case "$rc" in
0) return ;;
1) git commit --allow-empty --author='tartree-edit <>' -m "$m" ;;
*) fail "git diff failed ($rc)" ;;
esac
}
tryat_gitfetchinfo () {
git_manip_play
if test -d "$b.edit"; then
cp -a "$b.edit"/. "$play"/.
else
exec 3<"$b.tar"
tar -C $play -f - <&3 -x
exec 3<&-
fi
local innerwd=$play/*
git remote remove "$remote" 2>/dev/null ||:
git remote add "$remote" $innerwd
git fetch --no-tags -p "$remote" \
+"HEAD:refs/remotes/$remote/HEAD"
cd $innerwd
git checkout -b WORKTREE
gitfetchinfo_perhaps_commit INDEX
git add -Af .
gitfetchinfo_perhaps_commit WORKTREE
cd ../../..
git fetch --no-tags "$remote" --refmap \
+"refs/*:refs/remotes/$remote/*" \
+"refs/*:refs/remotes/$remote/*"
exit 0
}
tryat_done () {
local b="$1"
if test -d "$b.edit"; then
(set -e; cd "$b.edit"; tar cf "$b.tmp" *)
mv "$b.tmp" "$b.tar"
mv "$b.edit" "$b.tmp"
rm -rf "$b.tmp"
echo "$b.tar regenerated"
exit 0
fi
if test -f "$b.tar"; then
echo "$b.tar already exists and $b.edit doesn't"
exit 0
fi
}
tryat () {
local b="$1"
if ! test -f "$b.tar" && ! test -d "$b.edit"; then
return
fi
tryat_pre "$b"
tryat_$mode "$b"
fail "unexpected situation in $b.*"
}
case "$arg" in
/*) tryat "$base"
;;
*)
pwd=`pwd`
tryat "$pwd/$base"
tryat "$pwd/git-srcs/$base"
tryat "$pwd/tests/git-srcs/$base"
fail "could not find $base..."
;;
esac
|