From patchwork Wed May 22 09:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670614 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9225480607 for ; Wed, 22 May 2024 09:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368614; cv=none; b=iaLwoLjkecSwCzLmK7YktpCdjoM0meN69QpDFj/vOl177nGG9+QY/3TJryfvEkOKlJvzU4xE0dDY4ki7gAGxsMBtIlRw6u6SGylimmoH2a7TgWMyrgZ+fh1oY2hU9qWj+9Py9mpyO6lKHMmkkK4xl2rID26VsN6zxAupvLN/0oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368614; c=relaxed/simple; bh=h99lto38gvDSFS+LM7fh69jI+qhFIxdReuA5l1HWbGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q9Y46W+TLqnyvQqVA86CgFogIfqgwzp+AL8lO65PNfIE86IRHuuMlXxPr7CdEInGOOEKOYEU+JsQjTiV5NSUs7xDc4quPtDKZX1JB7fwgVwy57AvMzbcRHTUVwgNAqxHLX4ZoX1qVV5uYjGBr7p6dJtpK+AaC8KJd+nRowrrrZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lhZxe/In; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lhZxe/In" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-572669fd9f9so9921885a12.0 for ; Wed, 22 May 2024 02:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368611; x=1716973411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MdWWKo/gycfWwrs6jjjSXW/PKVbEMO/4cVQB+ft7/r0=; b=lhZxe/InnnqymV2FmYiqNljbBV4qB2opuX0WkIl+TleMEv++p0b46suwg2rOkpgceJ duE9QXYXn/pZdo1yo3V2e9A6zqpy95MxNZCORD+6JRK3RI1QBWykYi9T7RkdYjJfWqTu 2HEF7qpCuBOhszulKsvkVRVkvbfDrTZfe7CT+WTlPH4doxQhN55QTlvTGEniMyGMU0um 4O+kidHHxyWQYSh9GuNRz2SYPeLaI9Rppn7X9Mln5mBgG+jswOa2Fye401ftWv+pyE5b ddrdgPonTRrYVwauUR9FkjtFty50KKRKiG3xDAX6+92zdSWueYUL+yBI7mEESDeN/H9W df9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368611; x=1716973411; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MdWWKo/gycfWwrs6jjjSXW/PKVbEMO/4cVQB+ft7/r0=; b=bDAkaHe39rdtv+2504u5vb3eS6eZbixo5eEc2T97g4vRj65Y25ebLDPs+xslHN7bEL vAtsWojIvp7iK1oRaFdpxtC2SYcuz4HwyoCJSuqXnYl+OehhMosV/QdTrxxIXlvUv0j9 uCMpSY18qeqUjnkRkfdYfaU7H+Fz3U/l06uWVkTPFHIFxuwzS7nedQeW9vcUCqIhf8ez yWPO9/neBju9aVM3Wj2wkpFcf57Z6Brg6pZGmCaufwQRe+Cr4NEjLPWIMx1NRr2rJ9eW MIn0u/2DQbBGCokdX/J8erZIiWaXOXfUdMgHFgYUQhRgoZ475MHeB4imxoqFLuTt21+3 q0Nw== X-Gm-Message-State: AOJu0YyR9Wg4tqQp5/77X0184n2rt7XBpz4W88+AjqirxST5bYGVoIMT x1ZCbqR3nN4eEJC7ZtIdNOxIfIlDSVgJ/2FyhE7F2bYQjlmNFtasvHuG49w9 X-Google-Smtp-Source: AGHT+IFjgacEF2Y4aKR/I4JBGAu73mSLetfGq/F7lrYPTwfWovGukimzmE6oFNdUm9ZOD+dmskKofA== X-Received: by 2002:a50:d6ca:0:b0:570:369:3e06 with SMTP id 4fb4d7f45d1cf-57832a96712mr865989a12.19.1716368610705; Wed, 22 May 2024 02:03:30 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:30 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 1/6] refs: create and use `ref_update_expects_existing_old_ref()` Date: Wed, 22 May 2024 11:03:21 +0200 Message-ID: <20240522090326.1268326-2-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak The files and reftable backend, need to check if a ref must exist, so that the required validation can be done. A ref must exist only when the `old_oid` value of the update has been explicitly set and it is not the `null_oid` value. Since we also support symrefs now, we need to ensure that even when `old_target` is set a ref must exist. While this was missed when we added symref support in transactions, there are no active users of this path. As we introduce the 'symref-verify' command in the upcoming commits, it is important to fix this. So let's export this to a function called `ref_update_expects_existing_old_ref()` and expose it internally via 'refs-internal.h'. Signed-off-by: Karthik Nayak --- refs.c | 6 ++++++ refs/files-backend.c | 3 +-- refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/refs.c b/refs.c index fa5471d219..00e87f8ee3 100644 --- a/refs.c +++ b/refs.c @@ -2863,3 +2863,9 @@ int ref_update_check_old_target(const char *referent, struct ref_update *update, referent, update->old_target); return -1; } + +int ref_update_expects_existing_old_ref(struct ref_update *update) +{ + return (update->flags & REF_HAVE_OLD) && + (!is_null_oid(&update->old_oid) || update->old_target); +} diff --git a/refs/files-backend.c b/refs/files-backend.c index 3957bfa579..ef760869ca 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2411,8 +2411,7 @@ static int lock_ref_for_update(struct files_ref_store *refs, struct strbuf *err) { struct strbuf referent = STRBUF_INIT; - int mustexist = (update->flags & REF_HAVE_OLD) && - !is_null_oid(&update->old_oid); + int mustexist = ref_update_expects_existing_old_ref(update); int ret = 0; struct ref_lock *lock; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 53a6c5d842..ee298ec0d5 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -765,4 +765,10 @@ int ref_update_has_null_new_value(struct ref_update *update); int ref_update_check_old_target(const char *referent, struct ref_update *update, struct strbuf *err); +/* + * Check if the ref must exist, this means that the old_oid or + * old_target is non NULL. + */ +int ref_update_expects_existing_old_ref(struct ref_update *update); + #endif /* REFS_REFS_INTERNAL_H */ diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 98cebbcf39..dc7aa7f274 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -825,7 +825,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, ¤t_oid, &referent, &u->type); if (ret < 0) goto done; - if (ret > 0 && (!(u->flags & REF_HAVE_OLD) || is_null_oid(&u->old_oid))) { + if (ret > 0 && !ref_update_expects_existing_old_ref(u)) { /* * The reference does not exist, and we either have no * old object ID or expect the reference to not exist. From patchwork Wed May 22 09:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670616 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E90C80611 for ; Wed, 22 May 2024 09:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368615; cv=none; b=qsElwPYkW//rMUM5u8hl/iNNRZAUkvNyqmEvc6tQ2XXsh4IaCe0p1auQNmSMJmLUVuJNxZh1jVjjmVrx1/s5+i25KyAvvDXHp9YibYFBHs4GHLGonuF704bIrjENfVp+1ZU/26yb9wkvlY2ZAX7/sfLzhwXfkwLPgdzAhR2K6FQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368615; c=relaxed/simple; bh=E/rDMuvC7ejp70OtRXI6YzJv/ZnnWdVbW1zlM1nt04Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EzkxyDFnNh/YdVoK76yPhcV48Ke2nwO+/1L9s+FzeYlokAZru4/mlwZMyUs5z68R5dyt6709Mrv5rdm+Asub0X3h09VHIhnweFYmQWqphYgt02M7U5S2Rm1jGGGVP0LChh+JNk1HLQ/6x2lHrO9QV8Z/+THYzw8HX3fsfICm+2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZbLKHIu5; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZbLKHIu5" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5731ffcc905so11038047a12.2 for ; Wed, 22 May 2024 02:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368612; x=1716973412; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lp7ewlZJB7OAuxMaMwEEG27PpzvfYRixttjuh/lANew=; b=ZbLKHIu5swP/V+6FBir210JlQGI+rxf2npBo2taR9SPXzDO7wWOsuA3sXR2oz1A5y4 w9v8mhwKZpbszgQS20Iv3ll3gF5x4CzdvCRVqkzCol/Eo6ErYda8lrUUAyL3Da5lmoT6 JE65fhCilashaSS9KtTmSyAbtuql7B4taAZi/ljrRCwhMdvmaZGdOWuH01dEz81Z9PcK FiBo77MWNjcYMdySoLptCgOFtjOu6V82eU3vspY2f7GdGN8aW1eLU1F3Qu8GcwmRWFTh nnqYFjYN9tYANQgqHSccRXxf5wDXwOOAW85wVj3baJpyB5KBejGRUeSb+xc/uB7JwI8N TlJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368612; x=1716973412; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lp7ewlZJB7OAuxMaMwEEG27PpzvfYRixttjuh/lANew=; b=e7vHbkjQcBEyMv0G2odloKWV5zoB7E5wzfqu8EkmJbcvA5kvUvJk2cUG7oUhDWpDMS /9SrGJ/KLH2miT9HU3VRydY2dNGqDyIUszXBOFRqWMohU+WHIxj47kNUO0P0hPbIqh59 MfW1iYs0VzSOM1mNlhJIMJyePggFwGc+n9atFzlFBez0zQM2+TcobnuOH+Nn7ugbuHWZ atRH97br0fWXThed7VksekO8OmiGs9MQGGoM0L5G1zX/P2stO8MsbP7YyUlfznopph9q FIxeL5Th7ii0OACMasQ3+VcdVmcbw6awqEmvvoQNiqH0RHeyMoGcNIm0d6/T67VpXR9U g/4Q== X-Gm-Message-State: AOJu0YzFrltN9oqpnQOYxQ0RPe0uGbJUMGunPcJWWqUe6ts2XCsVxwk5 XAgJZ2StLVOWNw9SRT16lqGAGPI2fqTCJDE36WKpFXufqdMO2AMsNTaRVAwP X-Google-Smtp-Source: AGHT+IHX0vvdaorCWZCIRIeA8KT4q64wjablLdslZX62bfvl5lCAFix8C8Wlk7wkhPGNbIBjr782Ig== X-Received: by 2002:a50:d74e:0:b0:573:55ca:8f15 with SMTP id 4fb4d7f45d1cf-57832c11a20mr1114344a12.39.1716368611569; Wed, 22 May 2024 02:03:31 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:31 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 2/6] update-ref: add support for 'symref-verify' command Date: Wed, 22 May 2024 11:03:22 +0200 Message-ID: <20240522090326.1268326-3-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak The 'symref-verify' command allows users to verify if a provided contains the provided without changing the . If is not provided, the command will verify that the doesn't exist. The command allows users to verify symbolic refs within a transaction, and this means users can perform a set of changes in a transaction only when the verification holds good. Since we're checking for symbolic refs, this command will only work with the 'no-deref' mode. This is because any dereferenced symbolic ref will point to an object and not a ref and the regular 'verify' command can be used in such situations. Add required tests for symref support in 'verify'. Since we're here, also add reflog checks for the pre-existing 'verify' tests, there is no divergence from behavior, but we never tested to ensure that reflog wasn't affected by the 'verify' command. Signed-off-by: Karthik Nayak --- Documentation/git-update-ref.txt | 7 +++ builtin/update-ref.c | 80 +++++++++++++++++++++++---- refs.c | 11 +++- refs.h | 1 + t/t1400-update-ref.sh | 94 +++++++++++++++++++++++++++++++- t/t1416-ref-transaction-hooks.sh | 30 ++++++++++ 6 files changed, 208 insertions(+), 15 deletions(-) diff --git a/Documentation/git-update-ref.txt b/Documentation/git-update-ref.txt index 374a2ebd2b..9fe78b3501 100644 --- a/Documentation/git-update-ref.txt +++ b/Documentation/git-update-ref.txt @@ -65,6 +65,7 @@ performs all modifications together. Specify commands of the form: create SP SP LF delete SP [SP ] LF verify SP [SP ] LF + symref-verify SP [SP ] LF option SP LF start LF prepare LF @@ -86,6 +87,7 @@ quoting: create SP NUL NUL delete SP NUL [] NUL verify SP NUL [] NUL + symref-verify SP [NUL ] NUL option SP NUL start NUL prepare NUL @@ -117,6 +119,11 @@ verify:: Verify against but do not change it. If is zero or missing, the ref must not exist. +symref-verify:: + Verify symbolic against but do not change it. + If is missing, the ref must not exist. Can only be + used in `no-deref` mode. + option:: Modify the behavior of the next command naming a . The only valid option is `no-deref` to avoid dereferencing diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 21fdbf6ac8..6dce1cd663 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -76,6 +76,29 @@ static char *parse_refname(const char **next) return strbuf_detach(&ref, NULL); } +/* + * Wrapper around parse_refname which skips the next delimiter. + */ +static char *parse_next_refname(const char **next) +{ + if (line_termination) { + /* Without -z, consume SP and use next argument */ + if (!**next || **next == line_termination) + return NULL; + if (**next != ' ') + die("expected SP but got: %s", *next); + } else { + /* With -z, read the next NUL-terminated line */ + if (**next) + return NULL; + } + /* Skip the delimiter */ + (*next)++; + + return parse_refname(next); +} + + /* * The value being parsed is (as opposed to ; the * difference affects which error messages are generated): @@ -297,11 +320,47 @@ static void parse_cmd_verify(struct ref_transaction *transaction, die("verify %s: extra input: %s", refname, next); if (ref_transaction_verify(transaction, refname, &old_oid, - update_flags, &err)) + NULL, update_flags, &err)) + die("%s", err.buf); + + update_flags = default_flags; + free(refname); + strbuf_release(&err); +} + +static void parse_cmd_symref_verify(struct ref_transaction *transaction, + const char *next, const char *end) +{ + struct strbuf err = STRBUF_INIT; + struct object_id old_oid; + char *refname, *old_target; + + if (!(update_flags & REF_NO_DEREF)) + die("symref-verify: cannot operate with deref mode"); + + refname = parse_refname(&next); + if (!refname) + die("symref-verify: missing "); + + /* + * old_ref is optional, if not provided, we need to ensure that the + * ref doesn't exist. + */ + old_target = parse_next_refname(&next); + if (!old_target) + oidcpy(&old_oid, null_oid()); + + if (*next != line_termination) + die("symref-verify %s: extra input: %s", refname, next); + + if (ref_transaction_verify(transaction, refname, + old_target ? NULL : &old_oid, + old_target, update_flags, &err)) die("%s", err.buf); update_flags = default_flags; free(refname); + free(old_target); strbuf_release(&err); } @@ -380,15 +439,16 @@ static const struct parse_cmd { unsigned args; enum update_refs_state state; } command[] = { - { "update", parse_cmd_update, 3, UPDATE_REFS_OPEN }, - { "create", parse_cmd_create, 2, UPDATE_REFS_OPEN }, - { "delete", parse_cmd_delete, 2, UPDATE_REFS_OPEN }, - { "verify", parse_cmd_verify, 2, UPDATE_REFS_OPEN }, - { "option", parse_cmd_option, 1, UPDATE_REFS_OPEN }, - { "start", parse_cmd_start, 0, UPDATE_REFS_STARTED }, - { "prepare", parse_cmd_prepare, 0, UPDATE_REFS_PREPARED }, - { "abort", parse_cmd_abort, 0, UPDATE_REFS_CLOSED }, - { "commit", parse_cmd_commit, 0, UPDATE_REFS_CLOSED }, + { "update", parse_cmd_update, 3, UPDATE_REFS_OPEN }, + { "create", parse_cmd_create, 2, UPDATE_REFS_OPEN }, + { "delete", parse_cmd_delete, 2, UPDATE_REFS_OPEN }, + { "verify", parse_cmd_verify, 2, UPDATE_REFS_OPEN }, + { "symref-verify", parse_cmd_symref_verify, 2, UPDATE_REFS_OPEN }, + { "option", parse_cmd_option, 1, UPDATE_REFS_OPEN }, + { "start", parse_cmd_start, 0, UPDATE_REFS_STARTED }, + { "prepare", parse_cmd_prepare, 0, UPDATE_REFS_PREPARED }, + { "abort", parse_cmd_abort, 0, UPDATE_REFS_CLOSED }, + { "commit", parse_cmd_commit, 0, UPDATE_REFS_CLOSED }, }; static void update_refs_stdin(void) diff --git a/refs.c b/refs.c index 00e87f8ee3..865264d487 100644 --- a/refs.c +++ b/refs.c @@ -1331,14 +1331,19 @@ int ref_transaction_delete(struct ref_transaction *transaction, int ref_transaction_verify(struct ref_transaction *transaction, const char *refname, const struct object_id *old_oid, + const char *old_target, unsigned int flags, struct strbuf *err) { - if (!old_oid) - BUG("verify called with old_oid set to NULL"); + if (!old_target && !old_oid) + BUG("verify called with old_oid and old_target set to NULL"); + if (old_oid && old_target) + BUG("verify called with both old_oid and old_target set"); + if (old_target && !(flags & REF_NO_DEREF)) + BUG("verify cannot operate on symrefs with deref mode"); return ref_transaction_update(transaction, refname, NULL, old_oid, - NULL, NULL, + NULL, old_target, flags, NULL, err); } diff --git a/refs.h b/refs.h index 71cc1c58e0..48cec1ba72 100644 --- a/refs.h +++ b/refs.h @@ -781,6 +781,7 @@ int ref_transaction_delete(struct ref_transaction *transaction, int ref_transaction_verify(struct ref_transaction *transaction, const char *refname, const struct object_id *old_oid, + const char *old_target, unsigned int flags, struct strbuf *err); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index ec3443cc87..07e111b063 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -890,17 +890,23 @@ test_expect_success 'stdin update/create/verify combination works' ' ' test_expect_success 'stdin verify succeeds for correct value' ' + test-tool ref-store main for-each-reflog-ent $m >before && git rev-parse $m >expect && echo "verify $m $m" >stdin && git update-ref --stdin actual && - test_cmp expect actual + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent $m >after && + test_cmp before after ' test_expect_success 'stdin verify succeeds for missing reference' ' + test-tool ref-store main for-each-reflog-ent $m >before && echo "verify refs/heads/missing $Z" >stdin && git update-ref --stdin after && + test_cmp before after ' test_expect_success 'stdin verify treats no value as missing' ' @@ -1641,4 +1647,88 @@ test_expect_success PIPE 'transaction flushes status updates' ' test_cmp expected actual ' +format_command () { + if test "$1" = "-z" + then + shift + printf "$F" "$@" + else + echo "$@" + fi +} + +for type in "" "-z" +do + + test_expect_success "stdin $type symref-verify fails without --no-deref" ' + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-verify refs/heads/symref" "$a" >stdin && + test_must_fail git update-ref --stdin $type err && + grep "fatal: symref-verify: cannot operate with deref mode" err + ' + + test_expect_success "stdin $type symref-verify fails with too many arguments" ' + format_command $type "symref-verify refs/heads/symref" "$a" "$a" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + if test "$type" = "-z" + then + grep "fatal: unknown command: $a" err + else + grep "fatal: symref-verify refs/heads/symref: extra input: $a" err + fi + ' + + test_expect_success "stdin $type symref-verify succeeds for correct value" ' + git symbolic-ref refs/heads/symref >expect && + test-tool ref-store main for-each-reflog-ent refs/heads/symref >before && + format_command $type "symref-verify refs/heads/symref" "$a" >stdin && + git update-ref --stdin $type --no-deref actual && + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent refs/heads/symref >after && + test_cmp before after + ' + + test_expect_success "stdin $type symref-verify fails with no value" ' + git symbolic-ref refs/heads/symref >expect && + format_command $type "symref-verify refs/heads/symref" "" >stdin && + test_must_fail git update-ref --stdin $type --no-deref stdin && + git update-ref --stdin $type --no-deref before && + format_command $type "symref-verify refs/heads/missing" "refs/heads/unknown" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + grep "fatal: cannot lock ref ${SQ}refs/heads/missing${SQ}: unable to resolve reference ${SQ}refs/heads/missing${SQ}" err && + test_must_fail git rev-parse --verify -q refs/heads/missing && + test-tool ref-store main for-each-reflog-ent refs/heads/symref >after && + test_cmp before after + ' + + test_expect_success "stdin $type symref-verify fails for wrong value" ' + git symbolic-ref refs/heads/symref >expect && + format_command $type "symref-verify refs/heads/symref" "$b" >stdin && + test_must_fail git update-ref --stdin $type --no-deref actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-verify fails for mistaken null value" ' + git symbolic-ref refs/heads/symref >expect && + format_command $type "symref-verify refs/heads/symref" "$Z" >stdin && + test_must_fail git update-ref --stdin $type --no-deref actual && + test_cmp expect actual + ' + +done + test_done diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 067fd57290..fd58b902f4 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -157,4 +157,34 @@ test_expect_success 'hook captures git-symbolic-ref updates' ' test_cmp expect actual ' +test_expect_success 'hook gets all queued symref updates' ' + test_when_finished "rm actual" && + + git update-ref refs/heads/branch $POST_OID && + git symbolic-ref refs/heads/symref refs/heads/main && + + test_hook reference-transaction <<-\EOF && + echo "$*" >>actual + while read -r line + do + printf "%s\n" "$line" + done >>actual + EOF + + cat >expect <<-EOF && + prepared + ref:refs/heads/main $ZERO_OID refs/heads/symref + committed + ref:refs/heads/main $ZERO_OID refs/heads/symref + EOF + + git update-ref --no-deref --stdin <<-EOF && + start + symref-verify refs/heads/symref refs/heads/main + prepare + commit + EOF + test_cmp expect actual +' + test_done From patchwork Wed May 22 09:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670617 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE6E080632 for ; Wed, 22 May 2024 09:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368616; cv=none; b=ch8erI3vaw6KW+E63amAgZdy/YDnvJgmnjKAb6bp0sfZovWMGxOkbd3+lNHfWkcCCqB2MdszSJQKipT48nEeSq6JgoDH9er8RDERVrdzRny6tIo19rXzyFjtmnl4iDHGEFcdbVAYvcff9tcs6K1hCmTFqQC9JTxvae6mzxggBwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368616; c=relaxed/simple; bh=HZQeBlGGeL/gxQU58fHe4ME63q+oE5R76esqen9PpXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sS70MA7SHTEPPMCkGra1UOPEL633fkEW6kMvLbsUDeMP+Ag9KoHC9cmehPhp3ybHVnWYe9WS7vK7KC59QN3ZnZHVnt6P034++YIXle9JVcFuxwcb/Pf2+2A9gzsmPsc9N/myzWQGHaY3neZ0hMr0s1R63et+MUNZXTMZG43m6iM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EmRlmBCE; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EmRlmBCE" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-571ba432477so11096907a12.1 for ; Wed, 22 May 2024 02:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368613; x=1716973413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eGVphmbiPVn7ximhQRvx4E885yMC909YJDzBXXFur4I=; b=EmRlmBCEp9vd99aalgLV121MtWfT0KdZBf/n210nI0YcEu/et6y6+vld7mxrOgEy0a xBpES2snXGHwZaF2aCjiz4oPbr8qR7XCRp3nUZLHdbUFp8PNezjOCs+bdT8MGcgAgbBa VtTRVrs40+gMtF8kLg57Rr5IklCUtWmbnhvXyPQpK/aecvVzhbCcxrgTOOMwXtNOE7UW G9HItbhKHr17sxseIurfXQZ8CtQHuYzJKQC25IqjdxpujhIfkKSEwar87TZKxSEU34VT t/+vAGLcdF/bpnSpTGlEjI6IUZ/M4SVAgmLv8/0A4iAzKB7vR4lEKvEnKvHMx0wgcpfw +jyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368613; x=1716973413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eGVphmbiPVn7ximhQRvx4E885yMC909YJDzBXXFur4I=; b=wj6Poq8qA9eHCq1u3DLHE3hIZ2X1YQZMcSAeob7RjNS/d0854Idkz9l+9TKZ1VdCD+ WF1ri8VIM0XTitzkoXoZctF0Afz0mx1BXuD4YKFeS7mXQhQo9y0PAEr/DBf1oeOK+LDm e39tiBsXCywzg4oCW0JULX7HcX8MYgsmNVCJmSBrJu1I9wulppDw3vsPwBMIXI4q9dBQ qc9nuBrKdgM5n1KSk/+pOPiOo6dgpogeZ1CA7ix0zCwfs7TvdCJZUISOpZXS/+I0Dd6A KuW6wO+0ZwFd6sLHUO9Ae3/4RDTzAbip+UJqN1Uh+VmO0vxSejYve5O1Bx64DIM49RTh xs7w== X-Gm-Message-State: AOJu0Yzra873kk0Ak3bs8dWQ34x/++EVfqowlj+ircxNnRli5YpOVqVX 2okYM9FRePfKUyqa/LR9hYibK95ckFaLyGBZwAS5afW4CQHYV0dwl/ZBolUA X-Google-Smtp-Source: AGHT+IF0YSAMozp6sSPZAKci4lNc151GXj495txCumD6w9VFTCqjeGEpU1Q0FtSDp99W7nl7oB6+sw== X-Received: by 2002:a50:950e:0:b0:572:8aab:4415 with SMTP id 4fb4d7f45d1cf-57832c12431mr824956a12.40.1716368613030; Wed, 22 May 2024 02:03:33 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:32 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 3/6] update-ref: add support for 'symref-delete' command Date: Wed, 22 May 2024 11:03:23 +0200 Message-ID: <20240522090326.1268326-4-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak Add a new command 'symref-delete' to allow deletions of symbolic refs in a transaction via the '--stdin' mode of the 'git-update-ref' command. The 'symref-delete' command can, when given an , delete the provided only when it points to . This command is only compatible with the 'no-deref' mode because we optionally want to check the 'old_target' of the ref being deleted. De-referencing a symbolic ref would provide a regular ref and we already have the 'delete' command for regular refs. While users can also use 'git symbolic-ref -d' to delete symbolic refs, the 'symref-delete' command in 'git-update-ref' allows users to do so within a transaction, which promises atomicity of the operation and can be batched with other commands. Signed-off-by: Karthik Nayak --- Documentation/git-update-ref.txt | 5 +++ builtin/fetch.c | 2 +- builtin/receive-pack.c | 3 +- builtin/update-ref.c | 33 ++++++++++++++++++- refs.c | 14 ++++++--- refs.h | 4 ++- t/t1400-update-ref.sh | 54 ++++++++++++++++++++++++++++++++ t/t1416-ref-transaction-hooks.sh | 19 ++++++++++- 8 files changed, 125 insertions(+), 9 deletions(-) diff --git a/Documentation/git-update-ref.txt b/Documentation/git-update-ref.txt index 9fe78b3501..16e02f6979 100644 --- a/Documentation/git-update-ref.txt +++ b/Documentation/git-update-ref.txt @@ -65,6 +65,7 @@ performs all modifications together. Specify commands of the form: create SP SP LF delete SP [SP ] LF verify SP [SP ] LF + symref-delete SP [SP ] LF symref-verify SP [SP ] LF option SP LF start LF @@ -87,6 +88,7 @@ quoting: create SP NUL NUL delete SP NUL [] NUL verify SP NUL [] NUL + symref-delete SP [NUL ] NUL symref-verify SP [NUL ] NUL option SP NUL start NUL @@ -119,6 +121,9 @@ verify:: Verify against but do not change it. If is zero or missing, the ref must not exist. +symref-delete:: + Delete after verifying it exists with , if given. + symref-verify:: Verify symbolic against but do not change it. If is missing, the ref must not exist. Can only be diff --git a/builtin/fetch.c b/builtin/fetch.c index 66840b7c5b..d02592efca 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1383,7 +1383,7 @@ static int prune_refs(struct display_state *display_state, if (transaction) { for (ref = stale_refs; ref; ref = ref->next) { result = ref_transaction_delete(transaction, ref->name, NULL, 0, - "fetch: prune", &err); + NULL, "fetch: prune", &err); if (result) goto cleanup; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index b150ef39a8..9a4667d57d 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1576,7 +1576,8 @@ static const char *update(struct command *cmd, struct shallow_info *si) if (ref_transaction_delete(transaction, namespaced_name, old_oid, - 0, "push", &err)) { + 0, NULL, + "push", &err)) { rp_error("%s", err.buf); ret = "failed to delete"; } else { diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 6dce1cd663..0ef9c38d8d 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -293,7 +293,7 @@ static void parse_cmd_delete(struct ref_transaction *transaction, if (ref_transaction_delete(transaction, refname, have_old ? &old_oid : NULL, - update_flags, msg, &err)) + update_flags, NULL, msg, &err)) die("%s", err.buf); update_flags = default_flags; @@ -301,6 +301,36 @@ static void parse_cmd_delete(struct ref_transaction *transaction, strbuf_release(&err); } + +static void parse_cmd_symref_delete(struct ref_transaction *transaction, + const char *next, const char *end) +{ + struct strbuf err = STRBUF_INIT; + char *refname, *old_target; + + if (!(update_flags & REF_NO_DEREF)) + die("symref-delete: cannot operate with deref mode"); + + refname = parse_refname(&next); + if (!refname) + die("symref-delete: missing "); + + old_target = parse_next_refname(&next); + + if (*next != line_termination) + die("symref-delete %s: extra input: %s", refname, next); + + if (ref_transaction_delete(transaction, refname, NULL, + update_flags, old_target, msg, &err)) + die("%s", err.buf); + + update_flags = default_flags; + free(refname); + free(old_target); + strbuf_release(&err); +} + + static void parse_cmd_verify(struct ref_transaction *transaction, const char *next, const char *end) { @@ -443,6 +473,7 @@ static const struct parse_cmd { { "create", parse_cmd_create, 2, UPDATE_REFS_OPEN }, { "delete", parse_cmd_delete, 2, UPDATE_REFS_OPEN }, { "verify", parse_cmd_verify, 2, UPDATE_REFS_OPEN }, + { "symref-delete", parse_cmd_symref_delete, 2, UPDATE_REFS_OPEN }, { "symref-verify", parse_cmd_symref_verify, 2, UPDATE_REFS_OPEN }, { "option", parse_cmd_option, 1, UPDATE_REFS_OPEN }, { "start", parse_cmd_start, 0, UPDATE_REFS_STARTED }, diff --git a/refs.c b/refs.c index 865264d487..3afebfcb63 100644 --- a/refs.c +++ b/refs.c @@ -979,7 +979,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg, transaction = ref_store_transaction_begin(refs, &err); if (!transaction || ref_transaction_delete(transaction, refname, old_oid, - flags, msg, &err) || + flags, NULL, msg, &err) || ref_transaction_commit(transaction, &err)) { error("%s", err.buf); ref_transaction_free(transaction); @@ -1317,14 +1317,20 @@ int ref_transaction_create(struct ref_transaction *transaction, int ref_transaction_delete(struct ref_transaction *transaction, const char *refname, const struct object_id *old_oid, - unsigned int flags, const char *msg, + unsigned int flags, + const char *old_target, + const char *msg, struct strbuf *err) { if (old_oid && is_null_oid(old_oid)) BUG("delete called with old_oid set to zeros"); + if (old_oid && old_target) + BUG("delete called with both old_oid and old_target set"); + if (old_target && !(flags & REF_NO_DEREF)) + BUG("delete cannot operate on symrefs with deref mode"); return ref_transaction_update(transaction, refname, null_oid(), old_oid, - NULL, NULL, flags, + NULL, old_target, flags, msg, err); } @@ -2767,7 +2773,7 @@ int refs_delete_refs(struct ref_store *refs, const char *logmsg, for_each_string_list_item(item, refnames) { ret = ref_transaction_delete(transaction, item->string, - NULL, flags, msg, &err); + NULL, flags, NULL, msg, &err); if (ret) { warning(_("could not delete reference %s: %s"), item->string, err.buf); diff --git a/refs.h b/refs.h index 48cec1ba72..053c382f0b 100644 --- a/refs.h +++ b/refs.h @@ -767,7 +767,9 @@ int ref_transaction_create(struct ref_transaction *transaction, int ref_transaction_delete(struct ref_transaction *transaction, const char *refname, const struct object_id *old_oid, - unsigned int flags, const char *msg, + unsigned int flags, + const char *old_target, + const char *msg, struct strbuf *err); /* diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 07e111b063..22d560f0bf 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1729,6 +1729,60 @@ do test_cmp expect actual ' + test_expect_success "stdin $type symref-delete fails without --no-deref" ' + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-delete refs/heads/symref" "$a" >stdin && + test_must_fail git update-ref --stdin $type err && + grep "fatal: symref-delete: cannot operate with deref mode" err + ' + + test_expect_success "stdin $type symref-delete fails with no ref" ' + format_command $type "symref-delete " >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + grep "fatal: symref-delete: missing " err + ' + + test_expect_success "stdin $type symref-delete fails with too many arguments" ' + format_command $type "symref-delete refs/heads/symref" "$a" "$a" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + if test "$type" = "-z" + then + grep "fatal: unknown command: $a" err + else + grep "fatal: symref-delete refs/heads/symref: extra input: $a" err + fi + ' + + test_expect_success "stdin $type symref-delete fails with wrong old value" ' + format_command $type "symref-delete refs/heads/symref" "$m" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected refs/heads/main" err && + git symbolic-ref refs/heads/symref >expect && + echo $a >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-delete works with right old value" ' + format_command $type "symref-delete refs/heads/symref" "$a" >stdin && + git update-ref --stdin $type --no-deref stdin && + format_command $type "symref-delete refs/heads/symref" "" >stdin && + git update-ref --stdin $type --no-deref stdin && + git update-ref --stdin $type --no-deref >actual @@ -171,16 +172,32 @@ test_expect_success 'hook gets all queued symref updates' ' done >>actual EOF - cat >expect <<-EOF && + # In the files backend, "delete" also triggers an additional transaction + # update on the packed-refs backend, which constitutes additional reflog + # entries. + if test_have_prereq REFFILES + then + cat >expect <<-EOF + aborted + $ZERO_OID $ZERO_OID refs/heads/symrefd + EOF + else + >expect + fi && + + cat >>expect <<-EOF && prepared ref:refs/heads/main $ZERO_OID refs/heads/symref + ref:refs/heads/main $ZERO_OID refs/heads/symrefd committed ref:refs/heads/main $ZERO_OID refs/heads/symref + ref:refs/heads/main $ZERO_OID refs/heads/symrefd EOF git update-ref --no-deref --stdin <<-EOF && start symref-verify refs/heads/symref refs/heads/main + symref-delete refs/heads/symrefd refs/heads/main prepare commit EOF From patchwork Wed May 22 09:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670618 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE21280BFE for ; Wed, 22 May 2024 09:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368617; cv=none; b=Z0zvsB9P6cF0TlfCiNgu4tQIFtIhasXYtQ9RNB65kxv8D3mIlioc1/gHQEXQMe1YLmGZ/FeFe0K4OxJH2XDASUcY3xKg47JnrgaHyivqetAG2muuv0pyryAUGZzkg3k9gY9RgXDedCBMdsM+hjhL6wjjvRKkwGSQTNKNNEh1lAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368617; c=relaxed/simple; bh=Br9HqqB6n8DrUFVagCs9rVJA5vs3IXgdk/3gEySm/Hs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nZ+8eGI11IZIvPuQiDd/KGHZi4bmwC1COrBlNxuVYknoKK4c+lWobp+ltyNNxUerGwSqr89Z1XZjZg9PrLOpVmj7DZP6zhcYH7wIchm30OSFlKhIJuKZ8qNnx3wYw/0KrR8fxNOorHYn3mVM0yLUq1CgmSBSBa3rMeZz0sIXLvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ms2EKgQ4; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ms2EKgQ4" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so10530921a12.3 for ; Wed, 22 May 2024 02:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368614; x=1716973414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ahlZJWUfmbLcZZKQnxiAgNBy5cxwIMvOmpKms7NkTiA=; b=ms2EKgQ4rQ1TKFwpSuXcAG7600f4ScB0qPvTwT/ui4vVGJV2jTDX1ED+gY3hXLbx2I 7QP0ixO4lrw/mmL1xyrVuuzFOXWU8P4dreq5qJrqG6NzmpQ/wVLFTJjLiWKT2N1otnJR l1oDmqw8JMfW5aZljkjpEiLaPiR9ImJKTS4ikW3vJ7cnKzf09G55WmNYUzAJwToWpQTY yH/IJ/HyPJXN4/29IUOG6BzemrsceITcv2Kd4tgvb4BUFw2XcynyEj7rv+JlOmUC6Y7u lQ7q7A2kwtwX6yi7yZV7OqICXH1JQ1h471Qy6Jp4xm55MzrnCivHGmcJj5tyRt+qMa38 nieQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368614; x=1716973414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ahlZJWUfmbLcZZKQnxiAgNBy5cxwIMvOmpKms7NkTiA=; b=EjCPXWEoVO1FHibNUe2RC+6aawLGWMRerLdeNIcV0+e4SKx+4HdN9dG50UZBrlPnSE evJRvG+dYSgfnT0+oCFit5ZGHfx9IG4EK3lBjezuLq+pPSYxLa9c49kW6SoOGjXOCPx7 LEn+I+B7LHOcIG47ShrEK3Ak/S+2bC3H9ZrUFIjb7ivoO0hjVJmK2tDu0vTAIojGP7He T4EDDXBuwQzkBVipXRPOaYbH/x9LtqKN6FLgt+4JyRfEtyCBXzdvrj1A3lx1jud3oy2/ LXMQtDbk6SMQs7shsRgi//Gh/Od010UvdajXr4+5SZ3PuLsIEbyR3v0UrpdlAmUtlMjs wP8Q== X-Gm-Message-State: AOJu0Yzkp6FjwTtOMpyk/M7vJSFBWlLJVJDO6CyVN6nRCUaQDQ46MU4i eYdhS4kXpuOr3VrdBnN51yj+UF7iQyjD3n/m1M3N+PBV03981q4FlP1SZ1Ff X-Google-Smtp-Source: AGHT+IGfIu6FoZjxFoeQr0Ea88NWCYz5J3z9bKPDnNw+d39iKnh3LEExjKqhFBhj2p2CsJLnRhtoIQ== X-Received: by 2002:a50:bb03:0:b0:578:258c:1091 with SMTP id 4fb4d7f45d1cf-578329fe356mr787494a12.4.1716368613994; Wed, 22 May 2024 02:03:33 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:33 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 4/6] update-ref: add support for 'symref-create' command Date: Wed, 22 May 2024 11:03:24 +0200 Message-ID: <20240522090326.1268326-5-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak Add 'symref-create' command to the '--stdin' mode 'git-update-ref' to allow creation of symbolic refs in a transaction. The 'symref-create' command takes in a , which the created will point to. Also, support the 'core.prefersymlinkrefs' config, wherein if the config is set and the filesystem supports symlinks, we create the symbolic ref as a symlink. We fallback to creating a regular symref if creating the symlink is unsuccessful. Signed-off-by: Karthik Nayak --- Documentation/git-update-ref.txt | 6 +++ builtin/clone.c | 2 +- builtin/update-ref.c | 32 +++++++++++++++- refs.c | 9 +++-- refs.h | 1 + t/t0600-reffiles-backend.sh | 32 ++++++++++++++++ t/t1400-update-ref.sh | 65 ++++++++++++++++++++++++++++++++ t/t1416-ref-transaction-hooks.sh | 3 ++ t/t5605-clone-local.sh | 2 +- 9 files changed, 146 insertions(+), 6 deletions(-) diff --git a/Documentation/git-update-ref.txt b/Documentation/git-update-ref.txt index 16e02f6979..364ef78af1 100644 --- a/Documentation/git-update-ref.txt +++ b/Documentation/git-update-ref.txt @@ -65,6 +65,7 @@ performs all modifications together. Specify commands of the form: create SP SP LF delete SP [SP ] LF verify SP [SP ] LF + symref-create SP SP LF symref-delete SP [SP ] LF symref-verify SP [SP ] LF option SP LF @@ -88,6 +89,7 @@ quoting: create SP NUL NUL delete SP NUL [] NUL verify SP NUL [] NUL + symref-create SP NUL NUL symref-delete SP [NUL ] NUL symref-verify SP [NUL ] NUL option SP NUL @@ -121,6 +123,10 @@ verify:: Verify against but do not change it. If is zero or missing, the ref must not exist. +symref-create: + Create symbolic ref with after verifying + it does not exist. + symref-delete:: Delete after verifying it exists with , if given. diff --git a/builtin/clone.c b/builtin/clone.c index 93fdfc945a..ac1e131d8b 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -546,7 +546,7 @@ static void write_remote_refs(const struct ref *local_refs) if (!r->peer_ref) continue; if (ref_transaction_create(t, r->peer_ref->name, &r->old_oid, - 0, NULL, &err)) + NULL, 0, NULL, &err)) die("%s", err.buf); } diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 0ef9c38d8d..16d184603b 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -257,7 +257,7 @@ static void parse_cmd_create(struct ref_transaction *transaction, if (*next != line_termination) die("create %s: extra input: %s", refname, next); - if (ref_transaction_create(transaction, refname, &new_oid, + if (ref_transaction_create(transaction, refname, &new_oid, NULL, update_flags | create_reflog_flag, msg, &err)) die("%s", err.buf); @@ -267,6 +267,35 @@ static void parse_cmd_create(struct ref_transaction *transaction, strbuf_release(&err); } + +static void parse_cmd_symref_create(struct ref_transaction *transaction, + const char *next, const char *end) +{ + struct strbuf err = STRBUF_INIT; + char *refname, *new_target; + + refname = parse_refname(&next); + if (!refname) + die("symref-create: missing "); + + new_target = parse_next_refname(&next); + if (!new_target) + die("symref-create %s: missing ", refname); + + if (*next != line_termination) + die("symref-create %s: extra input: %s", refname, next); + + if (ref_transaction_create(transaction, refname, NULL, new_target, + update_flags | create_reflog_flag, + msg, &err)) + die("%s", err.buf); + + update_flags = default_flags; + free(refname); + free(new_target); + strbuf_release(&err); +} + static void parse_cmd_delete(struct ref_transaction *transaction, const char *next, const char *end) { @@ -473,6 +502,7 @@ static const struct parse_cmd { { "create", parse_cmd_create, 2, UPDATE_REFS_OPEN }, { "delete", parse_cmd_delete, 2, UPDATE_REFS_OPEN }, { "verify", parse_cmd_verify, 2, UPDATE_REFS_OPEN }, + { "symref-create", parse_cmd_symref_create, 2, UPDATE_REFS_OPEN }, { "symref-delete", parse_cmd_symref_delete, 2, UPDATE_REFS_OPEN }, { "symref-verify", parse_cmd_symref_verify, 2, UPDATE_REFS_OPEN }, { "option", parse_cmd_option, 1, UPDATE_REFS_OPEN }, diff --git a/refs.c b/refs.c index 3afebfcb63..7172f31bf2 100644 --- a/refs.c +++ b/refs.c @@ -1302,15 +1302,18 @@ int ref_transaction_update(struct ref_transaction *transaction, int ref_transaction_create(struct ref_transaction *transaction, const char *refname, const struct object_id *new_oid, + const char *new_target, unsigned int flags, const char *msg, struct strbuf *err) { - if (!new_oid || is_null_oid(new_oid)) { - strbuf_addf(err, "'%s' has a null OID", refname); + if (new_oid && new_target) + BUG("create called with both new_oid and new_target set"); + if ((!new_oid || is_null_oid(new_oid)) && !new_target) { + strbuf_addf(err, "'%s' has neither a valid OID nor a target", refname); return 1; } return ref_transaction_update(transaction, refname, new_oid, - null_oid(), NULL, NULL, flags, + null_oid(), new_target, NULL, flags, msg, err); } diff --git a/refs.h b/refs.h index 053c382f0b..055cc9173b 100644 --- a/refs.h +++ b/refs.h @@ -753,6 +753,7 @@ int ref_transaction_update(struct ref_transaction *transaction, int ref_transaction_create(struct ref_transaction *transaction, const char *refname, const struct object_id *new_oid, + const char *new_target, unsigned int flags, const char *msg, struct strbuf *err); diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh index a390cffc80..7cfb5e8c6c 100755 --- a/t/t0600-reffiles-backend.sh +++ b/t/t0600-reffiles-backend.sh @@ -468,4 +468,36 @@ test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' ' esac ' +test_expect_success SYMLINKS 'symref transaction supports symlinks' ' + test_when_finished "git symbolic-ref -d TEST_SYMREF_HEAD" && + git update-ref refs/heads/new @ && + test_config core.prefersymlinkrefs true && + cat >stdin <<-EOF && + start + symref-create TEST_SYMREF_HEAD refs/heads/new + prepare + commit + EOF + git update-ref --no-deref --stdin stdin <<-EOF && + start + symref-create TEST_SYMREF_HEAD refs/heads/new + prepare + commit + EOF + git update-ref --no-deref --stdin actual && + echo refs/heads/new >expect && + test_cmp expect actual +' + test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 22d560f0bf..78001f879a 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1783,6 +1783,71 @@ do test_must_fail git symbolic-ref -d refs/heads/symref2 ' + test_expect_success "stdin $type symref-create fails with too many arguments" ' + format_command $type "symref-create refs/heads/symref" "$a" "$a" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + if test "$type" = "-z" + then + grep "fatal: unknown command: $a" err + else + grep "fatal: symref-create refs/heads/symref: extra input: $a" err + fi + ' + + test_expect_success "stdin $type symref-create fails with no target" ' + format_command $type "symref-create refs/heads/symref" >stdin && + test_must_fail git update-ref --stdin $type --no-deref stdin && + test_must_fail git update-ref --stdin $type --no-deref stdin && + git update-ref --stdin $type --no-deref expect && + echo $a >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-create works with --no-deref" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-create refs/heads/symref" "$a" && + git update-ref --stdin $type err + ' + + test_expect_success "stdin $type create dangling symref ref works" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-create refs/heads/symref" "refs/heads/unkown" >stdin && + git update-ref --stdin $type --no-deref expect && + echo refs/heads/unkown >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-create does not create reflogs by default" ' + test_when_finished "git symbolic-ref -d refs/symref" && + format_command $type "symref-create refs/symref" "$a" >stdin && + git update-ref --stdin $type --no-deref expect && + echo $a >actual && + test_cmp expect actual && + test_must_fail git reflog exists refs/symref + ' + + test_expect_success "stdin $type symref-create reflogs with --create-reflog" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-create refs/heads/symref" "$a" >stdin && + git update-ref --create-reflog --stdin $type --no-deref expect && + echo $a >actual && + test_cmp expect actual && + git reflog exists refs/heads/symref + ' + done test_done diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index ccde1b944b..ff77dcca6b 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -189,15 +189,18 @@ test_expect_success 'hook gets all queued symref updates' ' prepared ref:refs/heads/main $ZERO_OID refs/heads/symref ref:refs/heads/main $ZERO_OID refs/heads/symrefd + $ZERO_OID ref:refs/heads/main refs/heads/symrefc committed ref:refs/heads/main $ZERO_OID refs/heads/symref ref:refs/heads/main $ZERO_OID refs/heads/symrefd + $ZERO_OID ref:refs/heads/main refs/heads/symrefc EOF git update-ref --no-deref --stdin <<-EOF && start symref-verify refs/heads/symref refs/heads/main symref-delete refs/heads/symrefd refs/heads/main + symref-create refs/heads/symrefc refs/heads/main prepare commit EOF diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index a3055869bc..339d8c786f 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -163,7 +163,7 @@ test_expect_success REFFILES 'local clone from repo with corrupt refs fails grac echo a >corrupt/.git/refs/heads/topic && test_must_fail git clone corrupt working 2>err && - grep "has a null OID" err + grep "has neither a valid OID nor a target" err ' test_done From patchwork Wed May 22 09:03:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670619 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB061811E7 for ; Wed, 22 May 2024 09:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368618; cv=none; b=a+8xCMIPsKg+u99kQI768qWq80ks2ZaZUQE4uSwY6cJE4HH3QoNPJcpbpPJyMu32BBgTRXH/f4PFtUpbWNUu3IpWcLA2h2AxVuDLSgxX0eXCAXw5GEiBmxuHQUS6/NdtKzSWMAXLUaFdrCc1B4W46YNoLRGriM8tWxfry4ozYsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368618; c=relaxed/simple; bh=c1Oid00CoSwXCs/n/GjZ6ci/v/6IVphE8POmTwHT6oQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tiV6DV1bXVwBymBmceRFZ2LAFj9RXqaOvjV9Dn272t+TKMlMECb3SkP0UYAWS0Pk7K74AHrC547cq6S/TPhdou6ltuegcp8ef+Rl8tHMvte1PkA2G3GRmVJkOjtJWxjnmdgFtu6XXfTSl4I99R/4cd9ECeRM6nZjgijrssfRgG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D3alPgf8; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D3alPgf8" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-56e6affdd21so3476679a12.3 for ; Wed, 22 May 2024 02:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368615; x=1716973415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=feVuXyzGPcv09ZUakSF4dmzDmzPnLB7k34ooDplfizU=; b=D3alPgf8K1stKEx/dJaagCxKEBDabLiEW+Azy3iame8qH2q5OIv77S/b+Xf6Bwl9t0 jfOyDANf/LW1MdjbZqiZxjfPpWq38Fn00CtRLsQKnT29E9GPLq6SSN2dLai7hKolIA+Q FkNNOLlR6CCgaWTv3kFT3GbVFwM/XkXd/krQjUJ3trqIIEEJzOgwe4sQiMDWNpqgdZIV jq1F3epHtoHGww3kXIbWEHXxnx6eu3wiE54PsjS+Ld1fwvZxp01NHl8ZSe6ZkHugYHTB 71eRn5uEwm+JTHTWXMWUvSmUdSGgZ2z6UdqBfUBduco0jl4OHdzZaRt+U+i5jFpT3xTC OCOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368615; x=1716973415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=feVuXyzGPcv09ZUakSF4dmzDmzPnLB7k34ooDplfizU=; b=CUPQyvNV9l02MvpVi8r8NahqrCHLNSTJYOrEEQEPUnCD3W7B0wdm06VW9W+wh/kQmn E49ItToQBfbsoAt+S3GXUrm6Ki+aSfZ6FTdXpomZhWW8sWHfTXPJn+4KJxBoqwSeji7T BHIcc5BA8UAYXmkKApWfqjkIlzCIefmgsa3AwBRhYk+7bnZ+9Wy/jr1Mnd2WauTXKu01 lGJBnRo7KtpzKPO2GGBXr96Rm0YVUkyjwuPw87jBcRU/Y7ugsUI/PBPsKd7UAridGvBR +QXKVDxfa2RxvDeXTpuFSFjB7hHE5S8MSPpZXtFhPLMTiGkpxP1FPtOKE/IJCYtRqrhG xboQ== X-Gm-Message-State: AOJu0Yxe/Wwqp9pG710aUhjWQRZ4yEansSt92a4GiGoZ5NlxFhAxtaLn PvUqfZGJzrUmzHLMzvRot6rTXIisdCXBXWIXsCxouvuCSIONec2f X-Google-Smtp-Source: AGHT+IG8S2Jk97enke++jofIjjDN2xqfrGjsg93VYtNP0xsF+sV2lr1cV022nQnoX/xCpZg4+WqlPw== X-Received: by 2002:a50:a6ce:0:b0:56e:10d3:85e3 with SMTP id 4fb4d7f45d1cf-57832a4a1fcmr1103255a12.13.1716368615183; Wed, 22 May 2024 02:03:35 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:34 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 5/6] reftable: pick either 'oid' or 'target' for new updates Date: Wed, 22 May 2024 11:03:25 +0200 Message-ID: <20240522090326.1268326-6-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak When creating a reference transaction update, we can provide the old/new oid/target for the update. We have checks in place to ensure that for each old/new, either oid or target is set and not both. In the reftable backend, when dealing with updates without the `REF_NO_DEREF` flag, we don't selectively propagate data as needed. Since there are no active users of the path, this is not caught. As we want to introduce the 'symref-update' command in the upcoming commit, which would use this flow, correct it. Signed-off-by: Karthik Nayak --- refs/reftable-backend.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index dc7aa7f274..8582f2ff2f 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -896,8 +896,9 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, */ new_update = ref_transaction_add_update( transaction, referent.buf, new_flags, - &u->new_oid, &u->old_oid, u->new_target, - u->old_target, u->msg); + u->new_target ? NULL : &u->new_oid, + u->old_target ? NULL : &u->old_oid, + u->new_target, u->old_target, u->msg); new_update->parent_update = u; From patchwork Wed May 22 09:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13670620 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B783880023 for ; Wed, 22 May 2024 09:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368621; cv=none; b=Ydq2qDxnlqi9RCF9aC5OCc/fNwO+U9wWpfK4PoTJju/CGIOgsTvBSCaa4+sEB1NkhmmVBylGMaWoPP26GxjHLAF0ikOvUuhESc9S/fwYqcxkH67ZZxMzwzIytgoSvXtZB24DrrBko9G6Qip3HzzPLwLRfBPXtIV/GsWJadrw8HA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716368621; c=relaxed/simple; bh=K3Hndgwh8Vl7hrFUu0NKEaDMh/M3P+zQnqI1X1a0eOQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=suMQjaokR756xNlCnfbY3gK86vZvPaPrctr6jZPndphQXuoKmY5k8FjMh0jlFVvTPWZ01Lo0U5jilWzwQ6gYjuQwjbfRwYba20mq+xqbDq0U8drgGfkyonIXFiCxGQiB9HDXoUUp3wZ8nkJfUTY1owUsB6GFYGQAx6aG3Mab4WY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G7aJ6esZ; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G7aJ6esZ" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-51f2ebbd8a7so7714561e87.2 for ; Wed, 22 May 2024 02:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716368617; x=1716973417; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IOvmsrx6o0Frx0r09R1Ep2FegdZNetuk7DZ7zeBuMi8=; b=G7aJ6esZhHY7AHAoU5p8iVorTU/iU9a3k2a9Kti8ESGucvV9OfW2/M5oYL2ZTcpeF9 2sCcMIOHgxEn6sO3hUBUitPdlS8Fi4WpBGcnaJevlfMXGT4CBQR3QWZ462rBIv1gdKrO scnh5Ca8UfzQEYPVItK/m3tWR4/Z8h/Hso9QFqeAgNFWCwuJW7zL8Rs8+Gc5B+cUkobv 3OmuOLnu44BqglAj20XpWTxkdNkOi3bbg5xAAXJQ4qy56FxVfAL7cFG+NbsCrMVFd7pq j1htv+4MY4kj2qhWRYWBds+FRRlVbu2hAHIGnXa2tRdy9Jzgnun6zIWugQRb6qMXm739 ZEjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716368617; x=1716973417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IOvmsrx6o0Frx0r09R1Ep2FegdZNetuk7DZ7zeBuMi8=; b=Fp6/ASelNzEUqMcPYdbbW69I/NMooaptW0iPLCQCxZoYCnvmL/mWn+JRGCtPojoAHC OHx92z7Kar9BO5E0tI5XZqBt+3PBGfOo0ZSpN4tBiL39EPyZBWErKxHfPfQfGGr40q+e YiM61tra0jjGKl0ULqWW5CO8xQ3J0KSn/uEz7LuJvwXWXBiBZVNEOTuxj5f80WJXG4w+ hNJesjfT/mAiH157D573VkckyG4QBwuoSwtBq2pNTp2j+WsKb3jSFRxt/kdvO6qahmi7 DvNpUa55A3EGt1gE/xLJ2UgccogrFgCCqjtJmRf3XtzltM94GZIB8jN5nizhBfi70npt 3FpA== X-Gm-Message-State: AOJu0YwoZtyu8QiZZWwx3i6tuTfaxvEzElQM+YJdyI7kr/6lDidEz0Bg XSOII074XJxlDqwTWwD72QitFcpojbJX45SHlih3Z5AplROaE39X X-Google-Smtp-Source: AGHT+IFWWQJy6lajaI//1M8tpZp73n68Kwj3h07zI9eYdTIVJA0BAQXCRrqoPmBSViQSOgXPNHoHwg== X-Received: by 2002:a05:6512:442:b0:51b:f78d:c189 with SMTP id 2adb3069b0e04-526bd694edbmr786648e87.14.1716368616367; Wed, 22 May 2024 02:03:36 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:414d:df4b:1d67:e754]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8281354a12.61.2024.05.22.02.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:03:35 -0700 (PDT) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: karthik.188@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im Subject: [PATCH v2 6/6] update-ref: add support for 'symref-update' command Date: Wed, 22 May 2024 11:03:26 +0200 Message-ID: <20240522090326.1268326-7-knayak@gitlab.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522090326.1268326-1-knayak@gitlab.com> References: <20240514124411.1037019-1-knayak@gitlab.com> <20240522090326.1268326-1-knayak@gitlab.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Karthik Nayak Add 'symref-update' command to the '--stdin' mode of 'git-update-ref' to allow updates of symbolic refs. The 'symref-update' command takes in a , which the will be updated to. If the doesn't exist it will be created. It also optionally takes either an `ref ` or `oid `. If the is provided, it checks to see if the targets the before the update. If is provided it checks to ensure that it is a regular ref and is the OID before the update. This by extension also means that this when a zero is provided, it ensures that the ref didn't exist before. The divergence in syntax from the regular `update` command is because if we don't use a `(ref | oid)` prefix for the old_value, then there is ambiguity around if the value provided should be treated as an oid or a reference. This is more so the reason, because we allow anything committish to be provided as an oid. The command allows users to perform symbolic ref updates within a transaction. This provides atomicity and allows users to perform a set of operations together. This command supports deref mode, to ensure that we can update dereferenced regular refs to symrefs. Signed-off-by: Karthik Nayak --- Documentation/git-update-ref.txt | 7 ++ builtin/update-ref.c | 90 ++++++++++++++ t/t1400-update-ref.sh | 203 +++++++++++++++++++++++++++++++ t/t1416-ref-transaction-hooks.sh | 4 + 4 files changed, 304 insertions(+) diff --git a/Documentation/git-update-ref.txt b/Documentation/git-update-ref.txt index 364ef78af1..afcf33cf60 100644 --- a/Documentation/git-update-ref.txt +++ b/Documentation/git-update-ref.txt @@ -65,6 +65,7 @@ performs all modifications together. Specify commands of the form: create SP SP LF delete SP [SP ] LF verify SP [SP ] LF + symref-update SP SP [SP (ref SP | oid SP )] LF symref-create SP SP LF symref-delete SP [SP ] LF symref-verify SP [SP ] LF @@ -89,6 +90,7 @@ quoting: create SP NUL NUL delete SP NUL [] NUL verify SP NUL [] NUL + symref-update SP NUL [NUL (ref NUL | oid NUL )] NUL symref-create SP NUL NUL symref-delete SP [NUL ] NUL symref-verify SP [NUL ] NUL @@ -119,6 +121,11 @@ delete:: Delete after verifying it exists with , if given. If given, may not be zero. +symref-update:: + Set to after verifying or , + if given. Specify a zero to ensure that the ref does not + exist before the update. + verify:: Verify against but do not change it. If is zero or missing, the ref must not exist. diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 16d184603b..bda37c161d 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -98,6 +98,40 @@ static char *parse_next_refname(const char **next) return parse_refname(next); } +/* + * Wrapper around parse_arg which skips the next delimiter. + */ +static char *parse_next_arg(const char **next) +{ + struct strbuf arg = STRBUF_INIT; + + if (line_termination) { + /* Without -z, consume SP and use next argument */ + if (!**next || **next == line_termination) + return NULL; + if (**next != ' ') + die("expected SP but got: %s", *next); + } else { + /* With -z, read the next NUL-terminated line */ + if (**next) + return NULL; + } + /* Skip the delimiter */ + (*next)++; + + if (line_termination) { + /* Without -z, use the next argument */ + *next = parse_arg(*next, &arg); + } else { + /* With -z, use everything up to the next NUL */ + strbuf_addstr(&arg, *next); + *next += arg.len; + } + + if (arg.len) + return strbuf_detach(&arg, NULL); + return NULL; +} /* * The value being parsed is (as opposed to ; the @@ -237,6 +271,61 @@ static void parse_cmd_update(struct ref_transaction *transaction, strbuf_release(&err); } +static void parse_cmd_symref_update(struct ref_transaction *transaction, + const char *next, const char *end) +{ + char *refname, *new_target, *old_arg; + char *old_target = NULL; + struct strbuf err = STRBUF_INIT; + struct object_id old_oid; + int have_old_oid = 0; + + refname = parse_refname(&next); + if (!refname) + die("symref-update: missing "); + + new_target = parse_next_refname(&next); + if (!new_target) + die("symref-update %s: missing ", refname); + + old_arg = parse_next_arg(&next); + if (old_arg) { + old_target = parse_next_arg(&next); + if (!old_target) + die("symref-update %s: expected old value", refname); + + if (!strcmp(old_arg, "oid")) { + if (repo_get_oid(the_repository, old_target, &old_oid)) + die("symref-update %s: invalid oid: %s", refname, old_target); + + old_target = NULL; + have_old_oid = 1; + } else if (!strcmp(old_arg, "ref")) { + if (check_refname_format(old_target, REFNAME_ALLOW_ONELEVEL)) + die("symref-update %s: invalid ref: %s", refname, old_target); + } else { + die("symref-update %s: invalid arg '%s' for old value", refname, old_arg); + } + } + + if (*next != line_termination) + die("symref-update %s: extra input: %s", refname, next); + + if (ref_transaction_update(transaction, refname, NULL, + have_old_oid ? &old_oid : NULL, + new_target, old_target, + update_flags | create_reflog_flag, + msg, &err)) + die("%s", err.buf); + + update_flags = default_flags; + free(refname); + free(old_arg); + free(old_target); + free(new_target); + strbuf_release(&err); +} + static void parse_cmd_create(struct ref_transaction *transaction, const char *next, const char *end) { @@ -502,6 +591,7 @@ static const struct parse_cmd { { "create", parse_cmd_create, 2, UPDATE_REFS_OPEN }, { "delete", parse_cmd_delete, 2, UPDATE_REFS_OPEN }, { "verify", parse_cmd_verify, 2, UPDATE_REFS_OPEN }, + { "symref-update", parse_cmd_symref_update, 4, UPDATE_REFS_OPEN }, { "symref-create", parse_cmd_symref_create, 2, UPDATE_REFS_OPEN }, { "symref-delete", parse_cmd_symref_delete, 2, UPDATE_REFS_OPEN }, { "symref-verify", parse_cmd_symref_verify, 2, UPDATE_REFS_OPEN }, diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 78001f879a..68afe7c228 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1360,6 +1360,7 @@ test_expect_success 'fails with duplicate HEAD update' ' ' test_expect_success 'fails with duplicate ref update via symref' ' + test_when_finished "git symbolic-ref -d refs/heads/symref2" && git branch target2 $A && git symbolic-ref refs/heads/symref2 refs/heads/target2 && cat >stdin <<-EOF && @@ -1848,6 +1849,208 @@ do git reflog exists refs/heads/symref ' + test_expect_success "stdin $type symref-update fails with too many arguments" ' + format_command $type "symref-update refs/heads/symref" "$a" "ref" "$a" "$a" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + if test "$type" = "-z" + then + grep "fatal: unknown command: $a" err + else + grep "fatal: symref-update refs/heads/symref: extra input: $a" err + fi + ' + + test_expect_success "stdin $type symref-update fails with wrong old value argument" ' + format_command $type "symref-update refs/heads/symref" "$a" "foo" "$a" "$a" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + grep "fatal: symref-update refs/heads/symref: invalid arg ${SQ}foo${SQ} for old value" err + ' + + test_expect_success "stdin $type symref-update creates with zero old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update creates with no old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-update refs/heads/symref" "$a" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update creates dangling" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + test_must_fail git rev-parse refs/heads/nonexistent && + format_command $type "symref-update refs/heads/symref" "refs/heads/nonexistent" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update fails with wrong old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-update refs/heads/symref" "$m" "ref" "$b" >stdin && + test_must_fail git update-ref --stdin $type --no-deref err && + grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected $b" err && + test_must_fail git rev-parse --verify -q $c + ' + + test_expect_success "stdin $type symref-update updates dangling ref" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + test_must_fail git rev-parse refs/heads/nonexistent && + git symbolic-ref refs/heads/symref refs/heads/nonexistent && + format_command $type "symref-update refs/heads/symref" "$a" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update updates dangling ref with old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + test_must_fail git rev-parse refs/heads/nonexistent && + git symbolic-ref refs/heads/symref refs/heads/nonexistent && + format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/nonexistent" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update fails update dangling ref with wrong old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + test_must_fail git rev-parse refs/heads/nonexistent && + git symbolic-ref refs/heads/symref refs/heads/nonexistent && + format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/wrongref" >stdin && + test_must_fail git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update works with right old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-update refs/heads/symref" "$m" "ref" "$a" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update works with no old value" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-update refs/heads/symref" "$m" >stdin && + git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update fails with empty old ref-target" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + git symbolic-ref refs/heads/symref $a && + format_command $type "symref-update refs/heads/symref" "$m" "ref" "" >stdin && + test_must_fail git update-ref --stdin $type --no-deref expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update creates (with deref)" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + format_command $type "symref-update refs/heads/symref" "$a" >stdin && + git update-ref --stdin $type expect && + git symbolic-ref --no-recurse refs/heads/symref >actual && + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual && + grep "$Z $(git rev-parse $a)" actual + ' + + test_expect_success "stdin $type symref-update regular ref to symref with correct old-oid" ' + test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" && + git update-ref --no-deref refs/heads/regularref $a && + format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse $a)" >stdin && + git update-ref --stdin $type expect && + git symbolic-ref --no-recurse refs/heads/regularref >actual && + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual && + grep "$(git rev-parse $a) $(git rev-parse $a)" actual + ' + + test_expect_success "stdin $type symref-update regular ref to symref fails with wrong old-oid" ' + test_when_finished "git update-ref -d refs/heads/regularref" && + git update-ref --no-deref refs/heads/regularref $a && + format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse refs/heads/target2)" >stdin && + test_must_fail git update-ref --stdin $type err && + grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: is at $(git rev-parse $a) but expected $(git rev-parse refs/heads/target2)" err && + echo $(git rev-parse $a) >expect && + git rev-parse refs/heads/regularref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update regular ref to symref fails with invalid old-oid" ' + test_when_finished "git update-ref -d refs/heads/regularref" && + git update-ref --no-deref refs/heads/regularref $a && + format_command $type "symref-update refs/heads/regularref" "$a" "oid" "not-a-ref-oid" >stdin && + test_must_fail git update-ref --stdin $type err && + grep "fatal: symref-update refs/heads/regularref: invalid oid: not-a-ref-oid" err && + echo $(git rev-parse $a) >expect && + git rev-parse refs/heads/regularref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update existing symref with zero old-oid" ' + test_when_finished "git symbolic-ref -d --no-recurse refs/heads/symref" && + git symbolic-ref refs/heads/symref refs/heads/target2 && + format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin && + test_must_fail git update-ref --stdin $type err && + grep "fatal: cannot lock ref ${SQ}refs/heads/symref${SQ}: reference already exists" err && + echo refs/heads/target2 >expect && + git symbolic-ref refs/heads/symref >actual && + test_cmp expect actual + ' + + test_expect_success "stdin $type symref-update regular ref to symref (with deref)" ' + test_when_finished "git symbolic-ref -d refs/heads/symref" && + test_when_finished "git update-ref -d --no-deref refs/heads/symref2" && + git update-ref refs/heads/symref2 $a && + git symbolic-ref --no-recurse refs/heads/symref refs/heads/symref2 && + format_command $type "symref-update refs/heads/symref" "$a" >stdin && + git update-ref $type --stdin expect && + git symbolic-ref --no-recurse refs/heads/symref2 >actual && + test_cmp expect actual && + echo refs/heads/symref2 >expect && + git symbolic-ref --no-recurse refs/heads/symref >actual && + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual && + grep "$(git rev-parse $a) $(git rev-parse $a)" actual + ' + + test_expect_success "stdin $type symref-update regular ref to symref" ' + test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" && + git update-ref --no-deref refs/heads/regularref $a && + format_command $type "symref-update refs/heads/regularref" "$a" >stdin && + git update-ref $type --stdin expect && + git symbolic-ref --no-recurse refs/heads/regularref >actual && + test_cmp expect actual && + test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual && + grep "$(git rev-parse $a) $(git rev-parse $a)" actual + ' + done test_done diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index ff77dcca6b..5a812ca3c0 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -163,6 +163,7 @@ test_expect_success 'hook gets all queued symref updates' ' git update-ref refs/heads/branch $POST_OID && git symbolic-ref refs/heads/symref refs/heads/main && git symbolic-ref refs/heads/symrefd refs/heads/main && + git symbolic-ref refs/heads/symrefu refs/heads/main && test_hook reference-transaction <<-\EOF && echo "$*" >>actual @@ -190,10 +191,12 @@ test_expect_success 'hook gets all queued symref updates' ' ref:refs/heads/main $ZERO_OID refs/heads/symref ref:refs/heads/main $ZERO_OID refs/heads/symrefd $ZERO_OID ref:refs/heads/main refs/heads/symrefc + ref:refs/heads/main ref:refs/heads/branch refs/heads/symrefu committed ref:refs/heads/main $ZERO_OID refs/heads/symref ref:refs/heads/main $ZERO_OID refs/heads/symrefd $ZERO_OID ref:refs/heads/main refs/heads/symrefc + ref:refs/heads/main ref:refs/heads/branch refs/heads/symrefu EOF git update-ref --no-deref --stdin <<-EOF && @@ -201,6 +204,7 @@ test_expect_success 'hook gets all queued symref updates' ' symref-verify refs/heads/symref refs/heads/main symref-delete refs/heads/symrefd refs/heads/main symref-create refs/heads/symrefc refs/heads/main + symref-update refs/heads/symrefu refs/heads/branch ref refs/heads/main prepare commit EOF