dir: convert struct untracked_cache_dir to object_id
Convert the exclude_sha1 member of struct untracked_cache_dir and rename it to exclude_oid. Eliminate several hard-coded integral constants, and update a function name that referred to SHA-1. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
70c369cde064375483917f4874a6e5670ef48164
3 files changed
+16
-14
dir.c
+12
-11
@@ -1240,11 +1240,11 @@ static void prep_exclude(struct dir_struct *dir,
1240
(!untracked || !untracked->valid ||
1241
/*
1242
* .. and .gitignore does not exist before
1243
- * (i.e. null exclude_sha1). Then we can skip
1243
+ * (i.e. null exclude_oid). Then we can skip
1244
* loading .gitignore, which would result in
1245
* ENOENT anyway.
1246
*/
1247
- !is_null_sha1(untracked->exclude_sha1))) {
1247
+ !is_null_oid(&untracked->exclude_oid))) {
1248
/*
1249
* dir->basebuf gets reused by the traversal, but we
1250
* need fname to remain unchanged to ensure the src
@@ -1275,9 +1275,9 @@ static void prep_exclude(struct dir_struct *dir,
1275
* order, though, if you do that.
1276
*/
1277
if (untracked &&
1278
- hashcmp(oid_stat.oid.hash, untracked->exclude_sha1)) {
1278
+ oidcmp(&oid_stat.oid, &untracked->exclude_oid)) {
1279
invalidate_gitignore(dir->untracked, untracked);
1280
- hashcpy(untracked->exclude_sha1, oid_stat.oid.hash);
1280
+ oidcpy(&untracked->exclude_oid, &oid_stat.oid);
1281
}
1282
dir->exclude_stack = stk;
1283
current = stk->baselen;
@@ -2622,9 +2622,10 @@ static void write_one_dir(struct untracked_cache_dir *untracked,
2622
stat_data_to_disk(&stat_data, &untracked->stat_data);
2623
strbuf_add(&wd->sb_stat, &stat_data, sizeof(stat_data));
2624
}
2625
- if (!is_null_sha1(untracked->exclude_sha1)) {
2625
+ if (!is_null_oid(&untracked->exclude_oid)) {
2626
ewah_set(wd->sha1_valid, i);
2627
- strbuf_add(&wd->sb_sha1, untracked->exclude_sha1, 20);
2627
+ strbuf_add(&wd->sb_sha1, untracked->exclude_oid.hash,
2628
+ the_hash_algo->rawsz);
2629
}
2630
2631
intlen = encode_varint(untracked->untracked_nr, intbuf);
@@ -2825,16 +2826,16 @@ static void read_stat(size_t pos, void *cb)
2826
ud->valid = 1;
2827
}
2828
2828
-static void read_sha1(size_t pos, void *cb)
2829
+static void read_oid(size_t pos, void *cb)
2830
{
2831
struct read_data *rd = cb;
2832
struct untracked_cache_dir *ud = rd->ucd[pos];
2832
- if (rd->data + 20 > rd->end) {
2833
+ if (rd->data + the_hash_algo->rawsz > rd->end) {
2834
rd->data = rd->end + 1;
2835
return;
2836
}
2836
- hashcpy(ud->exclude_sha1, rd->data);
2837
- rd->data += 20;
2837
+ hashcpy(ud->exclude_oid.hash, rd->data);
2838
+ rd->data += the_hash_algo->rawsz;
2839
}
2840
2841
static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
@@ -2917,7 +2918,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2918
ewah_each_bit(rd.check_only, set_check_only, &rd);
2919
rd.data = next + len;
2920
ewah_each_bit(rd.valid, read_stat, &rd);
2920
- ewah_each_bit(rd.sha1_valid, read_sha1, &rd);
2921
+ ewah_each_bit(rd.sha1_valid, read_oid, &rd);
2922
next = rd.data;
2923
2924
done:
dir.h
+3
-2
@@ -3,6 +3,7 @@
3
4
/* See Documentation/technical/api-directory-listing.txt */
5
6
+#include "cache.h"
7
#include "strbuf.h"
8
9
struct dir_entry {
@@ -118,8 +119,8 @@ struct untracked_cache_dir {
119
/* all data except 'dirs' in this struct are good */
120
unsigned int valid : 1;
121
unsigned int recurse : 1;
121
- /* null SHA-1 means this directory does not have .gitignore */
122
- unsigned char exclude_sha1[20];
122
+ /* null object ID means this directory does not have .gitignore */
123
+ struct object_id exclude_oid;
124
char name[FLEX_ARRAY];
125
};
126
t/helper/test-dump-untracked-cache.c
+1
-1
@@ -23,7 +23,7 @@ static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
23
len = base->len;
24
strbuf_addf(base, "%s/", ucd->name);
25
printf("%s %s", base->buf,
26
- sha1_to_hex(ucd->exclude_sha1));
26
+ oid_to_hex(&ucd->exclude_oid));
27
if (ucd->recurse)
28
fputs(" recurse", stdout);
29
if (ucd->check_only)