Remove post-upload-hook
This hook runs after "git fetch" in the repository the objects are fetched from as the user who fetched, and has security implications. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 10, 2009 at 12:17 UTC
1456b043fc0f0a395c35d6b5e55b0dad1b6e7acc
4 files changed
+2
-172
Documentation/git-upload-pack.txt
-2
@@ -20,8 +20,6 @@ The UI for the protocol is on the 'git-fetch-pack' side, and the
20
program pair is meant to be used to pull updates from a remote
21
repository. For push operations, see 'git-send-pack'.
22
23
-After finishing the operation successfully, `post-upload-pack`
24
-hook is called (see linkgit:githooks[5]).
23
24
OPTIONS
25
-------
Documentation/githooks.txt
-29
@@ -310,35 +310,6 @@ Both standard output and standard error output are forwarded to
310
'git-send-pack' on the other end, so you can simply `echo` messages
311
for the user.
312
313
-post-upload-pack
314
-----------------
315
-
316
-After upload-pack successfully finishes its operation, this hook is called
317
-for logging purposes.
318
-
319
-The hook is passed various pieces of information, one per line, from its
320
-standard input. Currently the following items can be fed to the hook, but
321
-more types of information may be added in the future:
322
-
323
-want SHA-1::
324
- 40-byte hexadecimal object name the client asked to include in the
325
- resulting pack. Can occur one or more times in the input.
326
-
327
-have SHA-1::
328
- 40-byte hexadecimal object name the client asked to exclude from
329
- the resulting pack, claiming to have them already. Can occur zero
330
- or more times in the input.
331
-
332
-time float::
333
- Number of seconds spent for creating the packfile.
334
-
335
-size decimal::
336
- Size of the resulting packfile in bytes.
337
-
338
-kind string:
339
- Either "clone" (when the client did not give us any "have", and asked
340
- for all our refs with "want"), or "fetch" (otherwise).
341
-
313
pre-auto-gc
314
~~~~~~~~~~~
315
t/t5501-post-upload-pack.sh
deleted
-69
@@ -1,69 +0,0 @@
1
-#!/bin/sh
2
-
3
-test_description='post upload-hook'
4
-
5
-. ./test-lib.sh
6
-
7
-LOGFILE=".git/post-upload-pack-log"
8
-
9
-test_expect_success setup '
10
- test_commit A &&
11
- test_commit B &&
12
- git reset --hard A &&
13
- test_commit C &&
14
- git branch prev B &&
15
- mkdir -p .git/hooks &&
16
- {
17
- echo "#!$SHELL_PATH" &&
18
- echo "cat >post-upload-pack-log"
19
- } >".git/hooks/post-upload-pack" &&
20
- chmod +x .git/hooks/post-upload-pack
21
-'
22
-
23
-test_expect_success initial '
24
- rm -fr sub &&
25
- git init sub &&
26
- (
27
- cd sub &&
28
- git fetch --no-tags .. prev
29
- ) &&
30
- want=$(sed -n "s/^want //p" "$LOGFILE") &&
31
- test "$want" = "$(git rev-parse --verify B)" &&
32
- ! grep "^have " "$LOGFILE" &&
33
- kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
34
- test "$kind" = fetch
35
-'
36
-
37
-test_expect_success second '
38
- rm -fr sub &&
39
- git init sub &&
40
- (
41
- cd sub &&
42
- git fetch --no-tags .. prev:refs/remotes/prev &&
43
- git fetch --no-tags .. master
44
- ) &&
45
- want=$(sed -n "s/^want //p" "$LOGFILE") &&
46
- test "$want" = "$(git rev-parse --verify C)" &&
47
- have=$(sed -n "s/^have //p" "$LOGFILE") &&
48
- test "$have" = "$(git rev-parse --verify B)" &&
49
- kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
50
- test "$kind" = fetch
51
-'
52
-
53
-test_expect_success all '
54
- rm -fr sub &&
55
- HERE=$(pwd) &&
56
- git init sub &&
57
- (
58
- cd sub &&
59
- git clone "file://$HERE/.git" new
60
- ) &&
61
- sed -n "s/^want //p" "$LOGFILE" | sort >actual &&
62
- git rev-parse A B C | sort >expect &&
63
- test_cmp expect actual &&
64
- ! grep "^have " "$LOGFILE" &&
65
- kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
66
- test "$kind" = clone
67
-'
68
-
69
-test_done
upload-pack.c
+2
-72
@@ -146,66 +146,8 @@ static int do_rev_list(int fd, void *create_full_pack)
146
return 0;
147
}
148
149
-static int feed_msg_to_hook(int fd, const char *fmt, ...)
150
-{
151
- int cnt;
152
- char buf[1024];
153
- va_list params;
154
-
155
- va_start(params, fmt);
156
- cnt = vsprintf(buf, fmt, params);
157
- va_end(params);
158
- return write_in_full(fd, buf, cnt) != cnt;
159
-}
160
-
161
-static int feed_obj_to_hook(const char *label, struct object_array *oa, int i, int fd)
162
-{
163
- return feed_msg_to_hook(fd, "%s %s\n", label,
164
- sha1_to_hex(oa->objects[i].item->sha1));
165
-}
166
-
167
-static int run_post_upload_pack_hook(size_t total, struct timeval *tv)
168
-{
169
- const char *argv[2];
170
- struct child_process proc;
171
- int err, i;
172
-
173
- argv[0] = "hooks/post-upload-pack";
174
- argv[1] = NULL;
175
-
176
- if (access(argv[0], X_OK) < 0)
177
- return 0;
178
-
179
- memset(&proc, 0, sizeof(proc));
180
- proc.argv = argv;
181
- proc.in = -1;
182
- proc.stdout_to_stderr = 1;
183
- err = start_command(&proc);
184
- if (err)
185
- return err;
186
- for (i = 0; !err && i < want_obj.nr; i++)
187
- err |= feed_obj_to_hook("want", &want_obj, i, proc.in);
188
- for (i = 0; !err && i < have_obj.nr; i++)
189
- err |= feed_obj_to_hook("have", &have_obj, i, proc.in);
190
- if (!err)
191
- err |= feed_msg_to_hook(proc.in, "time %ld.%06ld\n",
192
- (long)tv->tv_sec, (long)tv->tv_usec);
193
- if (!err)
194
- err |= feed_msg_to_hook(proc.in, "size %ld\n", (long)total);
195
- if (!err)
196
- err |= feed_msg_to_hook(proc.in, "kind %s\n",
197
- (nr_our_refs == want_obj.nr && !have_obj.nr)
198
- ? "clone" : "fetch");
199
- if (close(proc.in))
200
- err = 1;
201
- if (finish_command(&proc))
202
- err = 1;
203
- return err;
204
-}
205
-
149
static void create_pack_file(void)
150
{
208
- struct timeval start_tv, tv;
151
struct async rev_list;
152
struct child_process pack_objects;
153
int create_full_pack = (nr_our_refs == want_obj.nr && !have_obj.nr);
@@ -213,12 +155,10 @@ static void create_pack_file(void)
155
char abort_msg[] = "aborting due to possible repository "
156
"corruption on the remote side.";
157
int buffered = -1;
216
- ssize_t sz, total_sz;
158
+ ssize_t sz;
159
const char *argv[10];
160
int arg = 0;
161
220
- gettimeofday(&start_tv, NULL);
221
- total_sz = 0;
162
if (shallow_nr) {
163
rev_list.proc = do_rev_list;
164
rev_list.data = 0;
@@ -344,7 +284,7 @@ static void create_pack_file(void)
284
sz = xread(pack_objects.out, cp,
285
sizeof(data) - outsz);
286
if (0 < sz)
347
- total_sz += sz;
287
+ ;
288
else if (sz == 0) {
289
close(pack_objects.out);
290
pack_objects.out = -1;
@@ -381,16 +321,6 @@ static void create_pack_file(void)
321
}
322
if (use_sideband)
323
packet_flush(1);
384
-
385
- gettimeofday(&tv, NULL);
386
- tv.tv_sec -= start_tv.tv_sec;
387
- if (tv.tv_usec < start_tv.tv_usec) {
388
- tv.tv_sec--;
389
- tv.tv_usec += 1000000;
390
- }
391
- tv.tv_usec -= start_tv.tv_usec;
392
- if (run_post_upload_pack_hook(total_sz, &tv))
393
- warning("post-upload-hook failed");
324
return;
325
326
fail: