From: Duy Nguyen <pclouds@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] reflog expire: add progress output
Date: Thu, 20 Sep 2018 18:19:28 +0200 [thread overview]
Message-ID: <20180920161928.GA13379@duynguyen.home> (raw)
In-Reply-To: <87tvmljtaz.fsf@evledraar.gmail.com>
On Wed, Sep 19, 2018 at 07:22:44PM +0200, Ævar Arnfjörð Bjarmason wrote:
> >> @@ -225,14 +226,20 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
> >> struct commit_list *pending;
> >> timestamp_t expire_limit = cb->mark_limit;
> >> struct commit_list *leftover = NULL;
> >> + struct progress *progress = NULL;
> >> + int i = 0;
> >>
> >> for (pending = cb->mark_list; pending; pending = pending->next)
> >> pending->item->object.flags &= ~REACHABLE;
> >>
> >> pending = cb->mark_list;
> >> + progress = start_delayed_progress(
> >> + _("Marking unreachable commits in reflog for expiry"), 0);
> >
> > Maybe just "Searching expired reflog entries" or something like that.
> > It's not technically as accurate, but I think it's easier to
> > understand by by new people.
>
> Or "Pruning reflog entries"? I was aiming for some combination of a)
> making it clear what we're doing (pruning stuff) b) that we're doing it
> on a subset of the counter of the (very large) values we're showing.
>
> So the current one has "a" && "b", "Searching..." has neither, and
> "Pruning..." has "a" but not "b".
>
> Maybe making a && b clear isn't that important, but I'm currently
> leaning towards keeping the current one because it's not *that* long and
> makes things clearer to the user.
OK
> >> while (pending) {
> >> struct commit_list *parent;
> >> struct commit *commit = pop_commit(&pending);
> >> +
> >> + display_progress(progress, ++i);
> >
> > maybe rename it to commit_count or something and leave "i" for
> > temporary/short lived usage.
>
> Good point. Willdo.
Actually I'm still not sure if it's valuable to show the actual commit
count here. Some patch like this could show "activity" without the
number. But this is tangent.
-- 8< --
Subject: [PATCH] progress: add api for displaying a throbber
---
progress.c | 29 +++++++++++++++++++++++++----
progress.h | 1 +
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/progress.c b/progress.c
index 5a99c9fbf0..fada556bf0 100644
--- a/progress.c
+++ b/progress.c
@@ -36,6 +36,7 @@ struct progress {
unsigned delay;
struct throughput *throughput;
uint64_t start_ns;
+ int show_throbber;
};
static volatile sig_atomic_t progress_update;
@@ -81,11 +82,13 @@ static int is_foreground_fd(int fd)
static int display(struct progress *progress, uint64_t n, const char *done)
{
const char *eol, *tp;
+ static char throbber[] = "\\|/-";
if (progress->delay && (!progress_update || --progress->delay))
return 0;
- progress->last_value = n;
+ if (!progress->show_throbber)
+ progress->last_value = n;
tp = (progress->throughput) ? progress->throughput->display.buf : "";
eol = done ? done : " \r";
if (progress->total) {
@@ -104,8 +107,15 @@ static int display(struct progress *progress, uint64_t n, const char *done)
}
} else if (progress_update) {
if (is_foreground_fd(fileno(stderr)) || done) {
- fprintf(stderr, "%s: %"PRIuMAX"%s%s",
- progress->title, (uintmax_t)n, tp, eol);
+ if (progress->show_throbber) {
+ progress->last_value++;
+ fprintf(stderr, "%s: %c%s%s",
+ progress->title,
+ throbber[progress->last_value % 4],
+ tp, eol);
+ } else
+ fprintf(stderr, "%s: %"PRIuMAX"%s%s",
+ progress->title, (uintmax_t)n, tp, eol);
fflush(stderr);
}
progress_update = 0;
@@ -193,6 +203,14 @@ int display_progress(struct progress *progress, uint64_t n)
return progress ? display(progress, n, NULL) : 0;
}
+void display_throbber(struct progress *progress)
+{
+ if (progress) {
+ progress->show_throbber = 1;
+ display(progress, 0, NULL);
+ }
+}
+
static struct progress *start_progress_delay(const char *title, uint64_t total,
unsigned delay)
{
@@ -248,7 +266,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
throughput_string(&tp->display, tp->curr_total, rate);
}
progress_update = 1;
- buf = xstrfmt(", %s.\n", msg);
+ if (progress->show_throbber)
+ buf = xstrfmt(" %s.\n", msg);
+ else
+ buf = xstrfmt(", %s.\n", msg);
display(progress, progress->last_value, buf);
free(buf);
}
diff --git a/progress.h b/progress.h
index 70a4d4a0d6..9d23ff242f 100644
--- a/progress.h
+++ b/progress.h
@@ -5,6 +5,7 @@ struct progress;
void display_throughput(struct progress *progress, uint64_t total);
int display_progress(struct progress *progress, uint64_t n);
+void display_throbber(struct progress *progress);
struct progress *start_progress(const char *title, uint64_t total);
struct progress *start_delayed_progress(const char *title, uint64_t total);
void stop_progress(struct progress **progress);
--
2.19.0.rc0.337.ge906d732e7
-- 8< --
next prev parent reply other threads:[~2018-09-20 16:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-19 14:10 [PATCH] reflog expire: add progress output Ævar Arnfjörð Bjarmason
2018-09-19 16:26 ` Duy Nguyen
2018-09-19 17:22 ` Ævar Arnfjörð Bjarmason
2018-09-19 19:01 ` Jeff King
2018-09-19 20:16 ` Ævar Arnfjörð Bjarmason
2018-09-20 16:19 ` Duy Nguyen [this message]
2018-09-21 2:17 ` Eric Sunshine
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=20180920161928.GA13379@duynguyen.home \
--to=pclouds@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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 NNTP newsgroup(s).