From: Junio C Hamano <gitster@xxxxxxxxx> This moves a deeply nested part of the function check_unreachable_object() into a separate function. Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- builtin-fsck.c | 65 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 35 insertions(+), 30 deletions(-) diff --git a/builtin-fsck.c b/builtin-fsck.c index 78a6e1f..f01263a 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -145,6 +145,39 @@ static void check_reachable_object(struct object *obj) } } +static void dangling_object(struct object *obj) +{ + char *filename; + FILE *f; + printf("dangling %s %s\n", typename(obj->type), + sha1_to_hex(obj->sha1)); + if (!write_lost_and_found) + return; + + filename = git_path("lost-found/%s/%s", + obj->type == OBJ_COMMIT ? "commit" : "other", + sha1_to_hex(obj->sha1)); + + if (safe_create_leading_directories(filename)) { + error("Could not create lost-found"); + return; + } + if (!(f = fopen(filename, "w"))) + die("Could not open %s", filename); + if (obj->type == OBJ_BLOB) { + enum object_type type; + unsigned long size; + char *buf = read_sha1_file(obj->sha1, + &type, &size); + if (buf) { + fwrite(buf, size, 1, f); + free(buf); + } + } else + fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); + fclose(f); +} + /* * Check a single unreachable object */ @@ -180,36 +213,8 @@ static void check_unreachable_object(struct object *obj) * deleted a branch by mistake, this is a prime candidate to * start looking at, for example. */ - if (!obj->used) { - printf("dangling %s %s\n", typename(obj->type), - sha1_to_hex(obj->sha1)); - if (write_lost_and_found) { - char *filename = git_path("lost-found/%s/%s", - obj->type == OBJ_COMMIT ? "commit" : "other", - sha1_to_hex(obj->sha1)); - FILE *f; - - if (safe_create_leading_directories(filename)) { - error("Could not create lost-found"); - return; - } - if (!(f = fopen(filename, "w"))) - die("Could not open %s", filename); - if (obj->type == OBJ_BLOB) { - enum object_type type; - unsigned long size; - char *buf = read_sha1_file(obj->sha1, - &type, &size); - if (buf) { - fwrite(buf, size, 1, f); - free(buf); - } - } else - fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); - fclose(f); - } - return; - } + if (!obj->used) + dangling_object(obj); /* * Otherwise? It's there, it's unreachable, and some other unreachable -- 1.5.5.rc2.186.gbac51 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html