git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Vincent van Ravesteijn <vfr@lyx.org>
To: "\"Kenta Murata (村田 賢太)\"" <mrkn@cookpad.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Introduce --current option to git-branch builtin command.
Date: Thu, 07 Jun 2012 10:43:17 +0200	[thread overview]
Message-ID: <4FD069A5.1040905@lyx.org> (raw)
In-Reply-To: <CAECJ0BmcxeS1q8bw4hN9jDja2g8GGzNyN_v7jC3ehOW70x6CRA@mail.gmail.com>

Op 7-6-2012 9:23, Kenta Murata (村田 賢太) schreef:
> Introducing --current option to git-branch builtin command.
> This option allows us to simply show the current branch name.

I don't know whether we would need such an option. To me it feels this 
is a missing option indeed, but at the same time you can use 'git 
status' or 'git branch' to see the current branch. It might be useful in 
case you have lots of branches and lots of untracked files, but in that 
case "git status | head -n1" or "git branch | grep '*'" would do the trick.

>
> ---
>   builtin/branch.c |   12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index 0e060f2..21e4675 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -19,6 +19,7 @@
>   #include "column.h"
>
>   static const char * const builtin_branch_usage[] = {
> +       "git branch --current",
>          "git branch [options] [-r | -a] [--merged | --no-merged]",
>          "git branch [options] [-l] [-f]<branchname>  [<start-point>]",
>          "git branch [options] [-r] (-d | -D)<branchname>...",

git-branch has four modes: 'list', 'create', 'delete', and 'rename'. 
Isn't --current then just another option to the 'list'-mode?  Then it 
would be  something like:

"git branch [options] [-r | -a] [--current] [--merged | --no-merged]"


> @@ -794,7 +796,7 @@ 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&&  !edit_description&&  argc == 0)
> +       if (!delete&&  !rename&&  !edit_description&&  !show_current
> &&  argc == 0)
>                  list = 1;

In line with what I wrote above, show_current should imply 'list'-mode.

>
>          if (!!delete + !!rename + !!force_create + !!list>  1)
> @@ -852,6 +854,12 @@ int cmd_branch(int argc, const char **argv, const
> char *prefix)
>                          rename_branch(argv[0], argv[1], rename>  1);
>                  else
>                          usage_with_options(builtin_branch_usage, options);
> +       } else if (show_current) {
> +               const char *branch_name = head;
> +               if (detached) {
> +                       branch_name = _("(no branch)");
> +               }
> +               printf("%s\n", branch_name);
>          } else if (argc>  0&&  argc<= 2) {
>                  if (kinds != REF_LOCAL_BRANCH)
>                          die(_("-a and -r options to 'git branch' do
> not make sense with a branch name"));

If '--current' implies the 'list'-mode, it would use 'print_ref_list'. 
There already is code in print_ref_list to detect whether a branch is 
the current one, it outputs the branch list in a formatted way, it takes 
care of 'columns', so wouldn't it be better to modify that code to only 
print the current branch ?

Vincent

  reply	other threads:[~2012-06-07  8:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-07  7:23 [PATCH] Introduce --current option to git-branch builtin command Kenta Murata (村田 賢太)
2012-06-07  8:43 ` Vincent van Ravesteijn [this message]
2012-06-07 17:11   ` Junio C Hamano
2012-06-07 11:18 ` konglu
2012-06-07 11:23 ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FD069A5.1040905@lyx.org \
    --to=vfr@lyx.org \
    --cc=git@vger.kernel.org \
    --cc=mrkn@cookpad.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).