From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] fsck --lost-found: refactor handling of dangling objects
Date: Fri, 28 Mar 2008 15:05:46 +0100 (CET) [thread overview]
Message-ID: <alpine.LSU.1.00.0803281505330.18259@racer.site> (raw)
In-Reply-To: <alpine.LSU.1.00.0803281504591.18259@racer.site>
From: Junio C Hamano <gitster@pobox.com>
This moves a deeply nested part of the function
check_unreachable_object() into a separate function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
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
next prev parent reply other threads:[~2008-03-28 14:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-26 6:45 [PATCH] fsck --lost-found: show found commits human readably Junio C Hamano
2008-03-28 14:05 ` Johannes Schindelin
2008-03-28 14:05 ` Johannes Schindelin [this message]
2008-03-28 14:08 ` [PATCH 2/2] " Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.1.00.0803281505330.18259@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox