filter: use a `git_oid` in filter options, not a pointer Using a `git_oid *` in filter options was a mistake; it is a deviation from our typical pattern, and callers in some languages that GC may need very special treatment in order to pass both an options structure and a pointer outside of it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
diff --git a/include/git2/attr.h b/include/git2/attr.h
index 62c2ed6..3891a0c 100644
--- a/include/git2/attr.h
+++ b/include/git2/attr.h
@@ -147,11 +147,17 @@ typedef struct {
/** A combination of GIT_ATTR_CHECK flags */
unsigned int flags;
+#ifdef GIT_DEPRECATE_HARD
+ void *reserved;
+#else
+ git_oid *commit_id;
+#endif
+
/**
* The commit to load attributes from, when
* `GIT_ATTR_CHECK_INCLUDE_COMMIT` is specified.
*/
- git_oid *commit_id;
+ git_oid attr_commit_id;
} git_attr_options;
#define GIT_ATTR_OPTIONS_VERSION 1
diff --git a/include/git2/blob.h b/include/git2/blob.h
index fceb5c7..8fc7391 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -135,11 +135,17 @@ typedef struct {
/** Flags to control the filtering process, see `git_blob_filter_flag_t` above */
uint32_t flags;
+#ifdef GIT_DEPRECATE_HARD
+ void *reserved;
+#else
+ git_oid *commit_id;
+#endif
+
/**
* The commit to load attributes from, when
* `GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT` is specified.
*/
- git_oid *commit_id;
+ git_oid attr_commit_id;
} git_blob_filter_options;
#define GIT_BLOB_FILTER_OPTIONS_VERSION 1
diff --git a/include/git2/filter.h b/include/git2/filter.h
index 044c3b8..0465e5b 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -66,11 +66,17 @@ typedef struct {
/** See `git_filter_flag_t` above */
uint32_t flags;
+#ifdef GIT_DEPRECATE_HARD
+ void *reserved;
+#else
+ git_oid *commit_id;
+#endif
+
/**
* The commit to load attributes from, when
* `GIT_FILTER_ATTRIBUTES_FROM_COMMIT` is specified.
*/
- git_oid *commit_id;
+ git_oid attr_commit_id;
} git_filter_options;
#define GIT_FILTER_OPTIONS_VERSION 1
diff --git a/src/attr.c b/src/attr.c
index 03b720c..14eab5b 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 f862738..694967a 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 16e33ca..a07cb42 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 79096ee..06a4a00 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 dd7d2f7..73497cb 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(
diff --git a/tests/filter/bare.c b/tests/filter/bare.c
index f8e3423..8402638 100644
--- a/tests/filter/bare.c
+++ b/tests/filter/bare.c
@@ -137,13 +137,10 @@ void test_filter_bare__from_specific_commit_one(void)
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_blob *blob;
git_buf buf = { 0 };
- git_oid commit_id;
-
- cl_git_pass(git_oid_fromstr(&commit_id, "b8986fec0f7bde90f78ac72706e782d82f24f2f0"));
opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
- opts.commit_id = &commit_id;
+ cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "b8986fec0f7bde90f78ac72706e782d82f24f2f0"));
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "055c872")); /* ident */
@@ -165,13 +162,10 @@ void test_filter_bare__from_specific_commit_with_no_attributes_file(void)
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_blob *blob;
git_buf buf = { 0 };
- git_oid commit_id;
-
- cl_git_pass(git_oid_fromstr(&commit_id, "5afb6a14a864e30787857dd92af837e8cdd2cb1b"));
opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
- opts.commit_id = &commit_id;
+ cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "5afb6a14a864e30787857dd92af837e8cdd2cb1b"));
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */