Use OBJ_NONE to mean we don't have an object.
PATCH 2/2 Use OBJ_NONE to mean we don't have an object.
Rather than returning -1 (which is not a valid object_type value) from sha1_object_info we now return OBJ_NONE. Practically speaking there is no logic change in this patch, its just a cleanup to ensure the return value is always within object_type.
The type OBJ_NONE is already used in a few locations to mean "don't got that object", as OBJ_NONE = 0 and standard initializations like xcalloc will automatically prefill OBJ_NONE. This change is just continuing with that existing tradition.
I'm planning on taking advantage of this cleanup later on in the pack version 4 changes.
Signed-off-by Shawn O. Pearce <[email protected]>
--- builtin-cat-file.c | 2 +- builtin-commit-tree.c | 2 +- builtin-pack-objects.c | 4 ++-- cache.h | 2 +- diff.c | 2 +- fast-import.c | 2 +- mktree.c | 2 +- sha1_file.c | 42 ++++++++++++++++++++++++++---------------- 8 files changed, 34 insertions(+), 24 deletions(-)
builtin-cat-file.c +1 -1
@@ -120,7 +120,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)case 'p' : type =sha1_object_info (sha1,NULL ); -if (type <0 ) +if (type ==OBJ_NONE )die ("Not a valid object name %s" , argv[2 ]);/* custom pretty-print here */
builtin-commit-tree.c +1 -1
@@ -48,7 +48,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)static void check_valid (unsigned char *sha1,enum object_type expect) {enum object_type type =sha1_object_info (sha1,NULL ); -if (type <0 ) +if (type ==OBJ_NONE )die ("%s is not a valid object" ,sha1_to_hex (sha1));if (type != expect) die("%s is not a valid '%s' object", sha1_to_hex(sha1),
builtin-pack-objects.c +2 -2
@@ -859,7 +859,7 @@ static void add_pbase_object(struct tree_desc *tree,if (entry.pathlen != cmplen ||memcmp (entry.path, name, cmplen) || !has_sha1_file (entry.sha1) || - (type =sha1_object_info (entry.sha1, &size)) <0 ) + (type =sha1_object_info (entry.sha1, &size)) ==OBJ_NONE )continue ;if (name[cmplen] !='/' ) {unsigned hash =name_hash (fullname);
@@ -1061,7 +1061,7 @@ static void check_object(struct object_entry *entry) } entry->type =sha1_object_info (entry->sha1, &entry->size); -if (entry->type <0 ) +if (entry->type ==OBJ_NONE )die ("unable to get type of object %s" ,sha1_to_hex (entry->sha1)); }
cache.h +1 -1
@@ -275,7 +275,7 @@ enum object_type { };/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ -extern int sha1_object_info (const unsigned char *,unsigned long *); +extern enum object_type sha1_object_info (const unsigned char *,unsigned long *);extern void *unpack_sha1_file (void *map,unsigned long mapsize,enum object_type *type,unsigned long *size);extern void *read_sha1_file (const unsigned char *sha1,enum object_type *type,unsigned long *size);extern int hash_sha1_file (void *buf,unsigned long len,const char *type,unsigned char *sha1);
diff.c +1 -1
@@ -1440,7 +1440,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)return 0 ; } type =sha1_object_info (s->sha1, &s->size); -if (type <0 ) +if (type ==OBJ_NONE )locate_size_cache (s->sha1,0 , s->size); }else {
fast-import.c +1 -1
@@ -1628,7 +1628,7 @@ static void file_change_m(struct branch *b) command_buf.buf, typename(oe->type)); }else {enum object_type type =sha1_object_info (sha1,NULL ); -if (type <0 ) +if (type ==OBJ_NONE )die ("Blob not found: %s" , command_buf.buf);if (type !=OBJ_BLOB ) die("Not a blob (actually a %s): %s",
mktree.c +1 -1
@@ -116,7 +116,7 @@ int main(int ac, char **av) get_sha1_hex(ntr + 1, sha1))die ("input format error: %s" , sb.buf); type =sha1_object_info (sha1,NULL ); -if (type <0 ) +if (type ==OBJ_NONE )die ("object %s unavailable" ,sha1_to_hex (sha1)); *ntr++ =0 ;/* now at the beginning of SHA1 */ if (type !=type_from_string (ptr))
sha1_file.c +26 -16
74 lines not on this page · raw message
Signature · 1 line
1.5.0.2.775.g1a500