All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH v3] gc: save log from daemonized gc --auto and print it next time
Date: Tue, 25 Aug 2015 10:49:16 -0700	[thread overview]
Message-ID: <xmqqtwrnz2ar.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1440209546-23442-1-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Sat, 22 Aug 2015 09:12:26 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> While commit 9f673f9 (gc: config option for running --auto in
> background - 2014-02-08) helps reduce some complaints about 'gc
> --auto' hogging the terminal, it creates another set of problems.
>
> The latest in this set is, as the result of daemonizing, stderr is
> closed and all warnings are lost. This warning at the end of cmd_gc()
> is particularly important because it tells the user how to avoid "gc
> --auto" running repeatedly. Because stderr is closed, the user does
> not know, naturally they complain about 'gc --auto' wasting CPU.
>
> Daemonized gc now saves stderr to $GIT_DIR/gc.log. Following gc runs
> will not be daemonized and gc.log printed out until the user removes
> gc.log.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Let's try again. Compared to v2 [1], this version does not delete
>  gc.log automatically any more. The user needs to take action, then
>  delete gc.log to bring it background again.

Sounds a bit more sensible, but I wonder if it is a good idea to
keep going in the first place.  If the last gc run reported an
issue, would it make it likely that we would hit the same issue?

An alternative design I have in mind is to exit "gc --auto" with
success without doing anything, after giving the new warning
message.  What would be the pros-and-cons between this patch and
that alternative design?



>  [1] http://thread.gmane.org/gmane.comp.version-control.git/266182/focus=266320
>
>  builtin/gc.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index bcc75d9..00a83e1 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -43,9 +43,20 @@ static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
>  static struct argv_array rerere = ARGV_ARRAY_INIT;
>  
>  static char *pidfile;
> +static struct strbuf log_filename = STRBUF_INIT;
> +static int daemonized;
>  
>  static void remove_pidfile(void)
>  {
> +	if (daemonized && log_filename.len) {
> +		struct stat st;
> +
> +		close(2);
> +		if (stat(log_filename.buf, &st) ||
> +		    !st.st_size ||
> +		    rename(log_filename.buf, git_path("gc.log")))
> +			unlink(log_filename.buf);
> +	}
>  	if (pidfile)
>  		unlink(pidfile);
>  }
> @@ -330,13 +341,24 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>  			fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
>  		}
>  		if (detach_auto) {
> +			struct strbuf sb = STRBUF_INIT;
> +			if (strbuf_read_file(&sb, git_path("gc.log"), 0) > 0) {
> +				warning(_("last gc run reported:\n"
> +					  "%s\n"
> +					  "running in foreground until %s is removed"),
> +					sb.buf, git_path("gc.log"));
> +				detach_auto = 0;
> +			}
> +			strbuf_release(&sb);
> +		}
> +		if (detach_auto) {
>  			if (gc_before_repack())
>  				return -1;
>  			/*
>  			 * failure to daemonize is ok, we'll continue
>  			 * in foreground
>  			 */
> -			daemonize();
> +			daemonized = !daemonize();
>  		}
>  	} else
>  		add_repack_all_option();
> @@ -349,6 +371,18 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>  		    name, (uintmax_t)pid);
>  	}
>  
> +	if (daemonized) {
> +		int fd;
> +
> +		strbuf_addstr(&log_filename, git_path("gc.log_XXXXXX"));
> +		fd = xmkstemp(log_filename.buf);
> +		if (fd >= 0) {
> +			dup2(fd, 2);
> +			close(fd);
> +		} else
> +			strbuf_release(&log_filename);
> +	}
> +
>  	if (gc_before_repack())
>  		return -1;

  reply	other threads:[~2015-08-25 17:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 12:28 Since gc.autodetach=1 you can end up with auto-gc on every command with no user notification Ævar Arnfjörð Bjarmason
2015-07-08 12:47 ` Duy Nguyen
2015-08-22  2:12   ` [PATCH v3] gc: save log from daemonized gc --auto and print it next time Nguyễn Thái Ngọc Duy
2015-08-25 17:49     ` Junio C Hamano [this message]
2015-08-31 10:17       ` Duy Nguyen
2015-09-13  1:36     ` [PATCH v4] " Nguyễn Thái Ngọc Duy
2015-09-14 17:24       ` Junio C Hamano
2015-09-14 17:37         ` Junio C Hamano
2015-09-16  9:28           ` Michael Haggerty
2015-09-16 16:00             ` Junio C Hamano
2015-09-17  9:40               ` Michael Haggerty
2015-09-17 13:08               ` Duy Nguyen
2015-09-17 14:48                 ` Junio C Hamano
2015-09-19  5:13       ` [PATCH v5] " Nguyễn Thái Ngọc Duy
2015-09-21 16:43         ` Junio C Hamano
2015-09-19  5:14       ` [Alt. PATCH " Nguyễn Thái Ngọc Duy
2015-09-21 16:19         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqtwrnz2ar.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.