Skip to contentSkip to conversation

teach the user to be nice to git and let him say please sometimes

PATCH In review Heiko Voigt 5 participants 9 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 teach the user to be nice to git and let him say please sometimes

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

---
 .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
.gitignore +1 -0
index 6669bf0..28dd4cf 100644
@@ -105,6 +105,7 @@
 /git-parse-remote
 /git-patch-id
 /git-peek-remote
+/git-please
 /git-prune
 /git-prune-packed
 /git-pull
Makefile +1 -0
index 0f931a2..7e22cc0 100644
@@ -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
builtin.h +1 -0
index faef559..6fe1d5f 100644
@@ -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);
builtin/config.c +2 -21
index 33c9bf9..16b5152 100644
@@ -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)
builtin/please.c new file +9 -0
new file mode 100644
index 0000000..aea8424
@@ -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);
+}
cache.h +1 -0
index 94ca1ac..73a9caf 100644
@@ -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);
config.c +23 -0
index aefd80b..8b3e473 100644
@@ -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);
contrib/completion/git-prompt.sh +4 -1
index eaf5c36..a455d72 100644
@@ -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
 }
git.c +48 -0

74 lines not on this page · raw message

Signature · 1 line
1.8.3.rc1.44.gb387c77
#1 lore raw
Quoted 8 lines · Heiko Voigt

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

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 ;-)

Quoted 9 lines
 .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?

#2 lore raw

Hi,

Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Heiko Voigt

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

Quoted 7 lines
Quoted 5 lines

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.

Quoted 4 lines

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.

Quoted 11 lines
Quoted 9 lines
 .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

#3 lore raw
Quoted 9 lines · Heiko Voigt
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Heiko Voigt
Quoted 4 lines
Quoted 1 line

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>

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
#4 lore raw
Quoted 16 lines · Thomas Rast
Quoted 9 lines · Heiko Voigt
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Heiko Voigt
Quoted 4 lines
Quoted 1 line

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.

Quoted 7 lines

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...

#5 lore raw
In reply to Heiko Voigt
Quoted 8 lines · Heiko Voigt

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

A product of Git Berlin Meetup?

Quoted 13 lines
git.c +13 -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;

git.c static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · line 338

Quoted 10 lines
git.c +10 -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!

git.c static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · line 347

Quoted 9 lines
git.c +9 -0
+
+       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

#6 lore raw
Quoted 11 lines · Duy Nguyen
Quoted 8 lines · Heiko Voigt

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

A product of Git Berlin Meetup?

Yep :-)

Quoted 17 lines
Quoted 17 lines
git.c +17 -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;
Quoted 8 lines

git.c static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · line 338

Quoted 6 lines
git.c +6 -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

#7 lore raw
Quoted 5 lines · Heiko Voigt
Quoted 5 lines
Quoted 4 lines
git.c +4 -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.");
Quoted 7 lines
Quoted 1 line

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

#8 lore raw
In reply to Heiko Voigt
Quoted 4 lines · Heiko Voigt

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?