All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] teach the user to be nice to git and let him say please sometimes
@ 2013-05-11 20:20 Heiko Voigt
  2013-05-12 10:07 ` Ramkumar Ramachandra
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Heiko Voigt @ 2013-05-11 20:20 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Since ages we do not care about our program enough. Lets not treat them
as slaves anymore and say please.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Johan Herland <johan@herland.net>
---
 .gitignore                       |  1 +
 Makefile                         |  1 +
 builtin.h                        |  1 +
 builtin/config.c                 | 23 ++-----------------
 builtin/please.c                 |  9 ++++++++
 cache.h                          |  1 +
 config.c                         | 23 +++++++++++++++++++
 contrib/completion/git-prompt.sh |  5 +++-
 git.c                            | 49 +++++++++++++++++++++++++++++++++++++++-
 9 files changed, 90 insertions(+), 23 deletions(-)
 create mode 100644 builtin/please.c

diff --git a/.gitignore b/.gitignore
index 6669bf0..28dd4cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,6 +105,7 @@
 /git-parse-remote
 /git-patch-id
 /git-peek-remote
+/git-please
 /git-prune
 /git-prune-packed
 /git-pull
diff --git a/Makefile b/Makefile
index 0f931a2..7e22cc0 100644
--- a/Makefile
+++ b/Makefile
@@ -943,6 +943,7 @@ BUILTIN_OBJS += builtin/pack-objects.o
 BUILTIN_OBJS += builtin/pack-redundant.o
 BUILTIN_OBJS += builtin/pack-refs.o
 BUILTIN_OBJS += builtin/patch-id.o
+BUILTIN_OBJS += builtin/please.o
 BUILTIN_OBJS += builtin/prune-packed.o
 BUILTIN_OBJS += builtin/prune.o
 BUILTIN_OBJS += builtin/push.o
diff --git a/builtin.h b/builtin.h
index faef559..6fe1d5f 100644
--- a/builtin.h
+++ b/builtin.h
@@ -105,6 +105,7 @@ extern int cmd_notes(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
 extern int cmd_patch_id(int argc, const char **argv, const char *prefix);
+extern int cmd_please(int argc, const char **argv, const char *prefix);
 extern int cmd_prune(int argc, const char **argv, const char *prefix);
 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
diff --git a/builtin/config.c b/builtin/config.c
index 33c9bf9..16b5152 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -364,27 +364,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
-	if (use_global_config) {
-		char *user_config = NULL;
-		char *xdg_config = NULL;
-
-		home_config_paths(&user_config, &xdg_config, "config");
-
-		if (!user_config)
-			/*
-			 * It is unknown if HOME/.gitconfig exists, so
-			 * we do not know if we should write to XDG
-			 * location; error out even if XDG_CONFIG_HOME
-			 * is set and points at a sane location.
-			 */
-			die("$HOME not set");
-
-		if (access_or_warn(user_config, R_OK) &&
-		    xdg_config && !access_or_warn(xdg_config, R_OK))
-			given_config_file = xdg_config;
-		else
-			given_config_file = user_config;
-	}
+	if (use_global_config)
+		given_config_file = git_user_config();
 	else if (use_system_config)
 		given_config_file = git_etc_gitconfig();
 	else if (use_local_config)
diff --git a/builtin/please.c b/builtin/please.c
new file mode 100644
index 0000000..aea8424
--- /dev/null
+++ b/builtin/please.c
@@ -0,0 +1,9 @@
+#include "builtin.h"
+#include "run-command.h"
+
+int cmd_please(int argc, const char **argv, const char *prefix)
+{
+	if (!strcmp(argv[1], "-h"))
+		usage("Sometimes");
+	return run_command_v_opt(argv+1, RUN_GIT_CMD);
+}
diff --git a/cache.h b/cache.h
index 94ca1ac..73a9caf 100644
--- a/cache.h
+++ b/cache.h
@@ -1164,6 +1164,7 @@ extern int git_config_set_multivar_in_file(const char *, const char *, const cha
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
+extern const char *git_user_config(void);
 extern int check_repository_format_version(const char *var, const char *value, void *cb);
 extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
diff --git a/config.c b/config.c
index aefd80b..8b3e473 100644
--- a/config.c
+++ b/config.c
@@ -935,6 +935,29 @@ const char *git_etc_gitconfig(void)
 	return system_wide;
 }
 
+const char *git_user_config(void)
+{
+	char *user_config = NULL;
+	char *xdg_config = NULL;
+
+	home_config_paths(&user_config, &xdg_config, "config");
+
+	if (!user_config)
+		/*
+		 * It is unknown if HOME/.gitconfig exists, so
+		 * we do not know if we should write to XDG
+		 * location; error out even if XDG_CONFIG_HOME
+		 * is set and points at a sane location.
+		 */
+		die("$HOME not set");
+
+	if (access_or_warn(user_config, R_OK) &&
+			xdg_config && !access_or_warn(xdg_config, R_OK))
+		return xdg_config;
+	else
+		return user_config;
+}
+
 int git_env_bool(const char *k, int def)
 {
 	const char *v = getenv(k);
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index eaf5c36..a455d72 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -241,6 +241,7 @@ __git_ps1 ()
 	local ps1pc_start='\u@\h:\w '
 	local ps1pc_end='\$ '
 	local printf_format=' (%s)'
+	export GIT_POLITENESS_CHECK_PASSED="Yes"
 
 	case "$#" in
 		2|3)	pcmode=yes
@@ -250,7 +251,8 @@ __git_ps1 ()
 		;;
 		0|1)	printf_format="${1:-$printf_format}"
 		;;
-		*)	return
+		*)      unset GIT_POLITENESS_CHECK_PASSED
+			return
 		;;
 	esac
 
@@ -409,4 +411,5 @@ __git_ps1 ()
 			printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
 		fi
 	fi
+	unset GIT_POLITENESS_CHECK_PASSED
 }
diff --git a/git.c b/git.c
index 1ada169..6c67cef 100644
--- a/git.c
+++ b/git.c
@@ -19,6 +19,8 @@ const char git_more_info_string[] =
 
 static struct startup_info git_startup_info;
 static int use_pager = -1;
+static int impolite_counter;
+static int polite_counter;
 
 static void commit_pager_choice(void) {
 	switch (use_pager) {
@@ -302,6 +304,48 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	return 0;
 }
 
+static int read_polite_counter(const char *key, const char *value, void *data)
+{
+	if (!strcmp(key, "user.impolite"))
+		impolite_counter = git_config_int(key, value);
+	else if (!strcmp(key, "user.polite"))
+		polite_counter = git_config_int(key, value);
+	return 0;
+}
+
+static void check_politeness(const char *cmd)
+{
+	const char *user_config;
+	struct strbuf buf = STRBUF_INIT;
+
+	if (getenv("GIT_POLITENESS_CHECK_PASSED"))
+		return;
+
+	setenv("GIT_POLITENESS_CHECK_PASSED", "Yes", 1);
+
+	git_config_early(read_polite_counter, NULL, NULL);
+	if (!strcmp(cmd, "please")) {
+		impolite_counter = 0;
+		polite_counter++;
+	} else {
+		impolite_counter++;
+		polite_counter = 0;
+	}
+
+	if (impolite_counter > 10)
+		die("Error: Learn some manners, say please some time!");
+	if (polite_counter > 10)
+		die("Error: Too many please! I don't believe you.");
+
+	user_config = git_user_config();
+	strbuf_addf(&buf, "%d", polite_counter);
+	git_config_set_in_file(user_config, "user.polite", buf.buf);
+	strbuf_reset(&buf);
+	strbuf_addf(&buf, "%d", impolite_counter);
+	git_config_set_in_file(user_config, "user.impolite", buf.buf);
+	strbuf_release(&buf);
+}
+
 static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
@@ -379,6 +423,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "patch-id", cmd_patch_id },
 		{ "peek-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
 		{ "pickaxe", cmd_blame, RUN_SETUP },
+		{ "please", cmd_please, RUN_SETUP_GENTLY },
 		{ "prune", cmd_prune, RUN_SETUP },
 		{ "prune-packed", cmd_prune_packed, RUN_SETUP },
 		{ "push", cmd_push, RUN_SETUP },
@@ -441,8 +486,11 @@ static void handle_internal_command(int argc, const char **argv)
 
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		struct cmd_struct *p = commands+i;
+
 		if (strcmp(p->cmd, cmd))
 			continue;
+
+		check_politeness(cmd);
 		exit(run_builtin(p, argc, argv));
 	}
 }
-- 
1.8.3.rc1.44.gb387c77

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-11 20:20 [PATCH] teach the user to be nice to git and let him say please sometimes Heiko Voigt
@ 2013-05-12 10:07 ` Ramkumar Ramachandra
  2013-05-12 10:23 ` Duy Nguyen
  2013-05-12 21:19 ` Junio C Hamano
  2 siblings, 0 replies; 10+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-12 10:07 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: git, Junio C Hamano

Heiko Voigt wrote:
> Since ages we do not care about our program enough. Lets not treat them
> as slaves anymore and say please.

>  9 files changed, 90 insertions(+), 23 deletions(-)

Um, why such an elaborate joke?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-11 20:20 [PATCH] teach the user to be nice to git and let him say please sometimes Heiko Voigt
  2013-05-12 10:07 ` Ramkumar Ramachandra
@ 2013-05-12 10:23 ` Duy Nguyen
  2013-05-13 13:30   ` Heiko Voigt
  2013-05-12 21:19 ` Junio C Hamano
  2 siblings, 1 reply; 10+ messages in thread
From: Duy Nguyen @ 2013-05-12 10:23 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Git Mailing List, Junio C Hamano

On Sun, May 12, 2013 at 3:20 AM, Heiko Voigt <hvoigt@hvoigt.net> wrote:
> Since ages we do not care about our program enough. Lets not treat them
> as slaves anymore and say please.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
> Signed-off-by: Johan Herland <johan@herland.net>

A product of Git Berlin Meetup?

> +static void check_politeness(const char *cmd)
> +{
> +       const char *user_config;
> +       struct strbuf buf = STRBUF_INIT;
> +
> +       if (getenv("GIT_POLITENESS_CHECK_PASSED"))
> +               return;
> +
> +       setenv("GIT_POLITENESS_CHECK_PASSED", "Yes", 1);
> +
> +       git_config_early(read_polite_counter, NULL, NULL);
> +       if (!strcmp(cmd, "please")) {
> +               impolite_counter = 0;
> +               polite_counter++;
> +       } else {
> +               impolite_counter++;
> +               polite_counter = 0;
> +       }
> +
> +       if (impolite_counter > 10)
> +               die("Error: Learn some manners, say please some time!");
> +       if (polite_counter > 10)
> +               die("Error: Too many please! I don't believe you.");

NAK. If we truly care, we need better AI here!

> +
> +       user_config = git_user_config();
> +       strbuf_addf(&buf, "%d", polite_counter);
> +       git_config_set_in_file(user_config, "user.polite", buf.buf);
> +       strbuf_reset(&buf);
> +       strbuf_addf(&buf, "%d", impolite_counter);
> +       git_config_set_in_file(user_config, "user.impolite", buf.buf);
> +       strbuf_release(&buf);
> +}
--
Duy

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-11 20:20 [PATCH] teach the user to be nice to git and let him say please sometimes Heiko Voigt
  2013-05-12 10:07 ` Ramkumar Ramachandra
  2013-05-12 10:23 ` Duy Nguyen
@ 2013-05-12 21:19 ` Junio C Hamano
  2013-05-13 13:44   ` Heiko Voigt
  2 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2013-05-12 21:19 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: git

Heiko Voigt <hvoigt@hvoigt.net> writes:

> Since ages we do not care about our program enough. Lets not treat them
> as slaves anymore and say please.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
> Signed-off-by: Johan Herland <johan@herland.net>

So these were the ones present on the dev-day?

I actually would have expected, from the "please" title, the
opposite, us saying "please" to the user, either once in a while in
the advice messages we give to them, or perhaps in the en_POLITE
locale ;-)

>  .gitignore                       |  1 +
>  Makefile                         |  1 +
>  builtin.h                        |  1 +
>  builtin/config.c                 | 23 ++-----------------
>  builtin/please.c                 |  9 ++++++++
>  cache.h                          |  1 +
>  config.c                         | 23 +++++++++++++++++++
>  contrib/completion/git-prompt.sh |  5 +++-
>  git.c                            | 49 +++++++++++++++++++++++++++++++++++++++-

There is no test to protect this feature from future breakages?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-12 10:23 ` Duy Nguyen
@ 2013-05-13 13:30   ` Heiko Voigt
  2013-05-13 13:58     ` Duy Nguyen
  0 siblings, 1 reply; 10+ messages in thread
From: Heiko Voigt @ 2013-05-13 13:30 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List, Junio C Hamano

On Sun, May 12, 2013 at 05:23:15PM +0700, Duy Nguyen wrote:
> On Sun, May 12, 2013 at 3:20 AM, Heiko Voigt <hvoigt@hvoigt.net> wrote:
> > Since ages we do not care about our program enough. Lets not treat them
> > as slaves anymore and say please.
> >
> > Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> > Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> > Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
> > Signed-off-by: Johan Herland <johan@herland.net>
> 
> A product of Git Berlin Meetup?

Yep :-)

> > +static void check_politeness(const char *cmd)
> > +{
> > +       const char *user_config;
> > +       struct strbuf buf = STRBUF_INIT;
> > +
> > +       if (getenv("GIT_POLITENESS_CHECK_PASSED"))
> > +               return;
> > +
> > +       setenv("GIT_POLITENESS_CHECK_PASSED", "Yes", 1);
> > +
> > +       git_config_early(read_polite_counter, NULL, NULL);
> > +       if (!strcmp(cmd, "please")) {
> > +               impolite_counter = 0;
> > +               polite_counter++;
> > +       } else {
> > +               impolite_counter++;
> > +               polite_counter = 0;
> > +       }
> > +
> > +       if (impolite_counter > 10)
> > +               die("Error: Learn some manners, say please some time!");
> > +       if (polite_counter > 10)
> > +               die("Error: Too many please! I don't believe you.");
> 
> NAK. If we truly care, we need better AI here!

I agree but this patches goal was to implement the basic politeness
infrastructure. We planned to add more features, like inter-repository
jealousy, later. For inter-repository jealousy git would complain if you
worked more with one repository than others you cloned and you'd for
example sometimes need a double please to satisfy it.

Cheers Heiko

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-12 21:19 ` Junio C Hamano
@ 2013-05-13 13:44   ` Heiko Voigt
  2013-05-13 20:40     ` Thomas Rast
  0 siblings, 1 reply; 10+ messages in thread
From: Heiko Voigt @ 2013-05-13 13:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Sun, May 12, 2013 at 02:19:34PM -0700, Junio C Hamano wrote:
> Heiko Voigt <hvoigt@hvoigt.net> writes:
> 
> > Since ages we do not care about our program enough. Lets not treat them
> > as slaves anymore and say please.
> >
> > Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> > Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> > Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
> > Signed-off-by: Johan Herland <johan@herland.net>
> 
> So these were the ones present on the dev-day?

No this was just a random sample of the ones sitting at the same
beer garden table that this feature was implemented on.

> I actually would have expected, from the "please" title, the
> opposite, us saying "please" to the user, either once in a while in
> the advice messages we give to them, or perhaps in the en_POLITE
> locale ;-)

The en_POLITE is also a nice idea :-) We could split up the work on the
translations amongst all people joining a git meetup.

> >  .gitignore                       |  1 +
> >  Makefile                         |  1 +
> >  builtin.h                        |  1 +
> >  builtin/config.c                 | 23 ++-----------------
> >  builtin/please.c                 |  9 ++++++++
> >  cache.h                          |  1 +
> >  config.c                         | 23 +++++++++++++++++++
> >  contrib/completion/git-prompt.sh |  5 +++-
> >  git.c                            | 49 +++++++++++++++++++++++++++++++++++++++-
> 
> There is no test to protect this feature from future breakages?

In fact the whole testsuite should fail after the first 10 tests if you said
please right before running it. So since battery life is short and this
feature so important we did not bother to fix that. We already had
enough please complaints during intermediate commits and entering the
signed-off messages. It is really annoying, you should try this patch! ;-)
And it is especially unuseful when you are committing using git gui.

Cheers Heiko

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-13 13:30   ` Heiko Voigt
@ 2013-05-13 13:58     ` Duy Nguyen
  0 siblings, 0 replies; 10+ messages in thread
From: Duy Nguyen @ 2013-05-13 13:58 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Git Mailing List, Junio C Hamano

On Mon, May 13, 2013 at 8:30 PM, Heiko Voigt <hvoigt@hvoigt.net> wrote:
>> > +       if (impolite_counter > 10)
>> > +               die("Error: Learn some manners, say please some time!");
>> > +       if (polite_counter > 10)
>> > +               die("Error: Too many please! I don't believe you.");
>>
>> NAK. If we truly care, we need better AI here!
>
> I agree but this patches goal was to implement the basic politeness
> infrastructure. We planned to add more features, like inter-repository
> jealousy, later. For inter-repository jealousy git would complain if you
> worked more with one repository than others you cloned and you'd for
> example sometimes need a double please to satisfy it.

I'm still not happy with this direction. I propose we rewrite C Git in
Lisp first as a preparation step for git-please improvements. We could
drop support for all platforms but Lisp Machine along the way. That
would make all other Git implementations jealous.
--
Duy

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-13 13:44   ` Heiko Voigt
@ 2013-05-13 20:40     ` Thomas Rast
  2013-05-13 20:47       ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Rast @ 2013-05-13 20:40 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Junio C Hamano, git

Heiko Voigt <hvoigt@hvoigt.net> writes:

> On Sun, May 12, 2013 at 02:19:34PM -0700, Junio C Hamano wrote:
>> Heiko Voigt <hvoigt@hvoigt.net> writes:
>> 
>> > Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
>> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>> > Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
>> > Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
>> > Signed-off-by: Johan Herland <johan@herland.net>
>> 
>> So these were the ones present on the dev-day?
>
> No this was just a random sample of the ones sitting at the same
> beer garden table that this feature was implemented on.

Also see

  http://thomasrast.ch/pix/foss/20130509_gitmerge/DSC_7078.jpg.php

for an illustration of the history of this patch.

</plug>

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] teach the user to be nice to git and let him say please sometimes
  2013-05-13 20:40     ` Thomas Rast
@ 2013-05-13 20:47       ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2013-05-13 20:47 UTC (permalink / raw)
  To: Thomas Rast; +Cc: Heiko Voigt, git

Thomas Rast <trast@inf.ethz.ch> writes:

> Heiko Voigt <hvoigt@hvoigt.net> writes:
>
>> On Sun, May 12, 2013 at 02:19:34PM -0700, Junio C Hamano wrote:
>>> Heiko Voigt <hvoigt@hvoigt.net> writes:
>>> 
>>> > Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
>>> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>>> > Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
>>> > Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
>>> > Signed-off-by: Johan Herland <johan@herland.net>
>>> 
>>> So these were the ones present on the dev-day?
>>
>> No this was just a random sample of the ones sitting at the same
>> beer garden table that this feature was implemented on.
>
> Also see
>
>   http://thomasrast.ch/pix/foss/20130509_gitmerge/DSC_7078.jpg.php
>
> for an illustration of the history of this patch.
>
> </plug>

Thanks for sharing. I see some familiar faces.  Envy, envy...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] teach the user to be nice to git and let him say please sometimes
@ 2013-05-12  7:26 Heiko Voigt
  0 siblings, 0 replies; 10+ messages in thread
From: Heiko Voigt @ 2013-05-12  7:26 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Since ages we do not care about our program enough. Lets not treat them
as slaves anymore and say please.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Johan Herland <johan@herland.net>
---

I do not know why this very urgent patch did not make it to the
mailinglist yesterday evening. Well here is a resend.

 .gitignore                       |  1 +
 Makefile                         |  1 +
 builtin.h                        |  1 +
 builtin/config.c                 | 23 ++-----------------
 builtin/please.c                 |  9 ++++++++
 cache.h                          |  1 +
 config.c                         | 23 +++++++++++++++++++
 contrib/completion/git-prompt.sh |  5 +++-
 git.c                            | 49 +++++++++++++++++++++++++++++++++++++++-
 9 files changed, 90 insertions(+), 23 deletions(-)
 create mode 100644 builtin/please.c

diff --git a/.gitignore b/.gitignore
index 6669bf0..28dd4cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,6 +105,7 @@
 /git-parse-remote
 /git-patch-id
 /git-peek-remote
+/git-please
 /git-prune
 /git-prune-packed
 /git-pull
diff --git a/Makefile b/Makefile
index 0f931a2..7e22cc0 100644
--- a/Makefile
+++ b/Makefile
@@ -943,6 +943,7 @@ BUILTIN_OBJS += builtin/pack-objects.o
 BUILTIN_OBJS += builtin/pack-redundant.o
 BUILTIN_OBJS += builtin/pack-refs.o
 BUILTIN_OBJS += builtin/patch-id.o
+BUILTIN_OBJS += builtin/please.o
 BUILTIN_OBJS += builtin/prune-packed.o
 BUILTIN_OBJS += builtin/prune.o
 BUILTIN_OBJS += builtin/push.o
diff --git a/builtin.h b/builtin.h
index faef559..6fe1d5f 100644
--- a/builtin.h
+++ b/builtin.h
@@ -105,6 +105,7 @@ extern int cmd_notes(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
 extern int cmd_patch_id(int argc, const char **argv, const char *prefix);
+extern int cmd_please(int argc, const char **argv, const char *prefix);
 extern int cmd_prune(int argc, const char **argv, const char *prefix);
 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
diff --git a/builtin/config.c b/builtin/config.c
index 33c9bf9..16b5152 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -364,27 +364,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
-	if (use_global_config) {
-		char *user_config = NULL;
-		char *xdg_config = NULL;
-
-		home_config_paths(&user_config, &xdg_config, "config");
-
-		if (!user_config)
-			/*
-			 * It is unknown if HOME/.gitconfig exists, so
-			 * we do not know if we should write to XDG
-			 * location; error out even if XDG_CONFIG_HOME
-			 * is set and points at a sane location.
-			 */
-			die("$HOME not set");
-
-		if (access_or_warn(user_config, R_OK) &&
-		    xdg_config && !access_or_warn(xdg_config, R_OK))
-			given_config_file = xdg_config;
-		else
-			given_config_file = user_config;
-	}
+	if (use_global_config)
+		given_config_file = git_user_config();
 	else if (use_system_config)
 		given_config_file = git_etc_gitconfig();
 	else if (use_local_config)
diff --git a/builtin/please.c b/builtin/please.c
new file mode 100644
index 0000000..aea8424
--- /dev/null
+++ b/builtin/please.c
@@ -0,0 +1,9 @@
+#include "builtin.h"
+#include "run-command.h"
+
+int cmd_please(int argc, const char **argv, const char *prefix)
+{
+	if (!strcmp(argv[1], "-h"))
+		usage("Sometimes");
+	return run_command_v_opt(argv+1, RUN_GIT_CMD);
+}
diff --git a/cache.h b/cache.h
index 94ca1ac..73a9caf 100644
--- a/cache.h
+++ b/cache.h
@@ -1164,6 +1164,7 @@ extern int git_config_set_multivar_in_file(const char *, const char *, const cha
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
+extern const char *git_user_config(void);
 extern int check_repository_format_version(const char *var, const char *value, void *cb);
 extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
diff --git a/config.c b/config.c
index aefd80b..8b3e473 100644
--- a/config.c
+++ b/config.c
@@ -935,6 +935,29 @@ const char *git_etc_gitconfig(void)
 	return system_wide;
 }
 
+const char *git_user_config(void)
+{
+	char *user_config = NULL;
+	char *xdg_config = NULL;
+
+	home_config_paths(&user_config, &xdg_config, "config");
+
+	if (!user_config)
+		/*
+		 * It is unknown if HOME/.gitconfig exists, so
+		 * we do not know if we should write to XDG
+		 * location; error out even if XDG_CONFIG_HOME
+		 * is set and points at a sane location.
+		 */
+		die("$HOME not set");
+
+	if (access_or_warn(user_config, R_OK) &&
+			xdg_config && !access_or_warn(xdg_config, R_OK))
+		return xdg_config;
+	else
+		return user_config;
+}
+
 int git_env_bool(const char *k, int def)
 {
 	const char *v = getenv(k);
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index eaf5c36..a455d72 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -241,6 +241,7 @@ __git_ps1 ()
 	local ps1pc_start='\u@\h:\w '
 	local ps1pc_end='\$ '
 	local printf_format=' (%s)'
+	export GIT_POLITENESS_CHECK_PASSED="Yes"
 
 	case "$#" in
 		2|3)	pcmode=yes
@@ -250,7 +251,8 @@ __git_ps1 ()
 		;;
 		0|1)	printf_format="${1:-$printf_format}"
 		;;
-		*)	return
+		*)      unset GIT_POLITENESS_CHECK_PASSED
+			return
 		;;
 	esac
 
@@ -409,4 +411,5 @@ __git_ps1 ()
 			printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
 		fi
 	fi
+	unset GIT_POLITENESS_CHECK_PASSED
 }
diff --git a/git.c b/git.c
index 1ada169..6c67cef 100644
--- a/git.c
+++ b/git.c
@@ -19,6 +19,8 @@ const char git_more_info_string[] =
 
 static struct startup_info git_startup_info;
 static int use_pager = -1;
+static int impolite_counter;
+static int polite_counter;
 
 static void commit_pager_choice(void) {
 	switch (use_pager) {
@@ -302,6 +304,48 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	return 0;
 }
 
+static int read_polite_counter(const char *key, const char *value, void *data)
+{
+	if (!strcmp(key, "user.impolite"))
+		impolite_counter = git_config_int(key, value);
+	else if (!strcmp(key, "user.polite"))
+		polite_counter = git_config_int(key, value);
+	return 0;
+}
+
+static void check_politeness(const char *cmd)
+{
+	const char *user_config;
+	struct strbuf buf = STRBUF_INIT;
+
+	if (getenv("GIT_POLITENESS_CHECK_PASSED"))
+		return;
+
+	setenv("GIT_POLITENESS_CHECK_PASSED", "Yes", 1);
+
+	git_config_early(read_polite_counter, NULL, NULL);
+	if (!strcmp(cmd, "please")) {
+		impolite_counter = 0;
+		polite_counter++;
+	} else {
+		impolite_counter++;
+		polite_counter = 0;
+	}
+
+	if (impolite_counter > 10)
+		die("Error: Learn some manners, say please some time!");
+	if (polite_counter > 10)
+		die("Error: Too many please! I don't believe you.");
+
+	user_config = git_user_config();
+	strbuf_addf(&buf, "%d", polite_counter);
+	git_config_set_in_file(user_config, "user.polite", buf.buf);
+	strbuf_reset(&buf);
+	strbuf_addf(&buf, "%d", impolite_counter);
+	git_config_set_in_file(user_config, "user.impolite", buf.buf);
+	strbuf_release(&buf);
+}
+
 static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
@@ -379,6 +423,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "patch-id", cmd_patch_id },
 		{ "peek-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
 		{ "pickaxe", cmd_blame, RUN_SETUP },
+		{ "please", cmd_please, RUN_SETUP_GENTLY },
 		{ "prune", cmd_prune, RUN_SETUP },
 		{ "prune-packed", cmd_prune_packed, RUN_SETUP },
 		{ "push", cmd_push, RUN_SETUP },
@@ -441,8 +486,11 @@ static void handle_internal_command(int argc, const char **argv)
 
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		struct cmd_struct *p = commands+i;
+
 		if (strcmp(p->cmd, cmd))
 			continue;
+
+		check_politeness(cmd);
 		exit(run_builtin(p, argc, argv));
 	}
 }
@@ -506,7 +554,6 @@ static int run_argv(int *argcp, const char ***argv)
 	return done_alias;
 }
 
-
 int main(int argc, const char **argv)
 {
 	const char *cmd;
-- 
1.8.3.rc1.44.gb387c77

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-05-13 20:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-11 20:20 [PATCH] teach the user to be nice to git and let him say please sometimes Heiko Voigt
2013-05-12 10:07 ` Ramkumar Ramachandra
2013-05-12 10:23 ` Duy Nguyen
2013-05-13 13:30   ` Heiko Voigt
2013-05-13 13:58     ` Duy Nguyen
2013-05-12 21:19 ` Junio C Hamano
2013-05-13 13:44   ` Heiko Voigt
2013-05-13 20:40     ` Thomas Rast
2013-05-13 20:47       ` Junio C Hamano
2013-05-12  7:26 Heiko Voigt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.