mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'ps/undecided-is-not-necessarily-sha1'
Before discovering the repository details, We used to assume SHA-1 as the "default" hash function, which has been corrected. Hopefully this will smoke out codepaths that rely on such an unwarranted assumptions. * ps/undecided-is-not-necessarily-sha1: repository: stop setting SHA1 as the default object hash oss-fuzz/commit-graph: set up hash algorithm builtin/shortlog: don't set up revisions without repo builtin/diff: explicitly set hash algo when there is no repo builtin/bundle: abort "verify" early when there is no repository builtin/blame: don't access potentially unitialized `the_hash_algo` builtin/rev-parse: allow shortening to more than 40 hex characters remote-curl: fix parsing of detached SHA256 heads attr: fix BUG() when parsing attrs outside of repo attr: don't recompute default attribute source parse-options-cb: only abbreviate hashes when hash algo is known path: move `validate_headref()` to its only user path: harden validation of HEAD with non-standard hashes
This commit is contained in:
31
attr.c
31
attr.c
@@ -1205,15 +1205,16 @@ static void collect_some_attrs(struct index_state *istate,
|
||||
}
|
||||
|
||||
static const char *default_attr_source_tree_object_name;
|
||||
static int ignore_bad_attr_tree;
|
||||
|
||||
void set_git_attr_source(const char *tree_object_name)
|
||||
{
|
||||
default_attr_source_tree_object_name = xstrdup(tree_object_name);
|
||||
}
|
||||
|
||||
static void compute_default_attr_source(struct object_id *attr_source)
|
||||
static int compute_default_attr_source(struct object_id *attr_source)
|
||||
{
|
||||
int ignore_bad_attr_tree = 0;
|
||||
|
||||
if (!default_attr_source_tree_object_name)
|
||||
default_attr_source_tree_object_name = getenv(GIT_ATTR_SOURCE_ENVIRONMENT);
|
||||
|
||||
@@ -1222,22 +1223,34 @@ static void compute_default_attr_source(struct object_id *attr_source)
|
||||
ignore_bad_attr_tree = 1;
|
||||
}
|
||||
|
||||
if (!default_attr_source_tree_object_name || !is_null_oid(attr_source))
|
||||
return;
|
||||
if (!default_attr_source_tree_object_name)
|
||||
return 0;
|
||||
|
||||
if (!startup_info->have_repository) {
|
||||
if (!ignore_bad_attr_tree)
|
||||
die(_("cannot use --attr-source or GIT_ATTR_SOURCE without repo"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (repo_get_oid_treeish(the_repository,
|
||||
default_attr_source_tree_object_name,
|
||||
attr_source) && !ignore_bad_attr_tree)
|
||||
die(_("bad --attr-source or GIT_ATTR_SOURCE"));
|
||||
attr_source)) {
|
||||
if (!ignore_bad_attr_tree)
|
||||
die(_("bad --attr-source or GIT_ATTR_SOURCE"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct object_id *default_attr_source(void)
|
||||
{
|
||||
static struct object_id attr_source;
|
||||
static int has_attr_source = -1;
|
||||
|
||||
if (is_null_oid(&attr_source))
|
||||
compute_default_attr_source(&attr_source);
|
||||
if (is_null_oid(&attr_source))
|
||||
if (has_attr_source < 0)
|
||||
has_attr_source = compute_default_attr_source(&attr_source);
|
||||
if (!has_attr_source)
|
||||
return NULL;
|
||||
return &attr_source;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user