[PATCH 1/2] checkout: progress on non-tty. progress with lf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Edmundo Carmona Antoranz <eantoranz@xxxxxxxxx>

--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@xxxxxxxxx>
---
 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

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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]