Skip to content

Commit

Permalink
Remove post-upload-hook
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Dec 10, 2009
1 parent 5c30b8f commit 1456b04
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 172 deletions.
2 changes: 0 additions & 2 deletions Documentation/git-upload-pack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ The UI for the protocol is on the 'git-fetch-pack' side, and the
program pair is meant to be used to pull updates from a remote
repository. For push operations, see 'git-send-pack'.

After finishing the operation successfully, `post-upload-pack`
hook is called (see linkgit:githooks[5]).

OPTIONS
-------
Expand Down
29 changes: 0 additions & 29 deletions Documentation/githooks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,35 +310,6 @@ Both standard output and standard error output are forwarded to
'git-send-pack' on the other end, so you can simply `echo` messages
for the user.

post-upload-pack
----------------

After upload-pack successfully finishes its operation, this hook is called
for logging purposes.

The hook is passed various pieces of information, one per line, from its
standard input. Currently the following items can be fed to the hook, but
more types of information may be added in the future:

want SHA-1::
40-byte hexadecimal object name the client asked to include in the
resulting pack. Can occur one or more times in the input.

have SHA-1::
40-byte hexadecimal object name the client asked to exclude from
the resulting pack, claiming to have them already. Can occur zero
or more times in the input.

time float::
Number of seconds spent for creating the packfile.

size decimal::
Size of the resulting packfile in bytes.

kind string:
Either "clone" (when the client did not give us any "have", and asked
for all our refs with "want"), or "fetch" (otherwise).

pre-auto-gc
~~~~~~~~~~~

Expand Down
69 changes: 0 additions & 69 deletions t/t5501-post-upload-pack.sh

This file was deleted.

74 changes: 2 additions & 72 deletions upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,79 +146,19 @@ static int do_rev_list(int fd, void *create_full_pack)
return 0;
}

static int feed_msg_to_hook(int fd, const char *fmt, ...)
{
int cnt;
char buf[1024];
va_list params;

va_start(params, fmt);
cnt = vsprintf(buf, fmt, params);
va_end(params);
return write_in_full(fd, buf, cnt) != cnt;
}

static int feed_obj_to_hook(const char *label, struct object_array *oa, int i, int fd)
{
return feed_msg_to_hook(fd, "%s %s\n", label,
sha1_to_hex(oa->objects[i].item->sha1));
}

static int run_post_upload_pack_hook(size_t total, struct timeval *tv)
{
const char *argv[2];
struct child_process proc;
int err, i;

argv[0] = "hooks/post-upload-pack";
argv[1] = NULL;

if (access(argv[0], X_OK) < 0)
return 0;

memset(&proc, 0, sizeof(proc));
proc.argv = argv;
proc.in = -1;
proc.stdout_to_stderr = 1;
err = start_command(&proc);
if (err)
return err;
for (i = 0; !err && i < want_obj.nr; i++)
err |= feed_obj_to_hook("want", &want_obj, i, proc.in);
for (i = 0; !err && i < have_obj.nr; i++)
err |= feed_obj_to_hook("have", &have_obj, i, proc.in);
if (!err)
err |= feed_msg_to_hook(proc.in, "time %ld.%06ld\n",
(long)tv->tv_sec, (long)tv->tv_usec);
if (!err)
err |= feed_msg_to_hook(proc.in, "size %ld\n", (long)total);
if (!err)
err |= feed_msg_to_hook(proc.in, "kind %s\n",
(nr_our_refs == want_obj.nr && !have_obj.nr)
? "clone" : "fetch");
if (close(proc.in))
err = 1;
if (finish_command(&proc))
err = 1;
return err;
}

static void create_pack_file(void)
{
struct timeval start_tv, tv;
struct async rev_list;
struct child_process pack_objects;
int create_full_pack = (nr_our_refs == want_obj.nr && !have_obj.nr);
char data[8193], progress[128];
char abort_msg[] = "aborting due to possible repository "
"corruption on the remote side.";
int buffered = -1;
ssize_t sz, total_sz;
ssize_t sz;
const char *argv[10];
int arg = 0;

gettimeofday(&start_tv, NULL);
total_sz = 0;
if (shallow_nr) {
rev_list.proc = do_rev_list;
rev_list.data = 0;
Expand Down Expand Up @@ -344,7 +284,7 @@ static void create_pack_file(void)
sz = xread(pack_objects.out, cp,
sizeof(data) - outsz);
if (0 < sz)
total_sz += sz;
;
else if (sz == 0) {
close(pack_objects.out);
pack_objects.out = -1;
Expand Down Expand Up @@ -381,16 +321,6 @@ static void create_pack_file(void)
}
if (use_sideband)
packet_flush(1);

gettimeofday(&tv, NULL);
tv.tv_sec -= start_tv.tv_sec;
if (tv.tv_usec < start_tv.tv_usec) {
tv.tv_sec--;
tv.tv_usec += 1000000;
}
tv.tv_usec -= start_tv.tv_usec;
if (run_post_upload_pack_hook(total_sz, &tv))
warning("post-upload-hook failed");
return;

fail:
Expand Down

0 comments on commit 1456b04

Please sign in to comment.