summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-21 13:19:10 -0400
committerGitHub <noreply@github.com>2021-09-21 13:19:10 -0400
commitefa0d64e03c705bdbdfe56f0cac210322b76702e (patch)
tree997b65081942998b01e2fc2510bbb6ee7c807ddf /src
parentabd8142c4afbe8ceca579305efd8f9f9958cd7ed (diff)
parent90656858ce6ec0f4cba5ba5f8690ace9b83161d0 (diff)
downloadlibgit2-efa0d64e03c705bdbdfe56f0cac210322b76702e.tar.gz
Merge pull request #6067 from libgit2/ethomson/filter_commit_id
filter: use a `git_oid` in filter options, not a pointer
Diffstat (limited to 'src')
-rw-r--r--src/attr.c25
-rw-r--r--src/attr_file.c34
-rw-r--r--src/attr_file.h5
-rw-r--r--src/blob.c8
-rw-r--r--src/filter.c8
5 files changed, 58 insertions, 22 deletions
diff --git a/src/attr.c b/src/attr.c
index 03b720c5a..14eab5b46 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -382,7 +382,7 @@ static int attr_setup(
{
git_buf system = GIT_BUF_INIT, info = GIT_BUF_INIT;
git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL };
- git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL };
+ git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL };
git_index *idx = NULL;
const char *workdir;
@@ -432,7 +432,12 @@ static int attr_setup(
goto out;
if ((opts && (opts->flags & GIT_ATTR_CHECK_INCLUDE_COMMIT) != 0)) {
- commit_source.commit_id = opts->commit_id;
+#ifndef GIT_DEPRECATE_HARD
+ if (opts->commit_id)
+ commit_source.commit_id = opts->commit_id;
+ else
+#endif
+ commit_source.commit_id = &opts->attr_commit_id;
if ((error = preload_attr_source(repo, attr_session, &commit_source)) < 0)
goto out;
@@ -521,8 +526,10 @@ static int attr_decide_sources(
break;
}
- if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0 ||
- (flags & GIT_ATTR_CHECK_INCLUDE_COMMIT) != 0)
+ if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0)
+ srcs[count++] = GIT_ATTR_FILE_SOURCE_HEAD;
+
+ if ((flags & GIT_ATTR_CHECK_INCLUDE_COMMIT) != 0)
srcs[count++] = GIT_ATTR_FILE_SOURCE_COMMIT;
return count;
@@ -582,8 +589,14 @@ static int push_one_attr(void *ref, const char *path)
for (i = 0; !error && i < n_src; ++i) {
git_attr_file_source source = { src[i], path, GIT_ATTR_FILE };
- if (src[i] == GIT_ATTR_FILE_SOURCE_COMMIT && info->opts)
- source.commit_id = info->opts->commit_id;
+ if (src[i] == GIT_ATTR_FILE_SOURCE_COMMIT && info->opts) {
+#ifndef GIT_DEPRECATE_HARD
+ if (info->opts->commit_id)
+ source.commit_id = info->opts->commit_id;
+ else
+#endif
+ source.commit_id = &info->opts->attr_commit_id;
+ }
error = push_attr_source(info->repo, info->attr_session, info->files,
&source, allow_macros);
diff --git a/src/attr_file.c b/src/attr_file.c
index f8627381c..694967a1c 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -163,8 +163,9 @@ int git_attr_file__load(
break;
}
+ case GIT_ATTR_FILE_SOURCE_HEAD:
case GIT_ATTR_FILE_SOURCE_COMMIT: {
- if (source->commit_id) {
+ if (source->type == GIT_ATTR_FILE_SOURCE_COMMIT) {
if ((error = git_commit_lookup(&commit, repo, source->commit_id)) < 0 ||
(error = git_commit_tree(&tree, commit)) < 0)
goto cleanup;
@@ -234,6 +235,8 @@ int git_attr_file__load(
file->nonexistent = 1;
else if (source->type == GIT_ATTR_FILE_SOURCE_INDEX)
git_oid_cpy(&file->cache_data.oid, git_blob_id(blob));
+ else if (source->type == GIT_ATTR_FILE_SOURCE_HEAD)
+ git_oid_cpy(&file->cache_data.oid, git_tree_id(tree));
else if (source->type == GIT_ATTR_FILE_SOURCE_COMMIT)
git_oid_cpy(&file->cache_data.oid, git_tree_id(tree));
else if (source->type == GIT_ATTR_FILE_SOURCE_FILE)
@@ -288,22 +291,29 @@ int git_attr_file__out_of_date(
return (git_oid__cmp(&file->cache_data.oid, &id) != 0);
}
- case GIT_ATTR_FILE_SOURCE_COMMIT: {
+ case GIT_ATTR_FILE_SOURCE_HEAD: {
git_tree *tree = NULL;
- int error;
+ int error = git_repository_head_tree(&tree, repo);
- if (source->commit_id) {
- git_commit *commit = NULL;
+ if (error < 0)
+ return error;
- if ((error = git_commit_lookup(&commit, repo, source->commit_id)) < 0)
- return error;
+ error = (git_oid__cmp(&file->cache_data.oid, git_tree_id(tree)) != 0);
- error = git_commit_tree(&tree, commit);
+ git_tree_free(tree);
+ return error;
+ }
- git_commit_free(commit);
- } else {
- error = git_repository_head_tree(&tree, repo);
- }
+ case GIT_ATTR_FILE_SOURCE_COMMIT: {
+ git_commit *commit = NULL;
+ git_tree *tree = NULL;
+ int error;
+
+ if ((error = git_commit_lookup(&commit, repo, source->commit_id)) < 0)
+ return error;
+
+ error = git_commit_tree(&tree, commit);
+ git_commit_free(commit);
if (error < 0)
return error;
diff --git a/src/attr_file.h b/src/attr_file.h
index 16e33caf1..a07cb4268 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -40,9 +40,10 @@ typedef enum {
GIT_ATTR_FILE_SOURCE_MEMORY = 0,
GIT_ATTR_FILE_SOURCE_FILE = 1,
GIT_ATTR_FILE_SOURCE_INDEX = 2,
- GIT_ATTR_FILE_SOURCE_COMMIT = 3,
+ GIT_ATTR_FILE_SOURCE_HEAD = 3,
+ GIT_ATTR_FILE_SOURCE_COMMIT = 4,
- GIT_ATTR_FILE_NUM_SOURCES = 4
+ GIT_ATTR_FILE_NUM_SOURCES = 5
} git_attr_file_source_t;
typedef struct {
diff --git a/src/blob.c b/src/blob.c
index 79096ee95..06a4a0026 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -449,7 +449,13 @@ int git_blob_filter(
if ((opts.flags & GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT) != 0) {
filter_opts.flags |= GIT_FILTER_ATTRIBUTES_FROM_COMMIT;
- filter_opts.commit_id = opts.commit_id;
+
+#ifndef GIT_DEPRECATE_HARD
+ if (opts.commit_id)
+ git_oid_cpy(&filter_opts.attr_commit_id, opts.commit_id);
+ else
+#endif
+ git_oid_cpy(&filter_opts.attr_commit_id, &opts.attr_commit_id);
}
if (!(error = git_filter_list_load_ext(
diff --git a/src/filter.c b/src/filter.c
index dd7d2f7ec..73497cb30 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -446,7 +446,13 @@ static int filter_list_check_attributes(
if ((src->options.flags & GIT_FILTER_ATTRIBUTES_FROM_COMMIT) != 0) {
attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_COMMIT;
- attr_opts.commit_id = src->options.commit_id;
+
+#ifndef GIT_DEPRECATE_HARD
+ if (src->options.commit_id)
+ git_oid_cpy(&attr_opts.attr_commit_id, src->options.commit_id);
+ else
+#endif
+ git_oid_cpy(&attr_opts.attr_commit_id, &src->options.attr_commit_id);
}
error = git_attr_get_many_with_session(