[PATCH/RFC 3/6] status: refactor short-mode printing to its own function

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

 



We want to be able to call it from multiple places.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
I am tempted to move all of the short-printing code to its own file, and
move "cmd_status" to its own builtin-status.c, as well. I don't know if
that is a cleanup that makes sense to others, as well, or if it is too
much churn for too little good.

 builtin-commit.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 812470e..5b42179 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -966,11 +966,32 @@ static void short_untracked(int null_termination, struct string_list_item *it,
 	}
 }
 
+static void short_print(struct wt_status *s, int null_termination)
+{
+	int i;
+	for (i = 0; i < s->change.nr; i++) {
+		struct wt_status_change_data *d;
+		struct string_list_item *it;
+
+		it = &(s->change.items[i]);
+		d = it->util;
+		if (d->stagemask)
+			short_unmerged(null_termination, it, s);
+		else
+			short_status(null_termination, it, s);
+	}
+	for (i = 0; i < s->untracked.nr; i++) {
+		struct string_list_item *it;
+
+		it = &(s->untracked.items[i]);
+		short_untracked(null_termination, it, s);
+	}
+}
+
 int cmd_status(int argc, const char **argv, const char *prefix)
 {
 	struct wt_status s;
 	static int null_termination, shortstatus;
-	int i;
 	unsigned char sha1[20];
 	static struct option builtin_status_options[] = {
 		OPT__VERBOSE(&verbose),
@@ -1003,25 +1024,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
 	wt_status_collect(&s);
 
-	if (shortstatus) {
-		for (i = 0; i < s.change.nr; i++) {
-			struct wt_status_change_data *d;
-			struct string_list_item *it;
-
-			it = &(s.change.items[i]);
-			d = it->util;
-			if (d->stagemask)
-				short_unmerged(null_termination, it, &s);
-			else
-				short_status(null_termination, it, &s);
-		}
-		for (i = 0; i < s.untracked.nr; i++) {
-			struct string_list_item *it;
-
-			it = &(s.untracked.items[i]);
-			short_untracked(null_termination, it, &s);
-		}
-	} else {
+	if (shortstatus)
+		short_print(&s, null_termination);
+	else {
 		s.verbose = verbose;
 		if (s.relative_paths)
 			s.prefix = prefix;
-- 
1.6.4.2.418.g1a1d3.dirty

--
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]