diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt
index c04f62a54a1..a2d8c274c6a 100644
--- a/Documentation/config/core.txt
+++ b/Documentation/config/core.txt
@@ -101,6 +101,13 @@ core.untrackedCache::
`feature.manyFiles` is enabled which sets this setting to
`true` by default.
+core.usageAddSource::
+ Adds the source "<file>:<line>" numbers to usage messages
+ ("usage:", "fatal:", "error:", "warning:"). This setting is
+ primarily intended for those debugging or developing git
+ itself, or to compose a bug report against git itself (see
+ linkgit:git-bugreport[1]).
+
core.checkStat::
When missing or is set to `default`, many fields in the stat
structure are checked to detect if a file has been modifieddiff --git a/repo-settings.c b/repo-settings.c
index b93e91a212e..33eb582d590 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -10,6 +10,15 @@ static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
*dest = def;
}
+static void repo_cfg_bool_env(struct repository *r, const char *env,
+ const char *key, int *dest, int def)
+{
+ *dest = git_env_bool(env, -1);
+ if (*dest != -1)
+ return;
+ repo_cfg_bool(r, key, dest, def);
+}
+
void prepare_repo_settings(struct repository *r)
{
int experimental;@@ -45,6 +54,8 @@ void prepare_repo_settings(struct repository *r)
repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
+ repo_cfg_bool_env(r, "GIT_TEST_USAGE_ADD_SOURCE", "core.usageaddsource",
+ &r->settings.usage_add_source, 0);
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
/*
diff --git a/repository.h b/repository.h
index a057653981c..0e362f4adb2 100644
--- a/repository.h
+++ b/repository.h
@@ -41,6 +41,8 @@ struct repo_settings {
enum fetch_negotiation_setting fetch_negotiation_algorithm;
int core_multi_pack_index;
+
+ int usage_add_source;
};
struct repository {diff --git a/usage.c b/usage.c
index 62313862977..409f857a8f7 100644
--- a/usage.c
+++ b/usage.c
@@ -5,6 +5,7 @@
*/
#include "git-compat-util.h"
#include "cache.h"
+#include "config.h"
enum usage_kind {
USAGE_USAGE,@@ -14,6 +15,8 @@ enum usage_kind {
USAGE_BUG,
};
+static int dying;
+
static void vreportf(enum usage_kind kind,
const char *file, int line,
const char *err, va_list params)@@ -23,6 +26,24 @@ static void vreportf(enum usage_kind kind,
char msg[4096];
char *p, *pend = msg + sizeof(msg);
size_t prefix_len;
+ static int addln = -1;
+
+ if (addln < 0 && dying <= 1) {
+ struct repository *r = the_repository;
+ prepare_repo_settings(r);
+ addln = r->settings.usage_add_source;
+ } else if (addln < 0 && dying) {
+ /*
+ * We're already dying when trying to read our config,
+ * presumably via prepare_repo_settings(). Do a
+ * last-ditch effort of trying to get it from the
+ * environment.
+ */
+ const char *v = getenv("GIT_TEST_USAGE_ADD_SOURCE");
+ addln = v ? git_parse_maybe_bool(v) : 0;
+ if (addln < 1)
+ addln = 0;
+ }
switch (kind) {
case USAGE_USAGE:@@ -43,7 +64,7 @@ static void vreportf(enum usage_kind kind,
}
/* truncation via snprintf is OK here */
- if (kind == USAGE_BUG)
+ if (kind == USAGE_BUG || addln)
snprintf(prefix, sizeof(prefix), "%s%s:%d: ", prefix_i18n, file, line);
else
snprintf(prefix, sizeof(prefix), "%s", prefix_i18n);
@@ -123,7 +144,6 @@ static void warning_builtin(const char *file, int line, const char *warn, va_lis
static int die_is_recursing_builtin(void)
{
- static int dying;
/*
* Just an arbitrary number X where "a < x < b" where "a" is
* "maximum number of pthreads we'll ever plausibly spawn" and--
2.34.0.rc2.809.g11e21d44b24