Skip to contentSkip to conversation

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

PATCH New Heiko Voigt 1 participant 1 message 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.

---

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

81 lines not on this page · raw message

Signature · 1 line
1.8.3.rc1.44.gb387c77