From patchwork Tue Aug 18 12:17:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11720657 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C34381392 for ; Tue, 18 Aug 2020 12:18:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC0C1206DA for ; Tue, 18 Aug 2020 12:18:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d/a25xmK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbgHRMSE (ORCPT ); Tue, 18 Aug 2020 08:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgHRMSA (ORCPT ); Tue, 18 Aug 2020 08:18:00 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01677C061389 for ; Tue, 18 Aug 2020 05:17:59 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id t14so16768983wmi.3 for ; Tue, 18 Aug 2020 05:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Sx6CMLrWHoHQdFj8ZnUXjNm80mJffZ/ZFDEc2Snpvws=; b=d/a25xmKkzway2fPZJYbCF8HIEw5Q0HnHLA6iRITRvMBPW51LfNdvoycKf3UpMFON2 svb5vYzOn01ZMH4a5SBpGHXjlqgu20LqfE9zsLPNlzqkLdQ7S6s5H9F8wKFqTTzFq/B5 Wmz0kiyj94YJ9ZnjKkdSOlKA8nu9RF0LFt8sEmxj83Yptm0NZoGrWztSmnsBk5OMxi5g kwJOWcM1lQ/mnmnc3KKqYXeL9GUW3Tr+HfDKCeQd1VlmJp8FVrFYeQNsPB8Lq9Xlfdpo aZRYZA8GY1oIfn7f9KVIRUkzfN13jgV30P95AK+4HG0OsVRNRwxfdIEc6QmIoZthME5x Ro9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Sx6CMLrWHoHQdFj8ZnUXjNm80mJffZ/ZFDEc2Snpvws=; b=UAre/+ESoRhKdf9KLGuQzw0rnoP+k3GmnJ3srSx9NjC5TjxISj+vg8WuKvN5gCu02Q JgAuzf3RPaMrUVXnxjFlZSILfxLVJ7TEFvvRVsRDpsCNYPB5F5UPwgR3cnUK8Pof5ox1 dA5FwIv8qzdaNw9x1Wf3vrBhWvRcBd0TV54s6xHlxc7Abc0tHYg5tRKekK2GP1rsD1RR LgHJuBsq0VTXCzCUlcqubQZ3NRAMYJi3Tnqtx51vbCTTJNsrI6Bc4MSTK4Tsrtatvz7S JEt/wkcRSQmyQWmQAFBl3cgY61ciVpR1fhu6rJbCvIAMnx6qmbnoEDkn6t6VMv7s8+fn e0EA== X-Gm-Message-State: AOAM530QTS88zL5UWTEIKUOctR8XjeTYb7giNn2/ypY0puknP0AXF1Of ja+eqFw/AkryWeuv5xTlEmJh4p7v/Vo= X-Google-Smtp-Source: ABdhPJzm/52eYmFlNMoXB7luMaVVADqEgrb6UvdKQf7YU8I+PHgBnuPk/I/kN9Zns83Qh57jxnw4ug== X-Received: by 2002:a1c:1f85:: with SMTP id f127mr20373777wmf.154.1597753078074; Tue, 18 Aug 2020 05:17:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c17sm35891048wrc.42.2020.08.18.05.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 05:17:57 -0700 (PDT) Message-Id: <5e29fa74dc70b5e36ace27ed6d83060cf0925681.1597753075.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Tue, 18 Aug 2020 12:17:53 +0000 Subject: [PATCH 1/3] Make refs_ref_exists public Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- refs.c | 2 +- refs.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index cf91711968..d46080f4b6 100644 --- a/refs.c +++ b/refs.c @@ -313,7 +313,7 @@ int read_ref(const char *refname, struct object_id *oid) return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL); } -static int refs_ref_exists(struct ref_store *refs, const char *refname) +int refs_ref_exists(struct ref_store *refs, const char *refname) { return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL); } diff --git a/refs.h b/refs.h index 29e28124cd..04bd25019f 100644 --- a/refs.h +++ b/refs.h @@ -105,6 +105,8 @@ int refs_verify_refname_available(struct ref_store *refs, const struct string_list *skip, struct strbuf *err); +int refs_ref_exists(struct ref_store *refs, const char *refname); + int ref_exists(const char *refname); int should_autocreate_reflog(const char *refname); From patchwork Tue Aug 18 12:17:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11720659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03C3F138C for ; Tue, 18 Aug 2020 12:18:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7BF420786 for ; Tue, 18 Aug 2020 12:18:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C3ERfpjh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726684AbgHRMSK (ORCPT ); Tue, 18 Aug 2020 08:18:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726422AbgHRMSC (ORCPT ); Tue, 18 Aug 2020 08:18:02 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39A81C061342 for ; Tue, 18 Aug 2020 05:18:01 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z18so18036751wrm.12 for ; Tue, 18 Aug 2020 05:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=nXdXtq+pJkgU+YMl3pIHsZe3H1+zeknwvPy+XSBACD8=; b=C3ERfpjhA1aFknRkHR4065N8i9q2JRYG3rPjSvpnt4L3LVNYkBFTazJpoR5YF0hWAV DwfpORte4hxMUB2t1Y1SFzxoT9qydHyKLTPrF9xIilgWrm3KCH24zK0roOYJXtUjizL1 7VIoc3pBqeYH2eoSc/AjtiHEs4ajOxszcJTGSg7a0GKyn3yH+yPiRNadt70VoYACMnez v7vqMQkRBnS2fbaiws3H/8Ca1ssKcJoFNANjC+W5RplRO7Oz9ZtQqsZA6A716prGUFSZ w25Fbw0rwXeiPpoI1RuYBgg9IJPf+gaRUyjKFKSeIzUklIdrYVuwA2LMdJT1CiVKFKig hOAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=nXdXtq+pJkgU+YMl3pIHsZe3H1+zeknwvPy+XSBACD8=; b=jJzg6GXNR1PP3pgQ1WNJbnmZoEpRN8lEBRFQbEgKHNJUr5C9z/Bg1bkT8mBMLfv2d9 6iozqY017BPVVdzaXAKG4IT5+1h0InEl2ybbgSWGHAUOTilr7NQOCmphAzgBaBz+Rght 44WgThhxS6xcaNVo1xDrk0rWRdS5Ve13BUXvqdKj+6BCpcLjp9zs3/I7M/5f6UTmifjB 8FmAYxmJ1t1gk2CSUdJqN+3ixE8U+lw11yXCE0nd8fF0L3ywxwH7z+59Gdb2tf2Y31dw oaS+1LDDOGD0vTzU3QElvC6Klrw/Zjw4+sBAAGun45zCcpMuaDjeie3RfmHRkrKsXj5d p9Sg== X-Gm-Message-State: AOAM531aypLyBuQqzb19nw4LraJi/hsSRJWgYTLAkruR3gPzo/+zZNzX arZL5tqPm2BJ650/RcmWU5yQsmciJIE= X-Google-Smtp-Source: ABdhPJyxZXLr4xUJyYHjK96NwsiQCdd5Zkxk9DbcHdGKE+kQHC5db+H2FIfnjm+8Np0XPkDuZFIZ1A== X-Received: by 2002:adf:83c5:: with SMTP id 63mr19809429wre.321.1597753079357; Tue, 18 Aug 2020 05:17:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v20sm12779105wrd.6.2020.08.18.05.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 05:17:58 -0700 (PDT) Message-Id: <06a8e8cbd1370ba3d4ea8a0a9f1e69d27b1d62c4.1597753075.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Tue, 18 Aug 2020 12:17:54 +0000 Subject: [PATCH 2/3] Treat CHERRY_PICK_HEAD as a pseudo ref Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys Check for existence and delete CHERRY_PICK_HEAD through ref functions. This will help cherry-pick work with alternate ref storage backends. Signed-off-by: Han-Wen Nienhuys --- builtin/commit.c | 34 +++++++++++++++++++--------------- builtin/merge.c | 2 +- path.c | 1 - path.h | 7 ++++--- sequencer.c | 42 ++++++++++++++++++++++++++---------------- wt-status.c | 4 ++-- 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 69ac78d5e5..619b71bcb4 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -847,21 +847,25 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && !merge_contains_scissors) wt_status_add_cut_line(s->fp); - status_printf_ln(s, GIT_COLOR_NORMAL, - whence == FROM_MERGE - ? _("\n" - "It looks like you may be committing a merge.\n" - "If this is not correct, please remove the file\n" - " %s\n" - "and try again.\n") - : _("\n" - "It looks like you may be committing a cherry-pick.\n" - "If this is not correct, please remove the file\n" - " %s\n" - "and try again.\n"), - whence == FROM_MERGE ? - git_path_merge_head(the_repository) : - git_path_cherry_pick_head(the_repository)); + if (whence == FROM_MERGE) + status_printf_ln( + s, GIT_COLOR_NORMAL, + + _("\n" + "It looks like you may be committing a merge.\n" + "If this is not correct, please remove the file\n" + " %s\n" + "and try again.\n"), + git_path_merge_head(the_repository)); + else + status_printf_ln( + s, GIT_COLOR_NORMAL, + + _("\n" + "It looks like you may be committing a cherry-pick.\n" + "If this is not correct, please run\n" + " git cherry-pick --abort\n" + "and try again.\n")); } fprintf(s->fp, "\n"); diff --git a/builtin/merge.c b/builtin/merge.c index 74829a838e..b9a89ba858 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1348,7 +1348,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) else die(_("You have not concluded your merge (MERGE_HEAD exists).")); } - if (file_exists(git_path_cherry_pick_head(the_repository))) { + if (ref_exists("CHERRY_PICK_HEAD")) { if (advice_resolve_conflict) die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n" "Please, commit your changes before you merge.")); diff --git a/path.c b/path.c index 8b2c753191..783cc2ae81 100644 --- a/path.c +++ b/path.c @@ -1528,7 +1528,6 @@ char *xdg_cache_home(const char *filename) return NULL; } -REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD") REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD") REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG") REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG") diff --git a/path.h b/path.h index 1f1bf8f87a..8941c018a9 100644 --- a/path.h +++ b/path.h @@ -170,7 +170,6 @@ void report_linked_checkout_garbage(void); } struct path_cache { - const char *cherry_pick_head; const char *revert_head; const char *squash_msg; const char *merge_msg; @@ -182,9 +181,11 @@ struct path_cache { const char *shallow; }; -#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } +#define PATH_CACHE_INIT \ + { \ + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \ + } -const char *git_path_cherry_pick_head(struct repository *r); const char *git_path_revert_head(struct repository *r); const char *git_path_squash_msg(struct repository *r); const char *git_path_merge_msg(struct repository *r); diff --git a/sequencer.c b/sequencer.c index cc3f8fa88e..09e2ff659e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -381,7 +381,8 @@ static void print_advice(struct repository *r, int show_hint, * (typically rebase --interactive) wants to take care * of the commit itself so remove CHERRY_PICK_HEAD */ - unlink(git_path_cherry_pick_head(r)); + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD", + NULL, 0); return; } @@ -1455,7 +1456,8 @@ static int do_commit(struct repository *r, author, opts, flags, &oid); strbuf_release(&sb); if (!res) { - unlink(git_path_cherry_pick_head(r)); + refs_delete_ref(get_main_ref_store(r), "", + "CHERRY_PICK_HEAD", NULL, 0); unlink(git_path_merge_msg(r)); if (!is_rebase_i(opts)) print_commit_summary(r, NULL, &oid, @@ -1966,7 +1968,8 @@ static int do_pick_commit(struct repository *r, flags |= ALLOW_EMPTY; } else if (allow == 2) { drop_commit = 1; - unlink(git_path_cherry_pick_head(r)); + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD", + NULL, 0); unlink(git_path_merge_msg(r)); fprintf(stderr, _("dropping %s %s -- patch contents already upstream\n"), @@ -2305,8 +2308,10 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose) struct replay_opts opts = REPLAY_OPTS_INIT; int need_cleanup = 0; - if (file_exists(git_path_cherry_pick_head(r))) { - if (!unlink(git_path_cherry_pick_head(r)) && verbose) + if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) { + if (!refs_delete_ref(get_main_ref_store(r), "", + "CHERRY_PICK_HEAD", NULL, 0) && + verbose) warning(_("cancelling a cherry picking in progress")); opts.action = REPLAY_PICK; need_cleanup = 1; @@ -2671,8 +2676,9 @@ static int create_seq_dir(struct repository *r) enum replay_action action; const char *in_progress_error = NULL; const char *in_progress_advice = NULL; - unsigned int advise_skip = file_exists(git_path_revert_head(r)) || - file_exists(git_path_cherry_pick_head(r)); + unsigned int advise_skip = + file_exists(git_path_revert_head(r)) || + refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD"); if (!sequencer_get_last_command(r, &action)) { switch (action) { @@ -2771,7 +2777,7 @@ static int rollback_single_pick(struct repository *r) { struct object_id head_oid; - if (!file_exists(git_path_cherry_pick_head(r)) && + if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && !file_exists(git_path_revert_head(r))) return error(_("no cherry-pick or revert in progress")); if (read_ref_full("HEAD", 0, &head_oid, NULL)) @@ -2874,7 +2880,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts) } break; case REPLAY_PICK: - if (!file_exists(git_path_cherry_pick_head(r))) { + if (!refs_ref_exists(get_main_ref_store(r), + "CHERRY_PICK_HEAD")) { if (action != REPLAY_PICK) return error(_("no cherry-pick in progress")); if (!rollback_is_safe()) @@ -3569,7 +3576,8 @@ static int do_merge(struct repository *r, oid_to_hex(&j->item->object.oid)); strbuf_release(&ref_name); - unlink(git_path_cherry_pick_head(r)); + refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD", + NULL, 0); rollback_lock_file(&lock); rollback_lock_file(&lock); @@ -4201,7 +4209,7 @@ static int continue_single_pick(struct repository *r) { const char *argv[] = { "commit", NULL }; - if (!file_exists(git_path_cherry_pick_head(r)) && + if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && !file_exists(git_path_revert_head(r))) return error(_("no cherry-pick or revert in progress")); return run_command_v_opt(argv, RUN_GIT_CMD); @@ -4318,9 +4326,10 @@ static int commit_staged_changes(struct repository *r, } if (is_clean) { - const char *cherry_pick_head = git_path_cherry_pick_head(r); - - if (file_exists(cherry_pick_head) && unlink(cherry_pick_head)) + if (refs_ref_exists(get_main_ref_store(r), + "CHERRY_PICK_HEAD") && + refs_delete_ref(get_main_ref_store(r), "", + "CHERRY_PICK_HEAD", NULL, 0)) return error(_("could not remove CHERRY_PICK_HEAD")); if (!final_fixup) return 0; @@ -4379,7 +4388,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) if (!is_rebase_i(opts)) { /* Verify that the conflict has been resolved */ - if (file_exists(git_path_cherry_pick_head(r)) || + if (refs_ref_exists(get_main_ref_store(r), + "CHERRY_PICK_HEAD") || file_exists(git_path_revert_head(r))) { res = continue_single_pick(r); if (res) @@ -5442,7 +5452,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) int sequencer_determine_whence(struct repository *r, enum commit_whence *whence) { - if (file_exists(git_path_cherry_pick_head(r))) { + if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD")) { struct object_id cherry_pick_head, rebase_head; if (file_exists(git_path_seq_dir())) diff --git a/wt-status.c b/wt-status.c index d75399085d..c6abf2f3ca 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1672,8 +1672,8 @@ void wt_status_get_state(struct repository *r, state->merge_in_progress = 1; } else if (wt_status_check_rebase(NULL, state)) { ; /* all set */ - } else if (!stat(git_path_cherry_pick_head(r), &st) && - !get_oid("CHERRY_PICK_HEAD", &oid)) { + } else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && + !get_oid("CHERRY_PICK_HEAD", &oid)) { state->cherry_pick_in_progress = 1; oidcpy(&state->cherry_pick_head_oid, &oid); } From patchwork Tue Aug 18 12:17:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11720661 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 381EF138C for ; Tue, 18 Aug 2020 12:18:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C9772076D for ; Tue, 18 Aug 2020 12:18:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="grFmrUpF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbgHRMSK (ORCPT ); Tue, 18 Aug 2020 08:18:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbgHRMSC (ORCPT ); Tue, 18 Aug 2020 08:18:02 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB96AC061343 for ; Tue, 18 Aug 2020 05:18:01 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id f1so18069924wro.2 for ; Tue, 18 Aug 2020 05:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=JVkcrNkHn5N5zbWK87SPiCDfzN15XxBwL82x0K4dR3Q=; b=grFmrUpFRd4XGgD8Itz9wmSErAnsRbYn17qNQfOAF4YqL68T+OT4MFk58lXcjjK3Nx CI5/ibGStQTOX1TmtU7zB9/9FAjzK5+aK032XjkBV6JMrzmTB++UJ7xlcpA0YhxNbSKB ZIdkgeebI4Z4olkvoi5cB4A/RCnICCDsPhjrB5cDbwsySgL0/jGW16zJ+BYL14C3JwPh NGiWA+tiwG4i1yah4L3lNn7MKQ8qSVZ+NqFp85RO/Vf7pOlAXePHfpgdlAxE2ZyWSI35 sxZeh5d1UIe032b1TFPF0mobv17RskPUhPPumodu9SGi7Z63DPDKyV8uzPFmKupO2tpv QWqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=JVkcrNkHn5N5zbWK87SPiCDfzN15XxBwL82x0K4dR3Q=; b=s10Zlp20NvY4i6pm9Kq5IQHPbkt0BLb5hSCVs/p7kykTJKqmtUr9BBGLPQRP9dn+QD eZxuLRzM8zNx6sp0LZdaVQJSQeCDTRvI3WBrOlwgiSeqlvzLkrxWRsyclfuTCfLa6Ru7 G8kLNmlPMlOjOt/uCQbcOaFkrOSdksRajbH4RpOoK2NiKlcDZa5zeodASBt2daE3Q76n ZKqHjOBluqNjc8r05lUDl0o4Mx++IoarVM12WMIEAEkza0XCWC4IpSw78ggFlQFujjqQ A2OKYGzUZUWUiEJH1bO9IOO0CVO+Kt08K51X/9sNSMcp6iFfE5z07nizij8Ajz778J6g SbPQ== X-Gm-Message-State: AOAM5322b14TwPfKAHuebCuoFqw4T1eeAtCMxnRO0CE+LUgibV5VdOGx CagKZKesCttU7zl/sRq88q296QC/WPw= X-Google-Smtp-Source: ABdhPJyJH72pIGBOUVGdQrlf8Y5yST1D5ZjyQz+7au7YIeM9prL5N3Texxb2YTaBhU2o2Kc98thf2g== X-Received: by 2002:a5d:4144:: with SMTP id c4mr19784247wrq.200.1597753080095; Tue, 18 Aug 2020 05:18:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c10sm33946075wrx.15.2020.08.18.05.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 05:17:59 -0700 (PDT) Message-Id: <173d81dbb41c3a7f4ab5187c1a056da182c4f6e5.1597753075.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Tue, 18 Aug 2020 12:17:55 +0000 Subject: [PATCH 3/3] Treat REVERT_HEAD as a pseudo ref Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- path.c | 1 - path.h | 8 +++----- sequencer.c | 16 +++++++++------- wt-status.c | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/path.c b/path.c index 783cc2ae81..7b385e5eb2 100644 --- a/path.c +++ b/path.c @@ -1528,7 +1528,6 @@ char *xdg_cache_home(const char *filename) return NULL; } -REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD") REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG") REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG") REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR") diff --git a/path.h b/path.h index 8941c018a9..e7e77da6aa 100644 --- a/path.h +++ b/path.h @@ -170,7 +170,6 @@ void report_linked_checkout_garbage(void); } struct path_cache { - const char *revert_head; const char *squash_msg; const char *merge_msg; const char *merge_rr; @@ -181,12 +180,11 @@ struct path_cache { const char *shallow; }; -#define PATH_CACHE_INIT \ - { \ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \ +#define PATH_CACHE_INIT \ + { \ + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \ } -const char *git_path_revert_head(struct repository *r); const char *git_path_squash_msg(struct repository *r); const char *git_path_merge_msg(struct repository *r); const char *git_path_merge_rr(struct repository *r); diff --git a/sequencer.c b/sequencer.c index 09e2ff659e..d116ea69bd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2317,8 +2317,10 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose) need_cleanup = 1; } - if (file_exists(git_path_revert_head(r))) { - if (!unlink(git_path_revert_head(r)) && verbose) + if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) { + if (!refs_delete_ref(get_main_ref_store(r), "", "REVERT_HEAD", + NULL, 0) && + verbose) warning(_("cancelling a revert in progress")); opts.action = REPLAY_REVERT; need_cleanup = 1; @@ -2677,7 +2679,7 @@ static int create_seq_dir(struct repository *r) const char *in_progress_error = NULL; const char *in_progress_advice = NULL; unsigned int advise_skip = - file_exists(git_path_revert_head(r)) || + refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") || refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD"); if (!sequencer_get_last_command(r, &action)) { @@ -2778,7 +2780,7 @@ static int rollback_single_pick(struct repository *r) struct object_id head_oid; if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && - !file_exists(git_path_revert_head(r))) + !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) return error(_("no cherry-pick or revert in progress")); if (read_ref_full("HEAD", 0, &head_oid, NULL)) return error(_("cannot resolve HEAD")); @@ -2872,7 +2874,7 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts) */ switch (opts->action) { case REPLAY_REVERT: - if (!file_exists(git_path_revert_head(r))) { + if (!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) { if (action != REPLAY_REVERT) return error(_("no revert in progress")); if (!rollback_is_safe()) @@ -4210,7 +4212,7 @@ static int continue_single_pick(struct repository *r) const char *argv[] = { "commit", NULL }; if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") && - !file_exists(git_path_revert_head(r))) + !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) return error(_("no cherry-pick or revert in progress")); return run_command_v_opt(argv, RUN_GIT_CMD); } @@ -4390,7 +4392,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) /* Verify that the conflict has been resolved */ if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") || - file_exists(git_path_revert_head(r))) { + refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD")) { res = continue_single_pick(r); if (res) goto release_todo_list; diff --git a/wt-status.c b/wt-status.c index c6abf2f3ca..ecbe570e28 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1678,7 +1678,7 @@ void wt_status_get_state(struct repository *r, oidcpy(&state->cherry_pick_head_oid, &oid); } wt_status_check_bisect(NULL, state); - if (!stat(git_path_revert_head(r), &st) && + if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") && !get_oid("REVERT_HEAD", &oid)) { state->revert_in_progress = 1; oidcpy(&state->revert_head_oid, &oid);