git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] gc: save log from daemonized gc --auto and print it next time
Date: Tue, 24 Mar 2015 18:12:05 -0400	[thread overview]
Message-ID: <CAPig+cS8zn5XThxShZHYCPs=xUeiwHXKSueor3jX_7E0X_uhuA@mail.gmail.com> (raw)
In-Reply-To: <1427199448-28278-1-git-send-email-pclouds@gmail.com>

On Tue, Mar 24, 2015 at 8:17 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> 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.
>
> Besides reverting 9f673f9 and looking at the problem from another
> angle, we could save the stderr in $GIT_DIR/gc.log. Next time, 'gc
> --auto' will print the saved warnings, delete gc.log and exit.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/gc.c  | 37 ++++++++++++++++++++++++++++++++++++-
>  t/t6500-gc.sh | 20 ++++++++++++++++++++
>  2 files changed, 56 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 5c634af..07769a9 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -32,6 +32,8 @@ static int aggressive_window = 250;
>  static int gc_auto_threshold = 6700;
>  static int gc_auto_pack_limit = 50;
>  static int detach_auto = 1;
> +static struct strbuf log_filename = STRBUF_INIT;
> +static int daemonized;
>  static const char *prune_expire = "2.weeks.ago";
>
>  static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
> @@ -44,6 +46,15 @@ static char *pidfile;
>
>  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);
>  }
> @@ -324,13 +335,25 @@ 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 the following, gc skipped"));

When I read this message, it makes me think that the previous gc was
skipped, even though it's actually skipping the current one. Perhaps
rephrase as "skipping gc; last gc reported:"?

> +                               fputs(sb.buf, stderr);
> +                               strbuf_release(&sb);
> +                               /* let the next gc --auto run as usual */
> +                               unlink(git_path("gc.log"));
> +                               return 0;
> +                       }
> +
>                         if (gc_before_repack())
>                                 return -1;
>                         /*
>                          * failure to daemonize is ok, we'll continue
>                          * in foreground
>                          */
> -                       daemonize();
> +                       if (!daemonize())
> +                               daemonized = 1;
>                 }
>         } else
>                 add_repack_all_option();
> @@ -343,6 +366,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;
>
> diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
> index 63194d8..54bc9c4 100755
> --- a/t/t6500-gc.sh
> +++ b/t/t6500-gc.sh
> @@ -30,4 +30,24 @@ test_expect_success 'gc -h with invalid configuration' '
>         test_i18ngrep "[Uu]sage" broken/usage
>  '
>
> +test_expect_success !MINGW 'gc --auto and logging' '
> +       git init abc &&
> +       (
> +               cd abc &&
> +               # These create blobs starting with the magic number "17"
> +               for i in 901 944; do
> +                       echo $i >test && git hash-object -w test >/dev/null
> +               done &&
> +               git config gc.auto 1 &&
> +               LANG=C git gc --auto &&
> +               sleep 1 && # give it time to daemonize
> +               while test -f .git/gc.pid; do sleep 1; done &&
> +               grep "too many unreachable loose objects" .git/gc.log &&
> +               LANG=C git gc --auto 2>error &&
> +               grep skipped error &&
> +               grep "too many unreachable loose objects" error &&
> +               ! test -f .git/gc.log
> +       )
> +'
> +
>  test_done
> --
> 2.3.0.rc1.137.g477eb31
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-03-24 22:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-24 12:17 [PATCH] gc: save log from daemonized gc --auto and print it next time Nguyễn Thái Ngọc Duy
2015-03-24 22:07 ` Junio C Hamano
2015-03-25  0:58   ` Duy Nguyen
2015-03-24 22:12 ` Eric Sunshine [this message]
2015-03-26 10:54 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
2015-03-26 17:13   ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CAPig+cS8zn5XThxShZHYCPs=xUeiwHXKSueor3jX_7E0X_uhuA@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).