[PATCH 0/2] Minor convinience feature: format.defaultTo

STALE3738d

7 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 0/2] Minor convinience feature: format.defaultTo

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:36

Hi,

This is inspired by merge.defaultToUpstream. Disclaimer: I have an
"fpm" alias for doing this (separate from "fp" for when I need to
generate patches against some other branch), which I'd like to get rid
of.

Thanks.

Ramkumar Ramachandra (2):
  completion: complete format.coverLetter
  format-patch: introduce format.defaultTo

 Documentation/config.txt               |  4 ++++
 builtin/log.c                          |  7 +++++++
 contrib/completion/git-completion.bash |  2 ++
 t/t4014-format-patch.sh                | 10 ++++++++++
 4 files changed, 23 insertions(+)

-- 
1.8.5.2.229.g4448466.dirty

[PATCH 1/2] completion: complete format.coverLetter

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:36

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 contrib/completion/git-completion.bash | 1 +
 1 file changed, 1 insertion(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 51c2dd4..39b81f7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1991,6 +1991,7 @@ _git_config ()
 		fetch.unpackLimit
 		format.attach
 		format.cc
+		format.coverLetter
 		format.headers
 		format.numbered
 		format.pretty
-- 
1.8.5.2.229.g4448466.dirty

[PATCH 2/2] format-patch: introduce format.defaultTo

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:36

A very common workflow for preparing patches involves working off a
topic branch and generating patches against 'master' to send off to the
maintainer. However, a plain

  $ git format-patch -o outgoing

is a no-op on a topic branch, and the user has to remember to specify
'master' explicitly everytime. Save the user the extra keystrokes by
introducing format.defaultTo which can contain the name of a branch
against which to base patches.

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 Documentation/config.txt               |  4 ++++
 builtin/log.c                          |  7 +++++++
 contrib/completion/git-completion.bash |  1 +
 t/t4014-format-patch.sh                | 10 ++++++++++
 4 files changed, 22 insertions(+)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index a405806..b90abd1 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1135,6 +1135,10 @@ format.coverLetter::
 	format-patch is invoked, but in addition can be set to "auto", to
 	generate a cover-letter only when there's more than one patch.
 
+format.defaultTo::
+	The name of a branch against which to generate patches by
+	default. You'd usually want this to be 'master'.
+
 filter.<driver>.clean::
 	The command which is used to convert the content of a worktree
 	file to a blob upon checkin.  See linkgit:gitattributes[5] for
diff --git a/builtin/log.c b/builtin/log.c
index b97373d..ebc419e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -674,6 +674,7 @@ static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
 static int config_cover_letter;
+static const char *config_defaultto;
 
 enum {
 	COVER_UNSET,
@@ -750,6 +751,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
 		return 0;
 	}
+	if (!strcmp(var, "format.defaultto"))
+		return git_config_string(&config_defaultto, var, value);
 
 	return git_log_config(var, value, cb);
 }
@@ -1324,6 +1327,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		die (_("--subject-prefix and -k are mutually exclusive."));
 	rev.preserve_subject = keep_subject;
 
+	if (argc < 2 && config_defaultto) {
+		argv[1] = config_defaultto;
+		argc++;
+	}
 	argc = setup_revisions(argc, argv, &rev, &s_r_opt);
 	if (argc > 1)
 		die (_("unrecognized argument: %s"), argv[1]);
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 39b81f7..75699d4 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1992,6 +1992,7 @@ _git_config ()
 		format.attach
 		format.cc
 		format.coverLetter
+		format.defaultTo
 		format.headers
 		format.numbered
 		format.pretty
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 73194b2..46c0337 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1370,4 +1370,14 @@ test_expect_success 'cover letter auto user override' '
 	test_line_count = 2 list
 '
 
+test_expect_success 'defaultTo side' '
+	mkdir -p tmp &&
+	test_when_finished "rm -rf tmp;
+		git config --unset format.defaultTo" &&
+
+	git config format.defaultTo side &&
+	git format-patch -o tmp >list &&
+	test_line_count = 3 list
+'
+
 test_done
-- 
1.8.5.2.229.g4448466.dirty

Re: [PATCH 0/2] Minor convinience feature: format.defaultTo

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:36

Ramkumar Ramachandra wrote:
Ramkumar Ramachandra (2):
  completion: complete format.coverLetter
  format-patch: introduce format.defaultTo
Any thoughts on checkout.defaultTo? I have a "com" alias to checkout 'master'.

Re: [PATCH 2/2] format-patch: introduce format.defaultTo

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:59:36

Hi,

Ramkumar Ramachandra wrote:
                     a plain

  $ git format-patch -o outgoing

is a no-op on a topic branch, and the user has to remember to specify
'master' explicitly everytime. Save the user the extra keystrokes by
introducing format.defaultTo
Not excited.  Two reasons:

 1. Most config settings are in noun form: e.g.,
    "[remote] pushDefault = foo".  That makes their names easy to guess
    and makes them easy to talk about: I set the default remote for
    pushing by changing the remote.pushdefault setting.

    '[url "<foo>"] insteadOf' is an exception to that and a bit of an
    aberration.

    This new '[format] defaultTo' repeats the same end-with-a-preposition
    mistake, while I think it would be better to learn from it.

 2. Wouldn't a more natural default be @{u}..HEAD instead of relying on
    the user to do the make-work of keeping a local branch that tracks
    master up to date?

Hope that helps,
Jonathan

Re: [PATCH 2/2] format-patch: introduce format.defaultTo

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:36

Jonathan Nieder wrote:
 1. Most config settings are in noun form: e.g.,
    "[remote] pushDefault = foo".  That makes their names easy to guess
    and makes them easy to talk about: I set the default remote for
    pushing by changing the remote.pushdefault setting.

    '[url "<foo>"] insteadOf' is an exception to that and a bit of an
    aberration.

    This new '[format] defaultTo' repeats the same end-with-a-preposition
    mistake, while I think it would be better to learn from it.
I agree that it's somewhat unconventional to allow people to put a
<revision> as a configuration variable value, but I think it's useful.
url.<url>.insteadOf is incredibly useful, for instance.
 2. Wouldn't a more natural default be @{u}..HEAD instead of relying on
    the user to do the make-work of keeping a local branch that tracks
    master up to date?
Like I said in my message to Junio, @{u} is not necessarily the "best"
default for all workflows, although you can fill that into
format.defaultTo.

Re: [PATCH 1/2] completion: complete format.coverLetter

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:59:37

Ramkumar Ramachandra wrote:
 contrib/completion/git-completion.bash | 1 +
 1 file changed, 1 insertion(+)
Junio: Please push this part via 'maint' independently.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help