object: remove "used" field from struct object

The "used" field in struct object is only used by builtin/fsck. Remove that field and modify builtin/fsck to use a flag instead. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jul 19, 2017 at 17:21 UTC 092c55d0940420a705e0fa0708ec846babab6d3d
3 files changed +15 -12
builtin/fsck.c
+14 -10
@@ -19,6 +19,8 @@
19 #define REACHABLE 0x0001
20 #define SEEN 0x0002
21 #define HAS_OBJ 0x0004
22 +/* This flag is set if something points to this object. */
23 +#define USED 0x0008
24
25 static int show_root;
26 static int show_tags;
@@ -195,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
197 {
198 if (!obj)
199 return 1;
198 - obj->used = 1;
200 + obj->flags |= USED;
201 return 0;
202 }
203
@@ -244,7 +246,7 @@ static void check_unreachable_object(struct object *obj)
246 }
247
248 /*
247 - * "!used" means that nothing at all points to it, including
249 + * "!USED" means that nothing at all points to it, including
250 * other unreachable objects. In other words, it's the "tip"
251 * of some set of unreachable objects, usually a commit that
252 * got dropped.
@@ -255,7 +257,7 @@ static void check_unreachable_object(struct object *obj)
257 * deleted a branch by mistake, this is a prime candidate to
258 * start looking at, for example.
259 */
258 - if (!obj->used) {
260 + if (!(obj->flags & USED)) {
261 if (show_dangling)
262 printf("dangling %s %s\n", printable_type(obj),
263 describe_object(obj));
@@ -379,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
381 errors_found |= ERROR_OBJECT;
382 return error("%s: object corrupt or missing", oid_to_hex(oid));
383 }
382 - obj->flags = HAS_OBJ;
384 + obj->flags &= ~(REACHABLE | SEEN);
385 + obj->flags |= HAS_OBJ;
386 return fsck_obj(obj);
387 }
388
@@ -397,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
400 add_decoration(fsck_walk_options.object_names,
401 obj,
402 xstrfmt("%s@{%"PRItime"}", refname, timestamp));
400 - obj->used = 1;
403 + obj->flags |= USED;
404 mark_object_reachable(obj);
405 } else {
406 error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
@@ -445,7 +448,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
448 errors_found |= ERROR_REFS;
449 }
450 default_refs++;
448 - obj->used = 1;
451 + obj->flags |= USED;
452 if (name_objects)
453 add_decoration(fsck_walk_options.object_names,
454 obj, xstrdup(refname));
@@ -513,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
516 return 0; /* keep checking other objects */
517 }
518
516 - obj->flags = HAS_OBJ;
519 + obj->flags &= ~(REACHABLE | SEEN);
520 + obj->flags |= HAS_OBJ;
521 if (fsck_obj(obj))
522 errors_found |= ERROR_OBJECT;
523 return 0;
@@ -595,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
599 errors_found |= ERROR_REFS;
600 return 1;
601 }
598 - obj->used = 1;
602 + obj->flags |= USED;
603 if (name_objects)
604 add_decoration(fsck_walk_options.object_names,
605 obj, xstrdup(":"));
@@ -737,7 +741,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
741 continue;
742 }
743
740 - obj->used = 1;
744 + obj->flags |= USED;
745 if (name_objects)
746 add_decoration(fsck_walk_options.object_names,
747 obj, xstrdup(arg));
@@ -774,7 +778,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
778 if (!blob)
779 continue;
780 obj = &blob->object;
777 - obj->used = 1;
781 + obj->flags |= USED;
782 if (name_objects)
783 add_decoration(fsck_walk_options.object_names,
784 obj,
object.c
-1
@@ -141,7 +141,6 @@ void *create_object(const unsigned char *sha1, void *o)
141 struct object *obj = o;
142
143 obj->parsed = 0;
144 - obj->used = 0;
144 obj->flags = 0;
145 hashcpy(obj->oid.hash, sha1);
146
object.h
+1 -1
@@ -38,6 +38,7 @@ struct object_array {
38 * http-push.c: 16-----19
39 * commit.c: 16-----19
40 * sha1_name.c: 20
41 + * builtin/fsck.c: 0--3
42 */
43 #define FLAG_BITS 27
44
@@ -46,7 +47,6 @@ struct object_array {
47 */
48 struct object {
49 unsigned parsed : 1;
49 - unsigned used : 1;
50 unsigned type : TYPE_BITS;
51 unsigned flags : FLAG_BITS;
52 struct object_id oid;