git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] add new output-tuning flags to 'git cherry'
@ 2009-05-30  1:39 Jeff Epler
  2009-05-30  1:39 ` [PATCH 2/2] document new flags Jeff Epler
  2009-05-30 12:18 ` [PATCH 1/2] add new output-tuning flags to 'git cherry' Michael J Gruber
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Epler @ 2009-05-30  1:39 UTC (permalink / raw)
  To: git; +Cc: Jeff Epler

From: Jeff Epler <jepler@unpythonic.net>

The new flags are:
    -a or -##: abbreviate SHA1s to 7 or ## places
    -r: reverse 'upstream' and 'head' (useful when on 'head' and wanting to
        pick from 'upstream')
    -d: only show "+" (doesn't have) patches
    -D: only show "-" (does have) patches

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
---
 builtin-log.c |   54 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index f10cfeb..420f39e 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -1130,7 +1130,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
 }
 
 static const char cherry_usage[] =
-"git cherry [-v] [<upstream> [<head> [<limit>]]]";
+"git cherry [-v] [-a|-#] [-r] [-d|-D] [<upstream> [<head> [<limit>]]]";
 int cmd_cherry(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info revs;
@@ -1142,9 +1142,29 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 	const char *head = "HEAD";
 	const char *limit = NULL;
 	int verbose = 0;
+	int reverse = 0;
+	int abbrev = 40;
+	int show_has = 0;
+	int show_hasnt = 0;
+
+	while(argc > 1 && argv[1][0] == '-')
+	{
+		if (!strcmp(argv[1], "-v")) {
+			verbose = 1;
+		} else if(!strcmp(argv[1], "-a")) {
+			abbrev = DEFAULT_ABBREV;
+		} else if(isdigit(argv[1][1])) {
+			abbrev = atoi(argv+1);
+		} else if(!strcmp(argv[1], "-r")) {
+			reverse = 1;
+		} else if(!strcmp(argv[1], "-d")) {
+			show_hasnt = 1;
+		} else if(!strcmp(argv[1], "-D")) {
+			show_has = 1;
+		} else {
+			die("unrecognized argument: %s", argv[1]);
+		}
 
-	if (argc > 1 && !strcmp(argv[1], "-v")) {
-		verbose = 1;
 		argc--;
 		argv++;
 	}
@@ -1173,6 +1193,16 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 		upstream = current_branch->merge[0]->dst;
 	}
 
+	if(reverse) {
+		const char *temp = upstream;
+		upstream = head;
+		head = temp;
+	}
+
+	if(!show_has && !show_hasnt) {
+		show_has = show_hasnt = 1;
+	}
+
 	init_revisions(&revs, prefix);
 	revs.diff = 1;
 	revs.combine_merges = 0;
@@ -1207,27 +1237,31 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
 		commit_list_insert(commit, &list);
 	}
 
-	while (list) {
+	for (; list; list=list->next) {
 		char sign = '+';
+		int has;
 
 		commit = list->item;
-		if (has_commit_patch_id(commit, &ids))
+
+		if ((has = has_commit_patch_id(commit, &ids))) {
 			sign = '-';
+			if(!show_has) continue;
+		} else {
+			if(!show_hasnt) continue;
+		}
 
 		if (verbose) {
 			struct strbuf buf = STRBUF_INIT;
 			pretty_print_commit(CMIT_FMT_ONELINE, commit,
-			                    &buf, 0, NULL, NULL, 0, 0);
-			printf("%c %s %s\n", sign,
+					    &buf, 0, NULL, NULL, 0, 0);
+			printf("%c %.*s %s\n", sign, abbrev,
 			       sha1_to_hex(commit->object.sha1), buf.buf);
 			strbuf_release(&buf);
 		}
 		else {
-			printf("%c %s\n", sign,
+			printf("%c %.*s\n", sign, abbrev,
 			       sha1_to_hex(commit->object.sha1));
 		}
-
-		list = list->next;
 	}
 
 	free_patch_ids(&ids);
-- 
1.5.4.3

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

* [PATCH 2/2] document new flags
  2009-05-30  1:39 [PATCH 1/2] add new output-tuning flags to 'git cherry' Jeff Epler
@ 2009-05-30  1:39 ` Jeff Epler
  2009-05-30  8:19   ` Jakub Narebski
  2009-05-30 12:18 ` [PATCH 1/2] add new output-tuning flags to 'git cherry' Michael J Gruber
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff Epler @ 2009-05-30  1:39 UTC (permalink / raw)
  To: git; +Cc: Jeff Epler

From: Jeff Epler <jepler@unpythonic.net>

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
---
 Documentation/git-cherry.txt |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt
index 7deefda..100ed69 100644
--- a/Documentation/git-cherry.txt
+++ b/Documentation/git-cherry.txt
@@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream
 
 SYNOPSIS
 --------
-'git cherry' [-v] [<upstream> [<head> [<limit>]]]
+'git cherry' [-v] [-a|-#] [-r] [-d|-D] [<upstream> [<head> [<limit>]]]
 
 DESCRIPTION
 -----------
@@ -49,6 +49,18 @@ OPTIONS
 -v::
 	Verbose.
 
+-a|-#::
+	Abbreviate commit ids to the given number of characters, or 7 for -a
+
+-r::
+	Swap <upstream> and <head>
+
+-d::
+	Only show commits that don't exist in upstream ("+" lines)
+
+-D::
+	Only show commits that do exist in upstream ("-" lines)
+
 <upstream>::
 	Upstream branch to compare against.
 	Defaults to the first tracked remote branch, if available.
-- 
1.5.4.3

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

* Re: [PATCH 2/2] document new flags
  2009-05-30  1:39 ` [PATCH 2/2] document new flags Jeff Epler
@ 2009-05-30  8:19   ` Jakub Narebski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2009-05-30  8:19 UTC (permalink / raw)
  To: Jeff Epler; +Cc: git, Jeff Epler

Jeff Epler <unpythonic.net@unpythonic.net> writes:

> From: Jeff Epler <jepler@unpythonic.net>
> 
> Signed-off-by: Jeff Epler <jepler@unpythonic.net>
> ---
>  Documentation/git-cherry.txt |   14 +++++++++++++-
>  1 files changed, 13 insertions(+), 1 deletions(-)

Why split this patch in two? It is better to have new feature and
documentation together, I think.
 
> diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt
> index 7deefda..100ed69 100644
> --- a/Documentation/git-cherry.txt
> +++ b/Documentation/git-cherry.txt
> @@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream
>  
>  SYNOPSIS
>  --------
> -'git cherry' [-v] [<upstream> [<head> [<limit>]]]
> +'git cherry' [-v] [-a|-#] [-r] [-d|-D] [<upstream> [<head> [<limit>]]]
>  
>  DESCRIPTION
>  -----------
> @@ -49,6 +49,18 @@ OPTIONS
>  -v::
>  	Verbose.
>  
> +-a|-#::
> +	Abbreviate commit ids to the given number of characters, or 7 for -a
> +

Why invent new convention, instead of using -<n> like git-log?
Why do not use --abbrev or --abbrev-commit? -<n> is used elsewhere
to limit number of commits...

> +-r::
> +	Swap <upstream> and <head>

Why not -R like in git-diff?

> +
> +-d::
> +	Only show commits that don't exist in upstream ("+" lines)
> +
> +-D::
> +	Only show commits that do exist in upstream ("-" lines)
> +

I'm not sure if -d/-D is the best name of this short option...

>  <upstream>::
>  	Upstream branch to compare against.
>  	Defaults to the first tracked remote branch, if available.
> -- 
> 1.5.4.3
> 

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: [PATCH 1/2] add new output-tuning flags to 'git cherry'
  2009-05-30  1:39 [PATCH 1/2] add new output-tuning flags to 'git cherry' Jeff Epler
  2009-05-30  1:39 ` [PATCH 2/2] document new flags Jeff Epler
@ 2009-05-30 12:18 ` Michael J Gruber
  1 sibling, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2009-05-30 12:18 UTC (permalink / raw)
  To: Jeff Epler; +Cc: git, Jeff Epler

Jeff Epler venit, vidit, dixit 30.05.2009 03:39:
> From: Jeff Epler <jepler@unpythonic.net>

git cherry certainly could use a few enhancements. About the proposed
ones, I'm a bit doubtful, besides the issue of unusual option names
which Jakub mentioned:

> 
> The new flags are:
>     -a or -##: abbreviate SHA1s to 7 or ## places
>     -r: reverse 'upstream' and 'head' (useful when on 'head' and wanting to
>         pick from 'upstream')

What's wrong with using "git cherry HEAD upstream" in that case?

>     -d: only show "+" (doesn't have) patches
>     -D: only show "-" (does have) patches

Those are a matter of "git cherry <options> | egrep '^\+' etc.

So I don't think the patch adds new functionality. If anything I would
probably suggest having --abbrev and leaving the others out.

Useful new functionality would be:
- Display the upstream commit name which has the same patch id.
- Deal differently with a limit which is a predecessor of the merge-base.

> 
> Signed-off-by: Jeff Epler <jepler@unpythonic.net>
> ---
>  builtin-log.c |   54 ++++++++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 44 insertions(+), 10 deletions(-)
> 
> diff --git a/builtin-log.c b/builtin-log.c
> index f10cfeb..420f39e 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -1130,7 +1130,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
>  }
>  
>  static const char cherry_usage[] =
> -"git cherry [-v] [<upstream> [<head> [<limit>]]]";
> +"git cherry [-v] [-a|-#] [-r] [-d|-D] [<upstream> [<head> [<limit>]]]";
>  int cmd_cherry(int argc, const char **argv, const char *prefix)
>  {
>  	struct rev_info revs;
> @@ -1142,9 +1142,29 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
>  	const char *head = "HEAD";
>  	const char *limit = NULL;
>  	int verbose = 0;
> +	int reverse = 0;
> +	int abbrev = 40;
> +	int show_has = 0;
> +	int show_hasnt = 0;
> +
> +	while(argc > 1 && argv[1][0] == '-')
> +	{
> +		if (!strcmp(argv[1], "-v")) {
> +			verbose = 1;
> +		} else if(!strcmp(argv[1], "-a")) {
> +			abbrev = DEFAULT_ABBREV;
> +		} else if(isdigit(argv[1][1])) {
> +			abbrev = atoi(argv+1);
> +		} else if(!strcmp(argv[1], "-r")) {
> +			reverse = 1;
> +		} else if(!strcmp(argv[1], "-d")) {
> +			show_hasnt = 1;
> +		} else if(!strcmp(argv[1], "-D")) {
> +			show_has = 1;
> +		} else {
> +			die("unrecognized argument: %s", argv[1]);
> +		}
>  
> -	if (argc > 1 && !strcmp(argv[1], "-v")) {
> -		verbose = 1;
>  		argc--;
>  		argv++;
>  	}
> @@ -1173,6 +1193,16 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
>  		upstream = current_branch->merge[0]->dst;
>  	}
>  
> +	if(reverse) {
> +		const char *temp = upstream;
> +		upstream = head;
> +		head = temp;
> +	}
> +
> +	if(!show_has && !show_hasnt) {
> +		show_has = show_hasnt = 1;
> +	}
> +
>  	init_revisions(&revs, prefix);
>  	revs.diff = 1;
>  	revs.combine_merges = 0;
> @@ -1207,27 +1237,31 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
>  		commit_list_insert(commit, &list);
>  	}
>  
> -	while (list) {
> +	for (; list; list=list->next) {
>  		char sign = '+';
> +		int has;
>  
>  		commit = list->item;
> -		if (has_commit_patch_id(commit, &ids))
> +
> +		if ((has = has_commit_patch_id(commit, &ids))) {
>  			sign = '-';
> +			if(!show_has) continue;
> +		} else {
> +			if(!show_hasnt) continue;
> +		}
>  
>  		if (verbose) {
>  			struct strbuf buf = STRBUF_INIT;
>  			pretty_print_commit(CMIT_FMT_ONELINE, commit,
> -			                    &buf, 0, NULL, NULL, 0, 0);
> -			printf("%c %s %s\n", sign,
> +					    &buf, 0, NULL, NULL, 0, 0);
> +			printf("%c %.*s %s\n", sign, abbrev,
>  			       sha1_to_hex(commit->object.sha1), buf.buf);
>  			strbuf_release(&buf);
>  		}
>  		else {
> -			printf("%c %s\n", sign,
> +			printf("%c %.*s\n", sign, abbrev,
>  			       sha1_to_hex(commit->object.sha1));
>  		}
> -
> -		list = list->next;
>  	}
>  
>  	free_patch_ids(&ids);

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

end of thread, other threads:[~2009-05-30 12:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-30  1:39 [PATCH 1/2] add new output-tuning flags to 'git cherry' Jeff Epler
2009-05-30  1:39 ` [PATCH 2/2] document new flags Jeff Epler
2009-05-30  8:19   ` Jakub Narebski
2009-05-30 12:18 ` [PATCH 1/2] add new output-tuning flags to 'git cherry' Michael J Gruber

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).