builtin/mktree: convert to struct object_id
Convert this file to use struct object_id. Modify one use of get_sha1_hex into parse_oid_hex; this is safe since we get the data from a strbuf. 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
83eb08020cbce4f6dff93e6b67ce635a3cd657f0
1 file changed
+12
-12
builtin/mktree.c
+12
-12
@@ -10,13 +10,13 @@
10
11
static struct treeent {
12
unsigned mode;
13
- unsigned char sha1[20];
13
+ struct object_id oid;
14
int len;
15
char name[FLEX_ARRAY];
16
} **entries;
17
static int alloc, used;
18
19
-static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
19
+static void append_to_tree(unsigned mode, struct object_id *oid, char *path)
20
{
21
struct treeent *ent;
22
size_t len = strlen(path);
@@ -26,7 +26,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
26
FLEX_ALLOC_MEM(ent, name, path, len);
27
ent->mode = mode;
28
ent->len = len;
29
- hashcpy(ent->sha1, sha1);
29
+ oidcpy(&ent->oid, oid);
30
31
ALLOC_GROW(entries, used + 1, alloc);
32
entries[used++] = ent;
@@ -54,7 +54,7 @@ static void write_tree(struct object_id *oid)
54
for (i = 0; i < used; i++) {
55
struct treeent *ent = entries[i];
56
strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0');
57
- strbuf_add(&buf, ent->sha1, 20);
57
+ strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
58
}
59
60
write_object_file(buf.buf, buf.len, tree_type, oid);
@@ -69,11 +69,12 @@ static const char *mktree_usage[] = {
69
static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing)
70
{
71
char *ptr, *ntr;
72
+ const char *p;
73
unsigned mode;
74
enum object_type mode_type; /* object type derived from mode */
75
enum object_type obj_type; /* object type derived from sha */
76
char *path, *to_free = NULL;
76
- unsigned char sha1[20];
77
+ struct object_id oid;
78
79
ptr = buf;
80
/*
@@ -85,9 +86,8 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
86
die("input format error: %s", buf);
87
ptr = ntr + 1; /* type */
88
ntr = strchr(ptr, ' ');
88
- if (!ntr || buf + len <= ntr + 40 ||
89
- ntr[41] != '\t' ||
90
- get_sha1_hex(ntr + 1, sha1))
89
+ if (!ntr || parse_oid_hex(ntr + 1, &oid, &p) ||
90
+ *p != '\t')
91
die("input format error: %s", buf);
92
93
/* It is perfectly normal if we do not have a commit from a submodule */
@@ -116,12 +116,12 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
116
}
117
118
/* Check the type of object identified by sha1 */
119
- obj_type = sha1_object_info(sha1, NULL);
119
+ obj_type = sha1_object_info(oid.hash, NULL);
120
if (obj_type < 0) {
121
if (allow_missing) {
122
; /* no problem - missing objects are presumed to be of the right type */
123
} else {
124
- die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1));
124
+ die("entry '%s' object %s is unavailable", path, oid_to_hex(&oid));
125
}
126
} else {
127
if (obj_type != mode_type) {
@@ -131,11 +131,11 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
131
* because the new tree entry will never be correct.
132
*/
133
die("entry '%s' object %s is a %s but specified type was (%s)",
134
- path, sha1_to_hex(sha1), type_name(obj_type), type_name(mode_type));
134
+ path, oid_to_hex(&oid), type_name(obj_type), type_name(mode_type));
135
}
136
}
137
138
- append_to_tree(mode, sha1, path);
138
+ append_to_tree(mode, &oid, path);
139
free(to_free);
140
}
141