git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH 0/2] RFC/POC: patterns for branch list
@ 2011-04-27 12:15 Michael J Gruber
  2011-04-27 12:15 ` [RFC/PATCH 1/2] branch: allow pattern arguments Michael J Gruber
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michael J Gruber @ 2011-04-27 12:15 UTC (permalink / raw)
  To: git

This mini series is about introducing patterns to the list mode of
'git branch' much like the pattern for 'git tag -l'. There are several
things which I would like to do but would like to rfc first:

'-l' is the natural short option name for '--list'. This is taken for the
rarely used or needed 'create reflog' option. I'd change the latter to
'-g,--create-reflog' (cmp. log) and take '-l,--list' but know the reaction
already.

'-v' and '-vv' both take considerable time (because they need to walk).
It makes more sense to have '-v' display cheap output (upstream name)
and '-vv' add expensive output (ahead/behind info). '-vvv' could add super
expensive info (ahead/equivalent/behind a la cherry-mark).

But all of the above are changes to current (ui) behaviour. In the two patches
below, only the automatic activation of the list mode with -v/-vv is a
change of (undocumented) behaviour.

And yes, git-for-each-ref can do all this and more, but that is plumbing.

Michael J Gruber (2):
  branch: allow pattern arguments
  branch: introduce --list argument

 builtin/branch.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

-- 
1.7.5.270.gafca7

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

* [RFC/PATCH 1/2] branch: allow pattern arguments
  2011-04-27 12:15 [RFC/PATCH 0/2] RFC/POC: patterns for branch list Michael J Gruber
@ 2011-04-27 12:15 ` Michael J Gruber
  2011-04-27 12:15 ` [RFC/PATCH 2/2] branch: introduce --list argument Michael J Gruber
  2011-04-27 17:10 ` [RFC/PATCH 0/2] RFC/POC: patterns for branch list Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2011-04-27 12:15 UTC (permalink / raw)
  To: git

Allow pattern arguments for the list mode just like for git tag -l.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 builtin/branch.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 9cca1b9..10292ab 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -260,6 +260,7 @@ static char *resolve_symref(const char *src, const char *prefix)
 
 struct append_ref_cb {
 	struct ref_list *ref_list;
+	const char *pattern;
 	int ret;
 };
 
@@ -297,6 +298,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
 	if ((kind & ref_list->kinds) == 0)
 		return 0;
 
+	if (cb->pattern && fnmatch(cb->pattern, refname, 0))
+		return 0;
+
 	commit = NULL;
 	if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
 		commit = lookup_commit_reference_gently(sha1, 1);
@@ -494,7 +498,7 @@ static void show_detached(struct ref_list *ref_list)
 	}
 }
 
-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char *pattern)
 {
 	int i;
 	struct append_ref_cb cb;
@@ -508,6 +512,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 	if (merge_filter != NO_FILTER)
 		init_revisions(&ref_list.revs, NULL);
 	cb.ref_list = &ref_list;
+	cb.pattern = pattern;
 	cb.ret = 0;
 	for_each_rawref(append_ref, &cb);
 	if (merge_filter != NO_FILTER) {
@@ -525,7 +530,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 	qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
 
 	detached = (detached && (kinds & REF_LOCAL_BRANCH));
-	if (detached)
+	if (detached && (!pattern || !fnmatch(pattern, "HEAD", 0)))
 		show_detached(&ref_list);
 
 	for (i = 0; i < ref_list.index; i++) {
@@ -700,8 +705,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
 	if (delete)
 		return delete_branches(argc, argv, delete > 1, kinds);
-	else if (argc == 0)
-		return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+	else if (argc == 0 || (verbose && argc == 1))
+		return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argc ? argv[0] : NULL);
 	else if (rename && (argc == 1))
 		rename_branch(head, argv[0], rename > 1);
 	else if (rename && (argc == 2))
-- 
1.7.5.270.gafca7

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

* [RFC/PATCH 2/2] branch: introduce --list argument
  2011-04-27 12:15 [RFC/PATCH 0/2] RFC/POC: patterns for branch list Michael J Gruber
  2011-04-27 12:15 ` [RFC/PATCH 1/2] branch: allow pattern arguments Michael J Gruber
@ 2011-04-27 12:15 ` Michael J Gruber
  2011-04-27 17:10 ` [RFC/PATCH 0/2] RFC/POC: patterns for branch list Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2011-04-27 12:15 UTC (permalink / raw)
  To: git

Currently, there is no way to invoke the list mode with a pattern
because this is interpreted as branch creation.

Introduce a --list argument which invokes the list mode.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 builtin/branch.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 10292ab..4ccd89c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -619,7 +619,7 @@ static int opt_parse_merge_filter(const struct option *opt, const char *arg, int
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
 {
-	int delete = 0, rename = 0, force_create = 0;
+	int delete = 0, rename = 0, force_create = 0, list = 0;
 	int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
 	int reflog = 0;
 	enum branch_track track;
@@ -658,6 +658,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
 		OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
 		OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
+		OPT_BOOLEAN(0, "list", &list, "list branch names"),
 		OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
 		OPT__FORCE(&force_create, "force creation (when already exists)"),
 		{
@@ -700,12 +701,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
-	if (!!delete + !!rename + !!force_create > 1)
+	if (!!delete + !!rename + !!force_create + !!list > 1)
 		usage_with_options(builtin_branch_usage, options);
 
+	if (argc == 0 || (verbose && argc == 1))
+		list = 1;
+
 	if (delete)
 		return delete_branches(argc, argv, delete > 1, kinds);
-	else if (argc == 0 || (verbose && argc == 1))
+	else if (list)
 		return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argc ? argv[0] : NULL);
 	else if (rename && (argc == 1))
 		rename_branch(head, argv[0], rename > 1);
-- 
1.7.5.270.gafca7

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

* Re: [RFC/PATCH 0/2] RFC/POC: patterns for branch list
  2011-04-27 12:15 [RFC/PATCH 0/2] RFC/POC: patterns for branch list Michael J Gruber
  2011-04-27 12:15 ` [RFC/PATCH 1/2] branch: allow pattern arguments Michael J Gruber
  2011-04-27 12:15 ` [RFC/PATCH 2/2] branch: introduce --list argument Michael J Gruber
@ 2011-04-27 17:10 ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2011-04-27 17:10 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: git

Michael J Gruber <git@drmicha.warpmail.net> writes:

> This mini series is about introducing patterns to the list mode of
> 'git branch' much like the pattern for 'git tag -l'.

I do find myself often typing

    git branch | grep mg/

so this would be a welcome addition, even though the above is not too ugly
nor cumbersome.

> '-l' is the natural short option name for '--list'. This is taken for the
> rarely used or needed 'create reflog' option. I'd change the latter to
> '-g,--create-reflog' (cmp. log) and take '-l,--list' but know the reaction
> already.

My reaction would be "As the eventual goal, it is the right thing to
do---if we were writing git from scratch today, we would probably have
done so. Present a reasonable migration plan.".  Perhaps like this?

 1. Introduce "--create-reflog", and deprecate "-l".  Make "branch -l"
    emit warning and advise to use "--create-reflog" instead, but still
    act as a synonym for "--create-reflog".

    Introduce "--list" but without any short option.

    Ship 1.7.6 with these changes.

 2. Introduce "-g" as synonym for "--create-reflog".  Make "branch -l" die
    and advise to use "-g" or "--create-reflog" instead.

    Ship 1.7.X series after 1.7.7 with these changes.

 3. In 1.8.0, make "-l" a synonym for "--list".

> '-v' and '-vv' both take considerable time (because they need to walk).
> It makes more sense to have '-v' display cheap output (upstream name)
> and '-vv' add expensive output (ahead/behind info). '-vvv' could add super
> expensive info (ahead/equivalent/behind a la cherry-mark).

Probably.  Would it be a solution to deprecate "git branch -v" and make
the behaviour of "git branch -l -v{1,3}" as you described?

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

end of thread, other threads:[~2011-04-27 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-27 12:15 [RFC/PATCH 0/2] RFC/POC: patterns for branch list Michael J Gruber
2011-04-27 12:15 ` [RFC/PATCH 1/2] branch: allow pattern arguments Michael J Gruber
2011-04-27 12:15 ` [RFC/PATCH 2/2] branch: introduce --list argument Michael J Gruber
2011-04-27 17:10 ` [RFC/PATCH 0/2] RFC/POC: patterns for branch list Junio C Hamano

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