From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: pclouds@gmail.com, peff@peff.net, Elijah Newren <newren@gmail.com>
Subject: [RFC PATCH 1/3] fsck: Move fsck_head_link() to get_default_heads() to avoid some globals
Date: Fri, 9 Feb 2018 15:13:28 -0800 [thread overview]
Message-ID: <20180209231330.4457-2-newren@gmail.com> (raw)
In-Reply-To: <20180209231330.4457-1-newren@gmail.com>
This will make it easier to check the HEAD of other worktrees from fsck.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
builtin/fsck.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 04846d46f9..4132034170 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -33,8 +33,6 @@ static int check_strict;
static int keep_cache_objects;
static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
-static struct object_id head_oid;
-static const char *head_points_at;
static int errors_found;
static int write_lost_and_found;
static int verbose;
@@ -453,8 +451,15 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
return 0;
}
+static int fsck_head_link(const char **head_points_at,
+ struct object_id *head_oid);
+
static void get_default_heads(void)
{
+ const char *head_points_at;
+ struct object_id head_oid;
+
+ fsck_head_link(&head_points_at, &head_oid);
if (head_points_at && !is_null_oid(&head_oid))
fsck_handle_ref("HEAD", &head_oid, 0, NULL);
for_each_rawref(fsck_handle_ref, NULL);
@@ -548,33 +553,34 @@ static void fsck_object_dir(const char *path)
stop_progress(&progress);
}
-static int fsck_head_link(void)
+static int fsck_head_link(const char **head_points_at,
+ struct object_id *head_oid)
{
int null_is_error = 0;
if (verbose)
fprintf(stderr, "Checking HEAD link\n");
- head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
- if (!head_points_at) {
+ *head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid, NULL);
+ if (!*head_points_at) {
errors_found |= ERROR_REFS;
return error("Invalid HEAD");
}
- if (!strcmp(head_points_at, "HEAD"))
+ if (!strcmp(*head_points_at, "HEAD"))
/* detached HEAD */
null_is_error = 1;
- else if (!starts_with(head_points_at, "refs/heads/")) {
+ else if (!starts_with(*head_points_at, "refs/heads/")) {
errors_found |= ERROR_REFS;
return error("HEAD points to something strange (%s)",
- head_points_at);
+ *head_points_at);
}
- if (is_null_oid(&head_oid)) {
+ if (is_null_oid(head_oid)) {
if (null_is_error) {
errors_found |= ERROR_REFS;
return error("HEAD: detached HEAD points at nothing");
}
fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
- head_points_at + 11);
+ *head_points_at + 11);
}
return 0;
}
@@ -686,7 +692,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
git_config(fsck_config, NULL);
- fsck_head_link();
if (connectivity_only) {
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
--
2.16.1.75.gc01c8fdd7d
next prev parent reply other threads:[~2018-02-09 23:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-09 23:13 [RFC PATCH 0/3] Make fsck check other worktree HEADs Elijah Newren
2018-02-09 23:13 ` Elijah Newren [this message]
2018-02-09 23:13 ` [RFC PATCH 2/3] t1450-fsck: Add tests for HEAD of other worktrees Elijah Newren
2018-02-09 23:13 ` [RFC PATCH 3/3] fsck: Check HEAD of other worktrees as well Elijah Newren
2018-02-10 9:59 ` Duy Nguyen
2018-02-10 12:34 ` Jeff King
2018-02-10 20:11 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180209231330.4457-2-newren@gmail.com \
--to=newren@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).