Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-05-17 20:11:41 +0300
committerJunio C Hamano <gitster@pobox.com>2023-05-17 20:11:41 +0300
commit67a3b2b39f638872531324e03217fa58f7b9ad1e (patch)
tree5c4e9c7b9e2c0efc9c9f9e7e70fb11b104f95890 /attr.c
parent3307f7dde2ae8f5281d0782f7291a073c9b1cdc2 (diff)
parent44451a2e5eec5360378be23e2cdbd9ecee49e14e (diff)
Merge branch 'jc/attr-source-tree'
"git --attr-source=<tree> cmd $args" is a new way to have any command to read attributes not from the working tree but from the given tree object. * jc/attr-source-tree: attr: teach "--attr-source=<tree>" global option to "git"
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/attr.c b/attr.c
index ddf2b0cbc2..d45d34058d 100644
--- a/attr.c
+++ b/attr.c
@@ -21,6 +21,7 @@
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
+#include "object-name.h"
const char git_attr__true[] = "(builtin)true";
const char git_attr__false[] = "\0(builtin)false";
@@ -1170,11 +1171,42 @@ static void collect_some_attrs(struct index_state *istate,
fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
}
+static const char *default_attr_source_tree_object_name;
+
+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)
+{
+ if (!default_attr_source_tree_object_name)
+ default_attr_source_tree_object_name = getenv(GIT_ATTR_SOURCE_ENVIRONMENT);
+
+ if (!default_attr_source_tree_object_name || !is_null_oid(attr_source))
+ return;
+
+ if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, attr_source))
+ die(_("bad --attr-source or GIT_ATTR_SOURCE"));
+}
+
+static struct object_id *default_attr_source(void)
+{
+ static struct object_id attr_source;
+
+ if (is_null_oid(&attr_source))
+ compute_default_attr_source(&attr_source);
+ if (is_null_oid(&attr_source))
+ return NULL;
+ return &attr_source;
+}
+
void git_check_attr(struct index_state *istate,
- const struct object_id *tree_oid, const char *path,
+ const char *path,
struct attr_check *check)
{
int i;
+ const struct object_id *tree_oid = default_attr_source();
collect_some_attrs(istate, tree_oid, path, check);
@@ -1187,10 +1219,11 @@ void git_check_attr(struct index_state *istate,
}
}
-void git_all_attrs(struct index_state *istate, const struct object_id *tree_oid,
+void git_all_attrs(struct index_state *istate,
const char *path, struct attr_check *check)
{
int i;
+ const struct object_id *tree_oid = default_attr_source();
attr_check_reset(check);
collect_some_attrs(istate, tree_oid, path, check);