Skip to content

Commit 2c40c6a

Browse files
committed
Merge branch 'jt/fsck-code-cleanup'
Code clean-up. * jt/fsck-code-cleanup: fsck: cleanup unused variable object: remove "used" field from struct object fsck: remove redundant parse_tree() invocation
2 parents 17b1e1d + 78e7b98 commit 2c40c6a

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

builtin/fsck.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define REACHABLE 0x0001
2020
#define SEEN 0x0002
2121
#define HAS_OBJ 0x0004
22+
/* This flag is set if something points to this object. */
23+
#define USED 0x0008
2224

2325
static int show_root;
2426
static int show_tags;
@@ -168,18 +170,7 @@ static void mark_object_reachable(struct object *obj)
168170

169171
static int traverse_one_object(struct object *obj)
170172
{
171-
int result;
172-
struct tree *tree = NULL;
173-
174-
if (obj->type == OBJ_TREE) {
175-
tree = (struct tree *)obj;
176-
if (parse_tree(tree) < 0)
177-
return 1; /* error already displayed */
178-
}
179-
result = fsck_walk(obj, obj, &fsck_walk_options);
180-
if (tree)
181-
free_tree_buffer(tree);
182-
return result;
173+
return fsck_walk(obj, obj, &fsck_walk_options);
183174
}
184175

185176
static int traverse_reachable(void)
@@ -206,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
206197
{
207198
if (!obj)
208199
return 1;
209-
obj->used = 1;
200+
obj->flags |= USED;
210201
return 0;
211202
}
212203

@@ -255,7 +246,7 @@ static void check_unreachable_object(struct object *obj)
255246
}
256247

257248
/*
258-
* "!used" means that nothing at all points to it, including
249+
* "!USED" means that nothing at all points to it, including
259250
* other unreachable objects. In other words, it's the "tip"
260251
* of some set of unreachable objects, usually a commit that
261252
* got dropped.
@@ -266,7 +257,7 @@ static void check_unreachable_object(struct object *obj)
266257
* deleted a branch by mistake, this is a prime candidate to
267258
* start looking at, for example.
268259
*/
269-
if (!obj->used) {
260+
if (!(obj->flags & USED)) {
270261
if (show_dangling)
271262
printf("dangling %s %s\n", printable_type(obj),
272263
describe_object(obj));
@@ -390,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
390381
errors_found |= ERROR_OBJECT;
391382
return error("%s: object corrupt or missing", oid_to_hex(oid));
392383
}
393-
obj->flags = HAS_OBJ;
384+
obj->flags &= ~(REACHABLE | SEEN);
385+
obj->flags |= HAS_OBJ;
394386
return fsck_obj(obj);
395387
}
396388

@@ -408,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
408400
add_decoration(fsck_walk_options.object_names,
409401
obj,
410402
xstrfmt("%s@{%"PRItime"}", refname, timestamp));
411-
obj->used = 1;
403+
obj->flags |= USED;
412404
mark_object_reachable(obj);
413405
} else {
414406
error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
@@ -456,7 +448,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
456448
errors_found |= ERROR_REFS;
457449
}
458450
default_refs++;
459-
obj->used = 1;
451+
obj->flags |= USED;
460452
if (name_objects)
461453
add_decoration(fsck_walk_options.object_names,
462454
obj, xstrdup(refname));
@@ -524,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
524516
return 0; /* keep checking other objects */
525517
}
526518

527-
obj->flags = HAS_OBJ;
519+
obj->flags &= ~(REACHABLE | SEEN);
520+
obj->flags |= HAS_OBJ;
528521
if (fsck_obj(obj))
529522
errors_found |= ERROR_OBJECT;
530523
return 0;
@@ -606,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
606599
errors_found |= ERROR_REFS;
607600
return 1;
608601
}
609-
obj->used = 1;
602+
obj->flags |= USED;
610603
if (name_objects)
611604
add_decoration(fsck_walk_options.object_names,
612605
obj, xstrdup(":"));
@@ -667,7 +660,7 @@ static struct option fsck_opts[] = {
667660

668661
int cmd_fsck(int argc, const char **argv, const char *prefix)
669662
{
670-
int i, heads;
663+
int i;
671664
struct alternate_object_database *alt;
672665

673666
errors_found = 0;
@@ -735,7 +728,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
735728
}
736729
}
737730

738-
heads = 0;
739731
for (i = 0; i < argc; i++) {
740732
const char *arg = argv[i];
741733
struct object_id oid;
@@ -748,12 +740,11 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
748740
continue;
749741
}
750742

751-
obj->used = 1;
743+
obj->flags |= USED;
752744
if (name_objects)
753745
add_decoration(fsck_walk_options.object_names,
754746
obj, xstrdup(arg));
755747
mark_object_reachable(obj);
756-
heads++;
757748
continue;
758749
}
759750
error("invalid parameter: expected sha1, got '%s'", arg);
@@ -785,7 +776,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
785776
if (!blob)
786777
continue;
787778
obj = &blob->object;
788-
obj->used = 1;
779+
obj->flags |= USED;
789780
if (name_objects)
790781
add_decoration(fsck_walk_options.object_names,
791782
obj,

object.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ void *create_object(const unsigned char *sha1, void *o)
141141
struct object *obj = o;
142142

143143
obj->parsed = 0;
144-
obj->used = 0;
145144
obj->flags = 0;
146145
hashcpy(obj->oid.hash, sha1);
147146

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct object_array {
3838
* http-push.c: 16-----19
3939
* commit.c: 16-----19
4040
* sha1_name.c: 20
41+
* builtin/fsck.c: 0--3
4142
*/
4243
#define FLAG_BITS 27
4344

@@ -46,7 +47,6 @@ struct object_array {
4647
*/
4748
struct object {
4849
unsigned parsed : 1;
49-
unsigned used : 1;
5050
unsigned type : TYPE_BITS;
5151
unsigned flags : FLAG_BITS;
5252
struct object_id oid;

0 commit comments

Comments
 (0)