git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Nanako Shiraishi <nanako3@lavabit.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Matthieu Moy <Matthieu.Moy@imag.fr>,
	Teemu Likonen <tlikonen@iki.fi>,
	git@vger.kernel.org
Subject: [PATCH 3/4] push: make non-fast-forward help message configurable
Date: Sun, 6 Sep 2009 02:48:16 -0400	[thread overview]
Message-ID: <20090906064816.GC28941@coredump.intra.peff.net> (raw)
In-Reply-To: <20090906064454.GA1643@coredump.intra.peff.net>

This message is designed to help new users understand what
has happened when refs fail to push. However, it does not
help experienced users at all, and significantly clutters
the output, frequently dwarfing the regular status table and
making it harder to see.

This patch introduces a general configuration mechanism for
optional messages, with this push message as the first
example.

Signed-off-by: Jeff King <peff@peff.net>
---
Probably "messages" is too vague a term to use in the code and config.
Maybe "advice.*"?

 Documentation/config.txt |   16 ++++++++++++++++
 Makefile                 |    2 ++
 builtin-push.c           |    3 ++-
 cache.h                  |    1 +
 config.c                 |    3 +++
 messages.c               |   28 ++++++++++++++++++++++++++++
 messages.h               |   15 +++++++++++++++
 7 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 messages.c
 create mode 100644 messages.h

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5256c7f..ec308a6 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1201,6 +1201,22 @@ mergetool.keepTemporaries::
 mergetool.prompt::
 	Prompt before each invocation of the merge resolution program.
 
+message.all::
+	When set to 'true', display all optional help messages. When set
+	to 'false', do not display any. Defaults vary with individual
+	messages (see message.* below).
+
+message.*::
+	When set to 'true', display the given optional help message.
+	When set to 'false', do not display. The configuration variables
+	are:
++
+--
+	pushNonFastForward::
+		Help message shown when linkgit:git-push[1] refuses
+		non-fast-forward refs. Default: true.
+--
+
 pack.window::
 	The size of the window used by linkgit:git-pack-objects[1] when no
 	window size is given on the command line. Defaults to 10.
diff --git a/Makefile b/Makefile
index a614347..0785977 100644
--- a/Makefile
+++ b/Makefile
@@ -424,6 +424,7 @@ LIB_H += ll-merge.h
 LIB_H += log-tree.h
 LIB_H += mailmap.h
 LIB_H += merge-recursive.h
+LIB_H += messages.h
 LIB_H += object.h
 LIB_H += pack.h
 LIB_H += pack-refs.h
@@ -506,6 +507,7 @@ LIB_OBJS += mailmap.o
 LIB_OBJS += match-trees.o
 LIB_OBJS += merge-file.o
 LIB_OBJS += merge-recursive.o
+LIB_OBJS += messages.o
 LIB_OBJS += name-hash.o
 LIB_OBJS += object.o
 LIB_OBJS += pack-check.o
diff --git a/builtin-push.c b/builtin-push.c
index 787011f..dceac9f 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -157,7 +157,8 @@ static int do_push(const char *repo, int flags)
 			continue;
 
 		error("failed to push some refs to '%s'", url[i]);
-		if (nonfastforward) {
+		if (nonfastforward &&
+		    messages[MESSAGE_PUSH_NONFASTFORWARD].preference) {
 			printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
 			       "Merge the remote changes before pushing again.  See the 'non-fast forward'\n"
 			       "section of 'git push --help' for details.\n");
diff --git a/cache.h b/cache.h
index 5fad24c..32d1a27 100644
--- a/cache.h
+++ b/cache.h
@@ -4,6 +4,7 @@
 #include "git-compat-util.h"
 #include "strbuf.h"
 #include "hash.h"
+#include "messages.h"
 
 #include SHA1_HEADER
 #ifndef git_SHA_CTX
diff --git a/config.c b/config.c
index e87edea..aed1547 100644
--- a/config.c
+++ b/config.c
@@ -627,6 +627,9 @@ int git_default_config(const char *var, const char *value, void *dummy)
 	if (!prefixcmp(var, "mailmap."))
 		return git_default_mailmap_config(var, value);
 
+	if (!prefixcmp(var, "message."))
+		return git_default_message_config(var, value);
+
 	if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
 		pager_use_color = git_config_bool(var,value);
 		return 0;
diff --git a/messages.c b/messages.c
new file mode 100644
index 0000000..00fc196
--- /dev/null
+++ b/messages.c
@@ -0,0 +1,28 @@
+#include "cache.h"
+#include "messages.h"
+
+struct message_preference messages[] = {
+	{ "pushnonfastforward", 1 },
+};
+
+int git_default_message_config(const char *var, const char *value)
+{
+	const char *k = skip_prefix(var, "message.");
+	int i;
+
+	if (!strcmp(k, "all")) {
+		int v = git_config_bool(var, value);
+		for (i = 0; i < ARRAY_SIZE(messages); i++)
+			messages[i].preference = v;
+		return 0;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(messages); i++) {
+		if (strcmp(k, messages[i].name))
+			continue;
+		messages[i].preference = git_config_bool(var, value);
+		return 0;
+	}
+
+	return 0;
+}
diff --git a/messages.h b/messages.h
new file mode 100644
index 0000000..f175747
--- /dev/null
+++ b/messages.h
@@ -0,0 +1,15 @@
+#ifndef MESSAGE_H
+#define MESSAGE_H
+
+#define MESSAGE_PUSH_NONFASTFORWARD 0
+
+struct message_preference {
+	const char *name;
+	int preference;
+};
+
+extern struct message_preference messages[];
+
+int git_default_message_config(const char *var, const char *value);
+
+#endif /* MESSAGE_H */
-- 
1.6.4.2.266.g981efc.dirty

  parent reply	other threads:[~2009-09-06  6:48 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-06 17:32 [PATCH] push: point to 'git pull' and 'git push --force' in case of non-fast forward Matthieu Moy
2009-08-06 20:04 ` Michael J Gruber
2009-08-07 19:21   ` Matthieu Moy
2009-08-07 19:46     ` Michael J Gruber
2009-08-06 20:15 ` Junio C Hamano
2009-08-06 21:16   ` [PATCH] " Nicolas Sebrecht
2009-08-06 21:32     ` Junio C Hamano
2009-08-07 19:37   ` [PATCH] " Matthieu Moy
2009-08-07 20:05     ` Junio C Hamano
2009-08-07 20:22       ` Matthieu Moy
2009-08-08  7:51 ` [PATCH v2] " Matthieu Moy
2009-08-08  8:35   ` Teemu Likonen
2009-08-08 15:22     ` Matthieu Moy
2009-08-08 16:25       ` Junio C Hamano
2009-08-08 22:23         ` [PATCH v2] " Nicolas Sebrecht
2009-08-09 18:35         ` [PATCH v2] " Matthieu Moy
2009-08-09 20:22           ` Junio C Hamano
2009-08-10  8:43             ` Matthieu Moy
2009-08-10  8:49               ` Junio C Hamano
2009-08-10  8:56                 ` Matthieu Moy
2009-08-11  3:03         ` Nanako Shiraishi
2009-09-06  6:44           ` [RFC/PATCH 0/4] make helpful messages optional Jeff King
2009-09-06  6:46             ` [PATCH 1/4] push: fix english in non-fast-forward message Jeff King
2009-09-06  6:47             ` [PATCH 2/4] push: re-flow " Jeff King
2009-09-06  6:48             ` Jeff King [this message]
2009-09-06  7:09               ` [PATCH 3/4] push: make non-fast-forward help message configurable Junio C Hamano
2009-09-06  7:23                 ` Jeff King
2009-09-06  7:30                   ` Junio C Hamano
2009-09-06  7:32                     ` Jeff King
2009-09-06  7:52                   ` Junio C Hamano
2009-09-06 11:30                     ` Sverre Rabbelier
2009-09-07  0:44                     ` Nanako Shiraishi
2009-09-07  7:35                       ` Johannes Sixt
2009-09-07  7:40                       ` Mike Hommey
2009-09-07  8:24                       ` Jeff King
2009-09-07  8:34                         ` Matthieu Moy
2009-09-07  8:54                           ` Jeff King
2009-09-07 11:20                             ` Matthieu Moy
2009-09-08 18:51                             ` Uri Okrent
2009-09-09 11:22                               ` Jeff King
2009-09-09 11:26                   ` [PATCH 0/2] configurable advice messages Jeff King
2009-09-09 11:38                     ` [PATCH 1/2] push: make non-fast-forward help message configurable Jeff King
2009-09-09 19:06                       ` Junio C Hamano
2009-09-09 20:39                         ` Jeff King
2009-09-09 21:47                           ` Junio C Hamano
2009-09-09 11:43                     ` [PATCH 2/2] status: make "how to stage" messages optional Jeff King
2009-09-06  6:50             ` [PATCH 4/4] " Jeff King
2009-09-06 11:53             ` [RFC/PATCH 0/4] make helpful " Matthieu Moy

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

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

  git send-email \
    --in-reply-to=20090906064816.GC28941@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Matthieu.Moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nanako3@lavabit.com \
    --cc=tlikonen@iki.fi \
    /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.
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).