# [PATCH] branch: honor core.abbrev

8 messages from 2011-06-30 to 2011-07-02. Participants: Namhyung Kim, Jonathan Nieder, Andreas Schwab, Junio C Hamano.
Thread: https://gitlist.dev/t/27735

## Namhyung Kim, 2011-06-30 16:02

Subject: [PATCH] branch: honor core.abbrev
Message-ID: <1309449762-10476-1-git-send-email-namhyung@gmail.com>
URL: https://gitlist.dev/e/1309449762-10476-1-git-send-email-namhyung%40gmail.com

```
Honor 'core.abbrev' configuration unless user specifies the
length on command line. In order to do that, we need to set
'abbrev' to DEFAULT_ABBREV after config and command line
parsing done.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 Documentation/git-branch.txt |    1 +
 builtin/branch.c             |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index c50f189..906cccc 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -114,6 +114,7 @@ OPTIONS
 --abbrev=<length>::
 	Alter the sha1's minimum display length in the output listing.
 	The default value is 7.
+	(and can be overrided by the `core.abbrev` config option).
 
 --no-abbrev::
 	Display the full sha1s in the output listing rather than abbreviating them.
diff --git a/builtin/branch.c b/builtin/branch.c
index d6ab93b..5a15022 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -613,7 +613,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 verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
+	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
@@ -696,6 +696,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	if (!!delete + !!rename + !!force_create > 1)
 		usage_with_options(builtin_branch_usage, options);
 
+	if (abbrev == -1)
+		abbrev = DEFAULT_ABBREV;
+
 	if (delete)
 		return delete_branches(argc, argv, delete > 1, kinds);
 	else if (argc == 0)
-- 
1.7.6

```

## Jonathan Nieder, 2011-06-30 18:10

Subject: Re: [PATCH] branch: honor core.abbrev
Message-ID: <20110630181020.GA1128@elie>
URL: https://gitlist.dev/e/20110630181020.GA1128%40elie
In-Reply-To: <1309449762-10476-1-git-send-email-namhyung@gmail.com>

```
Namhyung Kim wrote:

> --- a/Documentation/git-branch.txt
> +++ b/Documentation/git-branch.txt
> @@ -114,6 +114,7 @@ OPTIONS
>  --abbrev=<length>::
>  	Alter the sha1's minimum display length in the output listing.
>  	The default value is 7.
> +	(and can be overrided by the `core.abbrev` config option).

Nitpicks: this would be clearer without the period after "7" and without
the parentheses around the following phrase.  s/overrided/overridden/.

> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -613,7 +613,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 verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
> +	int verbose = 0, abbrev = -1, detached = 0;

Yes.  (One meaningful "c89 -pedantic" warning down, several to go.)

Some squashable tests follow.  Maybe they can be useful.  Thanks for
fixing this.  

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t3203-branch-output.sh |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git i/t/t3203-branch-output.sh w/t/t3203-branch-output.sh
index 6b7c118e..87333b49 100755
--- i/t/t3203-branch-output.sh
+++ w/t/t3203-branch-output.sh
@@ -3,6 +3,17 @@
 test_description='git branch display tests'
 . ./test-lib.sh
 
+minimum_line_length () {
+	awk '
+		BEGIN { minlen = 99 }
+		{
+			if (length($1) < minlen)
+				minlen = length($1)
+		}
+		END { print minlen }
+	'
+}
+
 test_expect_success 'make commits' '
 	echo content >file &&
 	git add file &&
@@ -66,6 +77,24 @@ test_expect_success 'git branch -v shows branch summaries' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git branch -v --abbrev' '
+	echo 10 >expect &&
+	git branch -v --abbrev=10 >tmp &&
+	awk "{print \$(NF - 1)}" <tmp >commitids &&
+	minimum_line_length <commitids >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git branch -v respects [core] abbrev configuration' '
+	git config core.abbrev 9 &&
+	test_when_finished "git config --unset core.abbrev" &&
+	echo 9 >expect &&
+	git branch -v >tmp &&
+	awk "{print \$(NF - 1)}" <tmp >commitids &&
+	minimum_line_length <commitids >actual &&
+	test_cmp expect actual
+'
+
 cat >expect <<'EOF'
 * (no branch)
   branch-one

```

## Andreas Schwab, 2011-06-30 18:27

Subject: Re: [PATCH] branch: honor core.abbrev
Message-ID: <m2pqlvmayd.fsf@igel.home>
URL: https://gitlist.dev/e/m2pqlvmayd.fsf%40igel.home
In-Reply-To: <1309449762-10476-1-git-send-email-namhyung@gmail.com>

```
Namhyung Kim <namhyung@gmail.com> writes:

> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> index c50f189..906cccc 100644
> --- a/Documentation/git-branch.txt
> +++ b/Documentation/git-branch.txt
> @@ -114,6 +114,7 @@ OPTIONS
>  --abbrev=<length>::
>  	Alter the sha1's minimum display length in the output listing.
>  	The default value is 7.
> +	(and can be overrided by the `core.abbrev` config option).

overridden

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## Namhyung Kim, 2011-07-01 06:06

Subject: [PATCH v2] branch: honor core.abbrev
Message-ID: <1309500368-3729-1-git-send-email-namhyung@gmail.com>
URL: https://gitlist.dev/e/1309500368-3729-1-git-send-email-namhyung%40gmail.com
In-Reply-To: <20110630181020.GA1128@elie>

```
Honor 'core.abbrev' configuration unless user specifies the
length on command line. In order to do that, we need to set
'abbrev' to DEFAULT_ABBREV after config and command line
parsing done.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
Sorry for my bad English and thanks for pointing this out. :)

 Documentation/git-branch.txt |    3 ++-
 builtin/branch.c             |    5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index c50f189..507b8d0 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -113,7 +113,8 @@ OPTIONS
 
 --abbrev=<length>::
 	Alter the sha1's minimum display length in the output listing.
-	The default value is 7.
+	The default value is 7 and can be overridden by the `core.abbrev`
+	config option.
 
 --no-abbrev::
 	Display the full sha1s in the output listing rather than abbreviating them.
diff --git a/builtin/branch.c b/builtin/branch.c
index d6ab93b..5a15022 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -613,7 +613,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 verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
+	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
@@ -696,6 +696,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	if (!!delete + !!rename + !!force_create > 1)
 		usage_with_options(builtin_branch_usage, options);
 
+	if (abbrev == -1)
+		abbrev = DEFAULT_ABBREV;
+
 	if (delete)
 		return delete_branches(argc, argv, delete > 1, kinds);
 	else if (argc == 0)
-- 
1.7.6

```

## Namhyung Kim, 2011-07-01 06:10

Subject: Re: [PATCH] branch: honor core.abbrev
Message-ID: <1309500640.1310.53.camel@leonhard>
URL: https://gitlist.dev/e/1309500640.1310.53.camel%40leonhard
In-Reply-To: <m2pqlvmayd.fsf@igel.home>

```
2011-06-30 (목), 20:27 +0200, Andreas Schwab:
> Namhyung Kim <namhyung@gmail.com> writes:
> 
> > diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> > index c50f189..906cccc 100644
> > --- a/Documentation/git-branch.txt
> > +++ b/Documentation/git-branch.txt
> > @@ -114,6 +114,7 @@ OPTIONS
> >  --abbrev=<length>::
> >  	Alter the sha1's minimum display length in the output listing.
> >  	The default value is 7.
> > +	(and can be overrided by the `core.abbrev` config option).
> 
> overridden
> 
> Andreas.
> 

Fixed and resent.

Thanks.

-- 
Regards,
Namhyung Kim

```

## Junio C Hamano, 2011-07-01 18:21

Subject: Re: [PATCH v2] branch: honor core.abbrev
Message-ID: <7voc1doo8v.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7voc1doo8v.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1309500368-3729-1-git-send-email-namhyung@gmail.com>

```
Namhyung Kim <namhyung@gmail.com> writes:

> Honor 'core.abbrev' configuration unless user specifies the
> length on command line. In order to do that, we need to set

It is not clear from this description when "git branch" needs to even show
abbreviated object name.  I'll retitle it and/or reword the description to
hint that you are talking about "branch -v", but do you know of anything
in "git branch" that may be affected by this change other than "-v" output?

```

## Jonathan Nieder, 2011-07-01 19:05

Subject: Re: [PATCH v2] branch: honor core.abbrev
Message-ID: <20110701190558.GC8929@elie>
URL: https://gitlist.dev/e/20110701190558.GC8929%40elie
In-Reply-To: <7voc1doo8v.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano wrote:

> It is not clear from this description when "git branch" needs to even show
> abbreviated object name.  I'll retitle it and/or reword the description to
> hint that you are talking about "branch -v", but do you know of anything
> in "git branch" that may be affected by this change other than "-v" output?

I think it's just add_verbose_info.  "git branch" also uses
DEFAULT_ABBREV in the message

	Deleted branch topic (was 980ab98c).

but that is not currently affected by the --abbrev option.

```

## Jonathan Nieder, 2011-07-02 01:32

Subject: Re: [PATCH] branch: honor core.abbrev
Message-ID: <20110702013200.GA2374@elie>
URL: https://gitlist.dev/e/20110702013200.GA2374%40elie
In-Reply-To: <20110630181020.GA1128@elie>

```
Jonathan Nieder wrote:

> Some squashable tests follow.  Maybe they can be useful.  Thanks for
> fixing this.  
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
>  t/t3203-branch-output.sh |   29 +++++++++++++++++++++++++++++
>  1 files changed, 29 insertions(+), 0 deletions(-)

Are these not wanted?  Or are there improvements needed before they
can be included?

```
