diff options
| author | Eric W. Biederman <ebiederm@xmission.com> | 2023-10-01 21:40:18 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-10-02 14:57:39 -0700 |
| commit | 45b3b1214154975ac03c818838e3d12571f57d1e (patch) | |
| tree | ad173a49d3e0fce5ce3e81ce0801bfe3c24e1f7e /tree-walk.c | |
| parent | 095261a18d91cf47e8e8ef3b55f5e88e52ffc85f (diff) | |
| download | git-45b3b1214154975ac03c818838e3d12571f57d1e.tar.gz | |
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 'tree-walk.c')
| -rw-r--r-- | tree-walk.c | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/tree-walk.c b/tree-walk.c index 29ead71be1..3af50a01c2 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -10,27 +10,11 @@ #include "pathspec.h" #include "json-writer.h" -static const char *get_mode(const char *str, unsigned int *modep) -{ - unsigned char c; - unsigned int mode = 0; - - if (*str == ' ') - return NULL; - - while ((c = *str++) != ' ') { - if (c < '0' || c > '7') - return NULL; - mode = (mode << 3) + (c - '0'); - } - *modep = mode; - return str; -} - static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size, struct strbuf *err) { const char *path; - unsigned int mode, len; + unsigned int len; + uint16_t mode; const unsigned hashsz = the_hash_algo->rawsz; if (size < hashsz + 3 || buf[size - (hashsz + 1)]) { @@ -38,7 +22,7 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l return -1; } - path = get_mode(buf, &mode); + path = parse_mode(buf, &mode); if (!path) { strbuf_addstr(err, _("malformed mode in tree entry")); return -1; |
