# [PATCH] bash completion: refactor diff options

8 messages from 2009-01-11 to 2009-01-20. Participants: Thomas Rast, Junio C Hamano, Shawn O. Pearce.
Thread: https://gitlist.dev/t/17085

## Thomas Rast, 2009-01-11 13:14

Subject: [PATCH] bash completion: refactor diff options
Message-ID: <1231679663-31907-1-git-send-email-trast@student.ethz.ch>
URL: https://gitlist.dev/e/1231679663-31907-1-git-send-email-trast%40student.ethz.ch

```
diff, log and show all take the same diff options.  Refactor them from
__git_diff and __git_log into a variable, and complete them in
__git_show too.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

---

This conflicts with the --patience series; I can send a version based
on that if it goes in first.


 contrib/completion/git-completion.bash |   38 ++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7b074d7..5017369 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -759,24 +759,29 @@ _git_describe ()
 	__gitcomp "$(__git_refs)"
 }
 
-_git_diff ()
-{
-	__git_has_doubledash && return
-
-	local cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	--*)
-		__gitcomp "--cached --stat --numstat --shortstat --summary
+__git_diff_common_options="--stat --numstat --shortstat --summary
 			--patch-with-stat --name-only --name-status --color
 			--no-color --color-words --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
-			--find-copies-harder --pickaxe-all --pickaxe-regex
+			--find-copies-harder
 			--text --ignore-space-at-eol --ignore-space-change
 			--ignore-all-space --exit-code --quiet --ext-diff
 			--no-ext-diff
 			--no-prefix --src-prefix= --dst-prefix=
-			--base --ours --theirs
 			--inter-hunk-context=
+			--raw
+"
+
+_git_diff ()
+{
+	__git_has_doubledash && return
+
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "--cached --pickaxe-all --pickaxe-regex
+			--base --ours --theirs
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -959,16 +964,15 @@ _git_log ()
 			--relative-date --date=
 			--author= --committer= --grep=
 			--all-match
-			--pretty= --name-status --name-only --raw
+			--pretty=
 			--not --all
 			--left-right --cherry-pick
 			--graph
-			--stat --numstat --shortstat
-			--decorate --diff-filter=
-			--color-words --walk-reflogs
+			--decorate
+			--walk-reflogs
 			--parents --children --full-history
 			--merge
-			--inter-hunk-context=
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -1473,7 +1477,9 @@ _git_show ()
 		return
 		;;
 	--*)
-		__gitcomp "--pretty="
+		__gitcomp "--pretty=
+			$__git_diff_common_options
+			"
 		return
 		;;
 	esac
-- 
tg: (7eb5bbd..) t/bash-complete-show (depends on: origin/master)

```

## Thomas Rast, 2009-01-12 09:16

Subject: [PATCH next] bash completion: refactor diff options
Message-ID: <1231751817-17688-1-git-send-email-trast@student.ethz.ch>
URL: https://gitlist.dev/e/1231751817-17688-1-git-send-email-trast%40student.ethz.ch
In-Reply-To: <1231679663-31907-1-git-send-email-trast@student.ethz.ch>

```
diff, log and show all take the same diff options.  Refactor them from
__git_diff and __git_log into a variable, and complete them in
__git_show too.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

---

js/patience-diff is now in next, so here's a version on top of that.


 contrib/completion/git-completion.bash |   38 ++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dee75b5..39ae7a3 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -759,25 +759,30 @@ _git_describe ()
 	__gitcomp "$(__git_refs)"
 }
 
-_git_diff ()
-{
-	__git_has_doubledash && return
-
-	local cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	--*)
-		__gitcomp "--cached --stat --numstat --shortstat --summary
+__git_diff_common_options="--stat --numstat --shortstat --summary
 			--patch-with-stat --name-only --name-status --color
 			--no-color --color-words --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
-			--find-copies-harder --pickaxe-all --pickaxe-regex
+			--find-copies-harder
 			--text --ignore-space-at-eol --ignore-space-change
 			--ignore-all-space --exit-code --quiet --ext-diff
 			--no-ext-diff
 			--no-prefix --src-prefix= --dst-prefix=
-			--base --ours --theirs
 			--inter-hunk-context=
 			--patience
+			--raw
+"
+
+_git_diff ()
+{
+	__git_has_doubledash && return
+
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "--cached --pickaxe-all --pickaxe-regex
+			--base --ours --theirs
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -960,17 +965,16 @@ _git_log ()
 			--relative-date --date=
 			--author= --committer= --grep=
 			--all-match
-			--pretty= --name-status --name-only --raw
+			--pretty=
 			--not --all
 			--left-right --cherry-pick
 			--graph
-			--stat --numstat --shortstat
-			--decorate --diff-filter=
-			--color-words --walk-reflogs
+			--decorate
+			--walk-reflogs
 			--parents --children --full-history
 			--merge
 			--inter-hunk-context=
-			--patience
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -1475,7 +1479,9 @@ _git_show ()
 		return
 		;;
 	--*)
-		__gitcomp "--pretty="
+		__gitcomp "--pretty=
+			$__git_diff_common_options
+			"
 		return
 		;;
 	esac
-- 
tg: (f5cbdbb..) t/bash-complete-show (depends on: origin/next)

```

## Thomas Rast, 2009-01-18 01:03

Subject: [PATCH next resend] bash completion: refactor diff options
Message-ID: <1232240603-11729-1-git-send-email-trast@student.ethz.ch>
URL: https://gitlist.dev/e/1232240603-11729-1-git-send-email-trast%40student.ethz.ch
In-Reply-To: <1231679663-31907-1-git-send-email-trast@student.ethz.ch>

```
diff, log and show all take the same diff options.  Refactor them from
__git_diff and __git_log into a variable, and complete them in
__git_show too.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

---

Any news on this?


 contrib/completion/git-completion.bash |   38 ++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 70a6b44..40e3a14 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -774,25 +774,30 @@ _git_describe ()
 	__gitcomp "$(__git_refs)"
 }
 
-_git_diff ()
-{
-	__git_has_doubledash && return
-
-	local cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	--*)
-		__gitcomp "--cached --stat --numstat --shortstat --summary
+__git_diff_common_options="--stat --numstat --shortstat --summary
 			--patch-with-stat --name-only --name-status --color
 			--no-color --color-words --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
-			--find-copies-harder --pickaxe-all --pickaxe-regex
+			--find-copies-harder
 			--text --ignore-space-at-eol --ignore-space-change
 			--ignore-all-space --exit-code --quiet --ext-diff
 			--no-ext-diff
 			--no-prefix --src-prefix= --dst-prefix=
-			--base --ours --theirs
 			--inter-hunk-context=
 			--patience
+			--raw
+"
+
+_git_diff ()
+{
+	__git_has_doubledash && return
+
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "--cached --pickaxe-all --pickaxe-regex
+			--base --ours --theirs
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -975,17 +980,16 @@ _git_log ()
 			--relative-date --date=
 			--author= --committer= --grep=
 			--all-match
-			--pretty= --name-status --name-only --raw
+			--pretty=
 			--not --all
 			--left-right --cherry-pick
 			--graph
-			--stat --numstat --shortstat
-			--decorate --diff-filter=
-			--color-words --walk-reflogs
+			--decorate
+			--walk-reflogs
 			--parents --children --full-history
 			--merge
 			--inter-hunk-context=
-			--patience
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -1490,7 +1494,9 @@ _git_show ()
 		return
 		;;
 	--*)
-		__gitcomp "--pretty="
+		__gitcomp "--pretty=
+			$__git_diff_common_options
+			"
 		return
 		;;
 	esac
-- 
tg: (7ff1443..) t/bash-complete-show (depends on: origin/next)

```

## Junio C Hamano, 2009-01-18 07:18

Subject: Re: [PATCH next resend] bash completion: refactor diff options
Message-ID: <7vtz7xytdo.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtz7xytdo.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1232240603-11729-1-git-send-email-trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> diff, log and show all take the same diff options.  Refactor them from
> __git_diff and __git_log into a variable, and complete them in
> __git_show too.
>
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
>
> ---
>
> Any news on this?

> +__git_diff_common_options="--stat --numstat --shortstat --summary
>  			--patch-with-stat --name-only --name-status --color
>  			--no-color --color-words --no-renames --check
>  			--full-index --binary --abbrev --diff-filter=
> -			--find-copies-harder --pickaxe-all --pickaxe-regex
> +			--find-copies-harder

The changes around pickaxe made me "Huh?".  For log pickaxe makes very
good sense but for a single diff it doesn't, yet the original seems to
have had them only on "git diff" and not on "git log", which feels wrong.

Other than that, I think the patch tries to achieve a great thing in the
longer term---we do not have to worry about common parts going out of sync
between diff and log family of commands.

```

## Shawn O. Pearce, 2009-01-19 17:31

Subject: Re: [PATCH next resend] bash completion: refactor diff options
Message-ID: <20090119173153.GB14053@spearce.org>
URL: https://gitlist.dev/e/20090119173153.GB14053%40spearce.org
In-Reply-To: <7vtz7xytdo.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> wrote:
> Thomas Rast <trast@student.ethz.ch> writes:
> 
> > +__git_diff_common_options="--stat --numstat --shortstat --summary
> >  			--patch-with-stat --name-only --name-status --color
> >  			--no-color --color-words --no-renames --check
> >  			--full-index --binary --abbrev --diff-filter=
> > -			--find-copies-harder --pickaxe-all --pickaxe-regex
> > +			--find-copies-harder
> 
> The changes around pickaxe made me "Huh?".  For log pickaxe makes very
> good sense but for a single diff it doesn't, yet the original seems to
> have had them only on "git diff" and not on "git log", which feels wrong.
> 
> Other than that, I think the patch tries to achieve a great thing in the
> longer term---we do not have to worry about common parts going out of sync
> between diff and log family of commands.

I agree completely.  The pickaxe stuff in current completion is
just plain wrong.  I'd like to see it fixed with this cleanup.
Maybe do it in two parts; fix the pickaxe options to be on log
and not diff, and then do the cleanup for the common options.

-- 
Shawn.

```

## Thomas Rast, 2009-01-19 21:17

Subject: [PATCH v2 1/2] bash completion: move pickaxe options to log
Message-ID: <1232399880-22036-1-git-send-email-trast@student.ethz.ch>
URL: https://gitlist.dev/e/1232399880-22036-1-git-send-email-trast%40student.ethz.ch
In-Reply-To: <20090119173153.GB14053@spearce.org>

```
Move the options --pickaxe-all and --pickaxe-regex to git-log, where
they make more sense than with git-diff.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

---

Shawn O. Pearce wrote:
> Junio C Hamano <gitster@pobox.com> wrote:
> > The changes around pickaxe made me "Huh?".  For log pickaxe makes very
> > good sense but for a single diff it doesn't, yet the original seems to
> > have had them only on "git diff" and not on "git log", which feels wrong.
> 
> I agree completely.  The pickaxe stuff in current completion is
> just plain wrong.  I'd like to see it fixed with this cleanup.
> Maybe do it in two parts; fix the pickaxe options to be on log
> and not diff, and then do the cleanup for the common options.

Good point.  Sorry for not noticing in the first place; I was too
focused on just getting git-show completion working ;-)


 contrib/completion/git-completion.bash |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 60497a4..b5d3bbb 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -784,7 +784,7 @@ _git_diff ()
 			--patch-with-stat --name-only --name-status --color
 			--no-color --color-words --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
-			--find-copies-harder --pickaxe-all --pickaxe-regex
+			--find-copies-harder
 			--text --ignore-space-at-eol --ignore-space-change
 			--ignore-all-space --exit-code --quiet --ext-diff
 			--no-ext-diff
@@ -986,6 +986,7 @@ _git_log ()
 			--parents --children --full-history
 			--merge
 			--inter-hunk-context=
+			--pickaxe-all --pickaxe-regex
 			"
 		return
 		;;
-- 
tg: (28da86a..) t/bash-complete-pickaxe (depends on: origin/master)

```

## Thomas Rast, 2009-01-19 21:18

Subject: [PATCH v2 2/2] bash completion: refactor diff options
Message-ID: <1232399880-22036-2-git-send-email-trast@student.ethz.ch>
URL: https://gitlist.dev/e/1232399880-22036-2-git-send-email-trast%40student.ethz.ch
In-Reply-To: <1232399880-22036-1-git-send-email-trast@student.ethz.ch>

```
diff, log and show all take the same diff options.  Refactor them from
__git_diff and __git_log into a variable, and complete them in
__git_show too.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

---
 contrib/completion/git-completion.bash |   36 ++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 096603b..bfae953 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -773,14 +773,7 @@ _git_describe ()
 	__gitcomp "$(__git_refs)"
 }
 
-_git_diff ()
-{
-	__git_has_doubledash && return
-
-	local cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	--*)
-		__gitcomp "--cached --stat --numstat --shortstat --summary
+__git_diff_common_options="--stat --numstat --shortstat --summary
 			--patch-with-stat --name-only --name-status --color
 			--no-color --color-words --no-renames --check
 			--full-index --binary --abbrev --diff-filter=
@@ -789,9 +782,21 @@ _git_diff ()
 			--ignore-all-space --exit-code --quiet --ext-diff
 			--no-ext-diff
 			--no-prefix --src-prefix= --dst-prefix=
-			--base --ours --theirs
 			--inter-hunk-context=
 			--patience
+			--raw
+"
+
+_git_diff ()
+{
+	__git_has_doubledash && return
+
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "--cached --pickaxe-all --pickaxe-regex
+			--base --ours --theirs
+			$__git_diff_common_options
 			"
 		return
 		;;
@@ -977,17 +982,16 @@ _git_log ()
 			--relative-date --date=
 			--author= --committer= --grep=
 			--all-match
-			--pretty= --name-status --name-only --raw
+			--pretty=
 			--not --all
 			--left-right --cherry-pick
 			--graph
-			--stat --numstat --shortstat
-			--decorate --diff-filter=
-			--color-words --walk-reflogs
+			--decorate
+			--walk-reflogs
 			--parents --children --full-history
 			--merge
 			--inter-hunk-context=
-			--patience
+			$__git_diff_common_options
 			--pickaxe-all --pickaxe-regex
 			"
 		return
@@ -1492,7 +1496,9 @@ _git_show ()
 		return
 		;;
 	--*)
-		__gitcomp "--pretty="
+		__gitcomp "--pretty=
+			$__git_diff_common_options
+			"
 		return
 		;;
 	esac
-- 
tg: (3f8c856..) t/bash-complete-show (depends on: origin/next t/bash-complete-pickaxe t/bash-complete-pickaxe)

```

## Junio C Hamano, 2009-01-20 08:36

Subject: Re: [PATCH v2 2/2] bash completion: refactor diff options
Message-ID: <7vwscqjrwh.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwscqjrwh.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1232399880-22036-2-git-send-email-trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> diff, log and show all take the same diff options.  Refactor them from
> __git_diff and __git_log into a variable, and complete them in
> __git_show too.
>
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
>
> ---
>  contrib/completion/git-completion.bash |   36 ++++++++++++++++++-------------
>  1 files changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 096603b..bfae953 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -773,14 +773,7 @@ _git_describe ()
>  	__gitcomp "$(__git_refs)"
>  }
>  
> -_git_diff ()
> -{
> -	__git_has_doubledash && return
> -
> -	local cur="${COMP_WORDS[COMP_CWORD]}"
> -	case "$cur" in
> -	--*)
> -		__gitcomp "--cached --stat --numstat --shortstat --summary
> +__git_diff_common_options="--stat --numstat --shortstat --summary
>  			--patch-with-stat --name-only --name-status --color
>  			--no-color --color-words --no-renames --check
>  			--full-index --binary --abbrev --diff-filter=
> @@ -789,9 +782,21 @@ _git_diff ()
>  			--ignore-all-space --exit-code --quiet --ext-diff
>  			--no-ext-diff
>  			--no-prefix --src-prefix= --dst-prefix=
> -			--base --ours --theirs
>  			--inter-hunk-context=
>  			--patience
> +			--raw
> +"
> +
> +_git_diff ()
> +{
> +	__git_has_doubledash && return
> +
> +	local cur="${COMP_WORDS[COMP_CWORD]}"
> +	case "$cur" in
> +	--*)
> +		__gitcomp "--cached --pickaxe-all --pickaxe-regex
> +			--base --ours --theirs
> +			$__git_diff_common_options
>  			"
>  		return
>  		;;
> @@ -977,17 +982,16 @@ _git_log ()
>  			--relative-date --date=
>  			--author= --committer= --grep=
>  			--all-match
> -			--pretty= --name-status --name-only --raw
> +			--pretty=
>  			--not --all
>  			--left-right --cherry-pick
>  			--graph
> -			--stat --numstat --shortstat
> -			--decorate --diff-filter=
> -			--color-words --walk-reflogs
> +			--decorate
> +			--walk-reflogs
>  			--parents --children --full-history
>  			--merge
>  			--inter-hunk-context=
> -			--patience
> +			$__git_diff_common_options
>  			--pickaxe-all --pickaxe-regex
>  			"

I'll tweak this part to drop duplicated --ihc; other than that it looked
good.  Thanks.

```
