git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] cherry: support --abbrev option
@ 2010-03-15 16:03 Erik Faye-Lund
  2010-03-15 17:08 ` René Scharfe
  2010-03-15 17:13 ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Erik Faye-Lund @ 2010-03-15 16:03 UTC (permalink / raw)
  To: git

Switch to parse-options API while we're at it.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---

I sometimes find it useful to look at the commit-subject together with
the SHA-1s. Using --abbrev increases the chance that the lines fits on
an 80 character wide terminal, making the output easier to read.

 builtin/log.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index b70d0f7..020d618 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1286,8 +1286,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
 	return -1;
 }
 
-static const char cherry_usage[] =
-"git cherry [-v] [<upstream> [<head> [<limit>]]]";
+static const char * const cherry_usage[] = {
+	"git cherry [-v] [<upstream> [<head> [<limit>]]]",
+	NULL
+};
+
 int cmd_cherry(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info revs;
@@ -1298,26 +1301,26 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 	const char *upstream;
 	const char *head = "HEAD";
 	const char *limit = NULL;
-	int verbose = 0;
+	int verbose = 0, abbrev = 40;
 
-	if (argc > 1 && !strcmp(argv[1], "-v")) {
-		verbose = 1;
-		argc--;
-		argv++;
-	}
+	struct option options[] = {
+		OPT__ABBREV(&abbrev),
+		OPT__VERBOSE(&verbose),
+		OPT_END()
+	};
 
-	if (argc > 1 && !strcmp(argv[1], "-h"))
-		usage(cherry_usage);
+	argc = parse_options(argc, argv, prefix, options, cherry_usage,
+	    PARSE_OPT_KEEP_UNKNOWN);
 
 	switch (argc) {
-	case 4:
-		limit = argv[3];
-		/* FALLTHROUGH */
 	case 3:
-		head = argv[2];
+		limit = argv[2];
 		/* FALLTHROUGH */
 	case 2:
-		upstream = argv[1];
+		head = argv[1];
+		/* FALLTHROUGH */
+	case 1:
+		upstream = argv[0];
 		break;
 	default:
 		current_branch = branch_get(NULL);
@@ -1327,7 +1330,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 			fprintf(stderr, "Could not find a tracked"
 					" remote branch, please"
 					" specify <upstream> manually.\n");
-			usage(cherry_usage);
+			usage_with_options(cherry_usage, options);
 		}
 
 		upstream = current_branch->merge[0]->dst;
@@ -1380,12 +1383,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 			pretty_print_commit(CMIT_FMT_ONELINE, commit,
 					    &buf, &ctx);
 			printf("%c %s %s\n", sign,
-			       sha1_to_hex(commit->object.sha1), buf.buf);
+			       find_unique_abbrev(commit->object.sha1, abbrev),
+			       buf.buf);
 			strbuf_release(&buf);
 		}
 		else {
 			printf("%c %s\n", sign,
-			       sha1_to_hex(commit->object.sha1));
+			       find_unique_abbrev(commit->object.sha1, abbrev));
 		}
 
 		list = list->next;
-- 
1.7.0.2.416.g84492

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-16  1:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-15 16:03 [PATCH RFC] cherry: support --abbrev option Erik Faye-Lund
2010-03-15 17:08 ` René Scharfe
2010-03-15 22:30   ` Erik Faye-Lund
2010-03-15 23:16     ` René Scharfe
2010-03-15 23:50       ` Erik Faye-Lund
2010-03-16  0:46         ` René Scharfe
2010-03-16  0:59           ` Erik Faye-Lund
2010-03-16  1:44         ` Junio C Hamano
2010-03-15 17:13 ` Junio C Hamano
2010-03-15 22:39   ` Erik Faye-Lund

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).