diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2023-10-02 04:40:18 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-10-02 23:57:39 +0200 |
commit | 45b3b1214154975ac03c818838e3d12571f57d1e (patch) | |
tree | ad173a49d3e0fce5ce3e81ce0801bfe3c24e1f7e /builtin/fast-import.c | |
parent | cache: add a function to read an OID of a specific algorithm (diff) | |
download | git-45b3b1214154975ac03c818838e3d12571f57d1e.tar.xz git-45b3b1214154975ac03c818838e3d12571f57d1e.zip |
object: factor out parse_mode out of fast-import and tree-walk into in object.h
builtin/fast-import.c and tree-walk.c have almost identical version of
get_mode. The two functions started out the same but have diverged
slightly. The version in fast-import changed mode to a uint16_t to
save memory. The version in tree-walk started erroring if no mode was
present.
As far as I can tell both of these changes are valid for both of the
callers, so add the both changes and place the common parsing helper
in object.h
Rename the helper from get_mode to parse_mode so it does not
conflict with another helper named get_mode in diff-no-index.c
This will be used shortly in a new helper decode_tree_entry_raw
which is used to compute cmpatibility objects as part of
the sha256 transition.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fast-import.c')
-rw-r--r-- | builtin/fast-import.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 4dbb10aff3..2c645fcfbe 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1235,20 +1235,6 @@ static void *gfi_unpack_entry( return unpack_entry(the_repository, p, oe->idx.offset, &type, sizep); } -static const char *get_mode(const char *str, uint16_t *modep) -{ - unsigned char c; - uint16_t mode = 0; - - while ((c = *str++) != ' ') { - if (c < '0' || c > '7') - return NULL; - mode = (mode << 3) + (c - '0'); - } - *modep = mode; - return str; -} - static void load_tree(struct tree_entry *root) { struct object_id *oid = &root->versions[1].oid; @@ -1286,7 +1272,7 @@ static void load_tree(struct tree_entry *root) t->entries[t->entry_count++] = e; e->tree = NULL; - c = get_mode(c, &e->versions[1].mode); + c = parse_mode(c, &e->versions[1].mode); if (!c) die("Corrupt mode in %s", oid_to_hex(oid)); e->versions[0].mode = e->versions[1].mode; @@ -2275,7 +2261,7 @@ static void file_change_m(const char *p, struct branch *b) struct object_id oid; uint16_t mode, inline_data = 0; - p = get_mode(p, &mode); + p = parse_mode(p, &mode); if (!p) die("Corrupt mode: %s", command_buf.buf); switch (mode) { |