Re: [PATCH 2/2] use env_array member of struct child_process

2014-11-09 Thread René Scharfe
Am 20.10.2014 um 11:19 schrieb Jeff King:
> On Sun, Oct 19, 2014 at 01:14:20PM +0200, René Scharfe wrote:
> 
>> --- a/wt-status.c
>> +++ b/wt-status.c
>> @@ -726,14 +726,14 @@ static void wt_status_print_changed(struct wt_status 
>> *s)
>>   static void wt_status_print_submodule_summary(struct wt_status *s, int 
>> uncommitted)
>>   {
>>  struct child_process sm_summary = CHILD_PROCESS_INIT;
>> -struct argv_array env = ARGV_ARRAY_INIT;
>>  struct argv_array argv = ARGV_ARRAY_INIT;
> 
> I don't think it belongs in this patch, but a follow-on 3/2 might be to
> give argv the same treatment.

Yes, good idea.

-- >8 --
Subject: [PATCH] use args member of struct child_process

Convert users of struct child_process to using the managed argv_array
args instead of providing their own.  This shortens the code a bit and
ensures that the allocated memory is released automatically after use.

Suggested-by: Jeff King 
Signed-off-by: Rene Scharfe 
---
 builtin/repack.c | 47 ++-
 wt-status.c  | 17 +++--
 2 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index 2845620..83e91c7 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -135,7 +135,6 @@ int cmd_repack(int argc, const char **argv, const char 
*prefix)
};
struct child_process cmd = CHILD_PROCESS_INIT;
struct string_list_item *item;
-   struct argv_array cmd_args = ARGV_ARRAY_INIT;
struct string_list names = STRING_LIST_INIT_DUP;
struct string_list rollback = STRING_LIST_INIT_NODUP;
struct string_list existing_packs = STRING_LIST_INIT_DUP;
@@ -202,56 +201,55 @@ int cmd_repack(int argc, const char **argv, const char 
*prefix)
 
sigchain_push_common(remove_pack_on_signal);
 
-   argv_array_push(&cmd_args, "pack-objects");
-   argv_array_push(&cmd_args, "--keep-true-parents");
+   argv_array_push(&cmd.args, "pack-objects");
+   argv_array_push(&cmd.args, "--keep-true-parents");
if (!pack_kept_objects)
-   argv_array_push(&cmd_args, "--honor-pack-keep");
-   argv_array_push(&cmd_args, "--non-empty");
-   argv_array_push(&cmd_args, "--all");
-   argv_array_push(&cmd_args, "--reflog");
-   argv_array_push(&cmd_args, "--indexed-objects");
+   argv_array_push(&cmd.args, "--honor-pack-keep");
+   argv_array_push(&cmd.args, "--non-empty");
+   argv_array_push(&cmd.args, "--all");
+   argv_array_push(&cmd.args, "--reflog");
+   argv_array_push(&cmd.args, "--indexed-objects");
if (window)
-   argv_array_pushf(&cmd_args, "--window=%s", window);
+   argv_array_pushf(&cmd.args, "--window=%s", window);
if (window_memory)
-   argv_array_pushf(&cmd_args, "--window-memory=%s", 
window_memory);
+   argv_array_pushf(&cmd.args, "--window-memory=%s", 
window_memory);
if (depth)
-   argv_array_pushf(&cmd_args, "--depth=%s", depth);
+   argv_array_pushf(&cmd.args, "--depth=%s", depth);
if (max_pack_size)
-   argv_array_pushf(&cmd_args, "--max-pack-size=%s", 
max_pack_size);
+   argv_array_pushf(&cmd.args, "--max-pack-size=%s", 
max_pack_size);
if (no_reuse_delta)
-   argv_array_pushf(&cmd_args, "--no-reuse-delta");
+   argv_array_pushf(&cmd.args, "--no-reuse-delta");
if (no_reuse_object)
-   argv_array_pushf(&cmd_args, "--no-reuse-object");
+   argv_array_pushf(&cmd.args, "--no-reuse-object");
if (write_bitmaps)
-   argv_array_push(&cmd_args, "--write-bitmap-index");
+   argv_array_push(&cmd.args, "--write-bitmap-index");
 
if (pack_everything & ALL_INTO_ONE) {
get_non_kept_pack_filenames(&existing_packs);
 
if (existing_packs.nr && delete_redundant) {
if (unpack_unreachable)
-   argv_array_pushf(&cmd_args,
+   argv_array_pushf(&cmd.args,
"--unpack-unreachable=%s",
unpack_unreachable);
else if (pack_everything & LOOSEN_UNREACHABLE)
-   argv_array_push(&cmd_args,
+   argv_array_push(&cmd.args,
"--unpack-unreachable");
}
} else {
-   argv_array_push(&cmd_args, "--unpacked");
-   argv_array_push(&cmd_args, "--incremental");
+   argv_array_push(&cmd.args, "--unpacked");
+   argv_array_push(&cmd.args, "--incremental");
}
 
if (local)
-   argv_array_push(&cmd_args,  "--local");
+   argv_array_push(&cmd.args,  "--local");
if (quiet)
-   argv_array_pus

Re: [PATCH 2/2] use env_array member of struct child_process

2014-10-20 Thread Jeff King
On Sun, Oct 19, 2014 at 01:14:20PM +0200, René Scharfe wrote:

> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -726,14 +726,14 @@ static void wt_status_print_changed(struct wt_status *s)
>  static void wt_status_print_submodule_summary(struct wt_status *s, int 
> uncommitted)
>  {
>   struct child_process sm_summary = CHILD_PROCESS_INIT;
> - struct argv_array env = ARGV_ARRAY_INIT;
>   struct argv_array argv = ARGV_ARRAY_INIT;

I don't think it belongs in this patch, but a follow-on 3/2 might be to
give argv the same treatment.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] use env_array member of struct child_process

2014-10-19 Thread René Scharfe
Convert users of struct child_process to using the managed env_array for
specifying environment variables instead of supplying an array on the
stack or bringing their own argv_array.  This shortens and simplifies
the code and ensures automatically that the allocated memory is freed
after use.

Signed-off-by: Rene Scharfe 
---
 builtin/receive-pack.c | 23 ++-
 http-backend.c |  9 +++--
 pager.c| 15 ---
 transport-helper.c | 10 ++
 wt-status.c|  6 ++
 5 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f2f6c67..7593861 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -453,7 +453,6 @@ leave:
 static void prepare_push_cert_sha1(struct child_process *proc)
 {
static int already_done;
-   struct argv_array env = ARGV_ARRAY_INIT;
 
if (!push_cert.len)
return;
@@ -487,20 +486,26 @@ static void prepare_push_cert_sha1(struct child_process 
*proc)
nonce_status = check_nonce(push_cert.buf, bogs);
}
if (!is_null_sha1(push_cert_sha1)) {
-   argv_array_pushf(&env, "GIT_PUSH_CERT=%s", 
sha1_to_hex(push_cert_sha1));
-   argv_array_pushf(&env, "GIT_PUSH_CERT_SIGNER=%s",
+   argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
+sha1_to_hex(push_cert_sha1));
+   argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
 sigcheck.signer ? sigcheck.signer : "");
-   argv_array_pushf(&env, "GIT_PUSH_CERT_KEY=%s",
+   argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",
 sigcheck.key ? sigcheck.key : "");
-   argv_array_pushf(&env, "GIT_PUSH_CERT_STATUS=%c", 
sigcheck.result);
+   argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c",
+sigcheck.result);
if (push_cert_nonce) {
-   argv_array_pushf(&env, "GIT_PUSH_CERT_NONCE=%s", 
push_cert_nonce);
-   argv_array_pushf(&env, "GIT_PUSH_CERT_NONCE_STATUS=%s", 
nonce_status);
+   argv_array_pushf(&proc->env_array,
+"GIT_PUSH_CERT_NONCE=%s",
+push_cert_nonce);
+   argv_array_pushf(&proc->env_array,
+"GIT_PUSH_CERT_NONCE_STATUS=%s",
+nonce_status);
if (nonce_status == NONCE_SLOP)
-   argv_array_pushf(&env, 
"GIT_PUSH_CERT_NONCE_SLOP=%ld",
+   argv_array_pushf(&proc->env_array,
+"GIT_PUSH_CERT_NONCE_SLOP=%ld",
 nonce_stamp_slop);
}
-   proc->env = env.argv;
}
 }
 
diff --git a/http-backend.c b/http-backend.c
index 404e682..e3e0dda 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -314,7 +314,6 @@ static void run_service(const char **argv)
const char *encoding = getenv("HTTP_CONTENT_ENCODING");
const char *user = getenv("REMOTE_USER");
const char *host = getenv("REMOTE_ADDR");
-   struct argv_array env = ARGV_ARRAY_INIT;
int gzipped_request = 0;
struct child_process cld = CHILD_PROCESS_INIT;
 
@@ -329,13 +328,12 @@ static void run_service(const char **argv)
host = "(none)";
 
if (!getenv("GIT_COMMITTER_NAME"))
-   argv_array_pushf(&env, "GIT_COMMITTER_NAME=%s", user);
+   argv_array_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user);
if (!getenv("GIT_COMMITTER_EMAIL"))
-   argv_array_pushf(&env, "GIT_COMMITTER_EMAIL=%s@http.%s",
-user, host);
+   argv_array_pushf(&cld.env_array,
+"GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
 
cld.argv = argv;
-   cld.env = env.argv;
if (gzipped_request)
cld.in = -1;
cld.git_cmd = 1;
@@ -350,7 +348,6 @@ static void run_service(const char **argv)
 
if (finish_command(&cld))
exit(1);
-   argv_array_clear(&env);
 }
 
 static int show_text_ref(const char *name, const unsigned char *sha1,
diff --git a/pager.c b/pager.c
index b2b805a..f6e8c33 100644
--- a/pager.c
+++ b/pager.c
@@ -74,17 +74,10 @@ void setup_pager(void)
pager_process.use_shell = 1;
pager_process.argv = pager_argv;
pager_process.in = -1;
-   if (!getenv("LESS") || !getenv("LV")) {
-   static const char *env[3];
-   int i = 0;
-
-   if (!getenv("LESS"))
-   env[i++] = "LESS=FRX";
-   if (!getenv("LV"))
-