From: Edmundo Carmona <eantoranz@gmail.com>
To: git@vger.kernel.org
Cc: Edmundo Carmona Antoranz <eantoranz@gmail.com>
Subject: [PATCH 1/2] checkout: progress on non-tty. progress with lf
Date: Sat, 24 Oct 2015 08:59:46 -0600 [thread overview]
Message-ID: <1445698786-22673-1-git-send-email-eantoranz@gmail.com> (raw)
From: Edmundo Carmona Antoranz <eantoranz@gmail.com>
--progress-no-tty: option to write progress even if not working on a TTY
--progress-lf: option to print progress using LF instead of CR
Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
---
builtin/checkout.c | 12 ++++++++++--
progress.c | 8 +++++++-
progress.h | 1 +
unpack-trees.c | 3 +++
unpack-trees.h | 2 ++
5 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index bc703c0..2c86a9a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -37,6 +37,8 @@ struct checkout_opts {
int overwrite_ignore;
int ignore_skipworktree;
int ignore_other_worktrees;
+ int progress_lf;
+ int progress_notty;
const char *new_branch;
const char *new_branch_force;
@@ -417,7 +419,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
opts.reset = 1;
opts.merge = 1;
opts.fn = oneway_merge;
- opts.verbose_update = !o->quiet && isatty(2);
+ opts.verbose_update = !o->quiet && (o->progress_notty || isatty(2));
+ opts.eol = o->progress_lf ? _("\n") : NULL;
opts.src_index = &the_index;
opts.dst_index = &the_index;
parse_tree(tree);
@@ -501,7 +504,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
topts.update = 1;
topts.merge = 1;
topts.gently = opts->merge && old->commit;
- topts.verbose_update = !opts->quiet && isatty(2);
+ topts.verbose_update = !opts->quiet && (opts->progress_notty || isatty(2));
+ topts.eol = opts->progress_lf ? _("\n") : NULL;
topts.fn = twoway_merge;
if (opts->overwrite_ignore) {
topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -1156,6 +1160,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
N_("second guess 'git checkout <no-such-branch>'")),
OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
N_("do not check if another worktree is holding the given ref")),
+ OPT_BOOL(0, "progress-lf", &opts.progress_lf,
+ N_("write progress using lf instead of cr")),
+ OPT_BOOL(0, "progress-no-tty", &opts.progress_notty,
+ N_("write progress info even if not using a TTY")),
OPT_END(),
};
diff --git a/progress.c b/progress.c
index 353bd37..3af0594 100644
--- a/progress.c
+++ b/progress.c
@@ -36,6 +36,7 @@ struct progress {
unsigned delay;
unsigned delayed_percent_treshold;
struct throughput *throughput;
+ const char *eol;
};
static volatile sig_atomic_t progress_update;
@@ -99,7 +100,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
progress->last_value = n;
tp = (progress->throughput) ? progress->throughput->display.buf : "";
- eol = done ? done : " \r";
+ eol = done ? done : (progress->eol ? progress->eol : " \r");
if (progress->total) {
unsigned percent = n * 100 / progress->total;
if (percent != progress->last_percent || progress_update) {
@@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,
progress->delayed_percent_treshold = percent_treshold;
progress->delay = delay;
progress->throughput = NULL;
+ progress->eol = NULL;
set_progress_signal();
return progress;
}
@@ -230,6 +232,10 @@ struct progress *start_progress(const char *title, unsigned total)
return start_progress_delay(title, total, 0, 0);
}
+void set_progress_eol(struct progress *p_progress, const char *eol) {
+ p_progress->eol = eol;
+}
+
void stop_progress(struct progress **p_progress)
{
stop_progress_msg(p_progress, _("done"));
diff --git a/progress.h b/progress.h
index 611e4c4..dbde34e 100644
--- a/progress.h
+++ b/progress.h
@@ -8,6 +8,7 @@ int display_progress(struct progress *progress, unsigned n);
struct progress *start_progress(const char *title, unsigned total);
struct progress *start_progress_delay(const char *title, unsigned total,
unsigned percent_treshold, unsigned delay);
+void set_progress_eol(struct progress *p_progress, const char *eol);
void stop_progress(struct progress **progress);
void stop_progress_msg(struct progress **progress, const char *msg);
diff --git a/unpack-trees.c b/unpack-trees.c
index 8e2032f..250482b 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -202,6 +202,9 @@ static int check_updates(struct unpack_trees_options *o)
progress = start_progress_delay(_("Checking out files"),
total, 50, 1);
+ if (o->eol) {
+ set_progress_eol(progress, o->eol);
+ }
cnt = 0;
}
diff --git a/unpack-trees.h b/unpack-trees.h
index 36a73a6..3e4bc47 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -71,6 +71,8 @@ struct unpack_trees_options {
struct index_state *src_index;
struct index_state result;
+ const char *eol;
+
struct exclude_list *el; /* for internal use */
};
--
2.6.1
next reply other threads:[~2015-10-24 15:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-24 14:59 Edmundo Carmona [this message]
2015-10-25 1:50 ` [PATCH 1/2] checkout: progress on non-tty. progress with lf Edmundo Carmona Antoranz
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=1445698786-22673-1-git-send-email-eantoranz@gmail.com \
--to=eantoranz@gmail.com \
--cc=git@vger.kernel.org \
/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).