tree: convert read_tree_recursive to struct object_id
Convert the callback functions for read_tree_recursive to take a pointer to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 12, 2018 at 02:27 UTC
df46d77e00e7bbcfe46cc06c071fa5284f96c327
7 files changed
+20
-20
archive.c
+4
-4
@@ -198,7 +198,7 @@ static int write_directory(struct archiver_context *c)
198
return ret ? -1 : 0;
199
}
200
201
-static int queue_or_write_archive_entry(const unsigned char *sha1,
201
+static int queue_or_write_archive_entry(const struct object_id *oid,
202
struct strbuf *base, const char *filename,
203
unsigned mode, int stage, void *context)
204
{
@@ -224,14 +224,14 @@ static int queue_or_write_archive_entry(const unsigned char *sha1,
224
225
if (check_attr_export_ignore(check))
226
return 0;
227
- queue_directory(sha1, base, filename,
227
+ queue_directory(oid->hash, base, filename,
228
mode, stage, c);
229
return READ_TREE_RECURSIVE;
230
}
231
232
if (write_directory(c))
233
return -1;
234
- return write_archive_entry(sha1, base->buf, base->len, filename, mode,
234
+ return write_archive_entry(oid->hash, base->buf, base->len, filename, mode,
235
stage, context);
236
}
237
@@ -303,7 +303,7 @@ static const struct archiver *lookup_archiver(const char *name)
303
return NULL;
304
}
305
306
-static int reject_entry(const unsigned char *sha1, struct strbuf *base,
306
+static int reject_entry(const struct object_id *oid, struct strbuf *base,
307
const char *filename, unsigned mode,
308
int stage, void *context)
309
{
builtin/checkout.c
+2
-2
@@ -66,7 +66,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
66
67
}
68
69
-static int update_some(const unsigned char *sha1, struct strbuf *base,
69
+static int update_some(const struct object_id *oid, struct strbuf *base,
70
const char *pathname, unsigned mode, int stage, void *context)
71
{
72
int len;
@@ -78,7 +78,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
78
79
len = base->len + strlen(pathname);
80
ce = xcalloc(1, cache_entry_size(len));
81
- hashcpy(ce->oid.hash, sha1);
81
+ oidcpy(&ce->oid, oid);
82
memcpy(ce->name, base->buf, base->len);
83
memcpy(ce->name + base->len, pathname, len - base->len);
84
ce->ce_flags = create_ce_flags(0) | CE_UPDATE;
builtin/log.c
+1
-1
@@ -541,7 +541,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
541
return 0;
542
}
543
544
-static int show_tree_object(const unsigned char *sha1,
544
+static int show_tree_object(const struct object_id *oid,
545
struct strbuf *base,
546
const char *pathname, unsigned mode, int stage, void *context)
547
{
builtin/ls-tree.c
+4
-4
@@ -60,7 +60,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
60
return 0;
61
}
62
63
-static int show_tree(const unsigned char *sha1, struct strbuf *base,
63
+static int show_tree(const struct object_id *oid, struct strbuf *base,
64
const char *pathname, unsigned mode, int stage, void *context)
65
{
66
int retval = 0;
@@ -94,7 +94,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
94
char size_text[24];
95
if (!strcmp(type, blob_type)) {
96
unsigned long size;
97
- if (sha1_object_info(sha1, &size) == OBJ_BAD)
97
+ if (sha1_object_info(oid->hash, &size) == OBJ_BAD)
98
xsnprintf(size_text, sizeof(size_text),
99
"BAD");
100
else
@@ -103,11 +103,11 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
103
} else
104
xsnprintf(size_text, sizeof(size_text), "-");
105
printf("%06o %s %s %7s\t", mode, type,
106
- find_unique_abbrev(sha1, abbrev),
106
+ find_unique_abbrev(oid->hash, abbrev),
107
size_text);
108
} else
109
printf("%06o %s %s\t", mode, type,
110
- find_unique_abbrev(sha1, abbrev));
110
+ find_unique_abbrev(oid->hash, abbrev));
111
}
112
baselen = base->len;
113
strbuf_addstr(base, pathname);
merge-recursive.c
+1
-1
@@ -335,7 +335,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
335
return result;
336
}
337
338
-static int save_files_dirs(const unsigned char *sha1,
338
+static int save_files_dirs(const struct object_id *oid,
339
struct strbuf *base, const char *path,
340
unsigned int mode, int stage, void *context)
341
{
tree.c
+7
-7
@@ -10,7 +10,7 @@
10
const char *tree_type = "tree";
11
12
static int read_one_entry_opt(struct index_state *istate,
13
- const unsigned char *sha1,
13
+ const struct object_id *oid,
14
const char *base, int baselen,
15
const char *pathname,
16
unsigned mode, int stage, int opt)
@@ -31,16 +31,16 @@ static int read_one_entry_opt(struct index_state *istate,
31
ce->ce_namelen = baselen + len;
32
memcpy(ce->name, base, baselen);
33
memcpy(ce->name + baselen, pathname, len+1);
34
- hashcpy(ce->oid.hash, sha1);
34
+ oidcpy(&ce->oid, oid);
35
return add_index_entry(istate, ce, opt);
36
}
37
38
-static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
38
+static int read_one_entry(const struct object_id *oid, struct strbuf *base,
39
const char *pathname, unsigned mode, int stage,
40
void *context)
41
{
42
struct index_state *istate = context;
43
- return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
43
+ return read_one_entry_opt(istate, oid, base->buf, base->len, pathname,
44
mode, stage,
45
ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
46
}
@@ -49,12 +49,12 @@ static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
49
* This is used when the caller knows there is no existing entries at
50
* the stage that will conflict with the entry being added.
51
*/
52
-static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base,
52
+static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
53
const char *pathname, unsigned mode, int stage,
54
void *context)
55
{
56
struct index_state *istate = context;
57
- return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
57
+ return read_one_entry_opt(istate, oid, base->buf, base->len, pathname,
58
mode, stage,
59
ADD_CACHE_JUST_APPEND);
60
}
@@ -83,7 +83,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
83
continue;
84
}
85
86
- switch (fn(entry.oid->hash, base,
86
+ switch (fn(entry.oid, base,
87
entry.path, entry.mode, stage, context)) {
88
case 0:
89
continue;
tree.h
+1
-1
@@ -27,7 +27,7 @@ void free_tree_buffer(struct tree *tree);
27
struct tree *parse_tree_indirect(const struct object_id *oid);
28
29
#define READ_TREE_RECURSIVE 1
30
-typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *);
30
+typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
31
32
extern int read_tree_recursive(struct tree *tree,
33
const char *base, int baselen,