From 3cc9d87710b20c86252809e068fe309f6bb7ecc2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jun 2014 05:43:07 -0400 Subject: [PATCH 1/3] replace: replace spaces with tabs in indentation This matches our usual style and the surrounding code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/replace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 1bb491d3c4f..8507835d396 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -23,9 +23,9 @@ static const char * const git_replace_usage[] = { }; enum replace_format { - REPLACE_FORMAT_SHORT, - REPLACE_FORMAT_MEDIUM, - REPLACE_FORMAT_LONG + REPLACE_FORMAT_SHORT, + REPLACE_FORMAT_MEDIUM, + REPLACE_FORMAT_LONG }; struct show_data { From 28bf9429ef2e1534be8d3a59ad236834be542b86 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jun 2014 05:45:46 -0400 Subject: [PATCH 2/3] avoid double close of descriptors handed to run_command When a file descriptor is given to run_command via the "in", "out", or "err" parameters, run_command takes ownership. The descriptor will be closed in the parent process whether the process is spawned successfully or not, and closing it again is wrong. In practice this has not caused problems, because we usually close() right after start_command returns, meaning no other code has opened a descriptor in the meantime. So we just get EBADF and ignore it (rather than accidentally closing somebody else's descriptor!). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/replace.c | 2 -- daemon.c | 1 - 2 files changed, 3 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 8507835d396..eb1d2ec5e53 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -207,8 +207,6 @@ static void export_object(const unsigned char *sha1, const char *filename) if (run_command(&cmd)) die("cat-file reported failure"); - - close(fd); } /* diff --git a/daemon.c b/daemon.c index eba12556848..a2701af2fc7 100644 --- a/daemon.c +++ b/daemon.c @@ -783,7 +783,6 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) logerror("unable to fork"); else add_child(&cld, addr, addrlen); - close(incoming); } static void child_handler(int signo) From 36857e0026f5a7855f941a955bf7014408a816dd Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jun 2014 05:46:05 -0400 Subject: [PATCH 3/3] replace: use argv_array in export_object This is a little more verbose, but will make it easier to make parts of our command-line conditional (without resorting to magic numbers or lots of NULLs to get an appropriately sized argv array). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/replace.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index eb1d2ec5e53..25841708fa2 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -193,15 +193,17 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f */ static void export_object(const unsigned char *sha1, const char *filename) { - const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL }; - struct child_process cmd = { argv }; + struct child_process cmd = { NULL }; int fd; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) die_errno("unable to open %s for writing", filename); - argv[3] = sha1_to_hex(sha1); + argv_array_push(&cmd.args, "--no-replace-objects"); + argv_array_push(&cmd.args, "cat-file"); + argv_array_push(&cmd.args, "-p"); + argv_array_push(&cmd.args, sha1_to_hex(sha1)); cmd.git_cmd = 1; cmd.out = fd;