From: Phillip Wood <phillip.wood123@gmail.com>
To: Ghanshyam Thakkar <shyamthakkar001@gmail.com>, git@vger.kernel.org
Cc: gitster@pobox.com, ps@pks.im
Subject: Re: [PATCH v3 2/2] add-patch: classify '@' as a synonym for 'HEAD'
Date: Mon, 5 Feb 2024 16:37:22 +0000 [thread overview]
Message-ID: <9f9f26f1-5460-468e-a893-5caf7fbea981@gmail.com> (raw)
In-Reply-To: <20240203112619.979239-6-shyamthakkar001@gmail.com>
Hi Ghanshyam
I think this is a useful addition, I've left a couple of comments below
On 03/02/2024 11:25, Ghanshyam Thakkar wrote:
> diff --git a/add-patch.c b/add-patch.c
> index 68f525b35c..7d565dcb33 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -378,6 +378,11 @@ static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk)
> return 0;
> }
>
> +static inline int user_meant_head(const char *rev)
> +{
> + return !strcmp(rev, "HEAD") || !strcmp(rev, "@");
> +}
> +
As well as the places you have converted we also have an explicit test
for "HEAD" in parse_diff() which looks like
if (s->revision) {
struct object_id oid;
strvec_push(&args,
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
repo_get_oid(the_repository, "HEAD", &oid) ?
empty_tree_oid_hex() : s->revision);
}
I suspect we need to update that code as well to accept "@" as a synonym
for "HEAD" on an unborn branch.
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index a6e30931b5..79e208ee6d 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -539,12 +539,13 @@ static int checkout_paths(const struct checkout_opts *opts,
> * recognized by diff-index), we will always replace the name
> * with the hex of the commit (whether it's in `...` form or
> * not) for the run_add_interactive() machinery to work
> - * properly. However, there is special logic for the HEAD case
> - * so we mustn't replace that. Also, when we were given a
> - * tree-object, new_branch_info->commit would be NULL, but we
> - * do not have to do any replacement, either.
> + * properly. However, there is special logic for the 'HEAD' and
> + * '@' case so we mustn't replace that. Also, when we were
> + * given a tree-object, new_branch_info->commit would be NULL,
> + * but we do not have to do any replacement, either.
> */
> - if (rev && new_branch_info->commit && strcmp(rev, "HEAD"))
> + if (rev && new_branch_info->commit && strcmp(rev, "HEAD") &&
> + strcmp(rev, "@"))
> rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
I agree with Junio's suggestion to use the user_meant_head() here.
Looking at this made me wonder why builtin/reset.c does not need
updating. The answer seems to be that reset passes in the revision as
given on the commandline after checking it refers to a valid tree
whereas for checkout the revision for on the commandline might contain
"..." which run_add_p() cannot handle.
> diff --git a/t/t2071-restore-patch.sh b/t/t2071-restore-patch.sh
> index b5c5c0ff7e..3dc9184b4a 100755
> --- a/t/t2071-restore-patch.sh
> +++ b/t/t2071-restore-patch.sh
> @@ -44,13 +44,17 @@ test_expect_success PERL 'git restore -p with staged changes' '
It is a pre-existing problem but all these "PERL" prerequisites are
no-longer required as we've removed the perl implementation of "add -p"
> verify_state dir/foo index index
> '
>
> -test_expect_success PERL 'git restore -p --source=HEAD' '
> - set_state dir/foo work index &&
> - # the third n is to get out in case it mistakenly does not apply
> - test_write_lines n y n | git restore -p --source=HEAD &&
> - verify_saved_state bar &&
> - verify_state dir/foo head index
> -'
> +for opt in "HEAD" "@"
> +do
> + test_expect_success PERL "git restore -p --source=$opt" '
> + set_state dir/foo work index &&
> + # the third n is to get out in case it mistakenly does not apply
> + test_write_lines n y n | git restore -p --source=$opt >output &&
> + verify_saved_state bar &&
> + verify_state dir/foo head index &&
> + test_grep "Discard" output
It is good to see that we're now testing for a reversed patch here.
Best Wishes
Phillip
next prev parent reply other threads:[~2024-02-05 16:37 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 18:11 [GSOC][RFC PATCH 0/2] add-patch: compare object id Ghanshyam Thakkar
2024-01-28 18:11 ` [RFC PATCH 1/2] add-patch: compare object id instead of literal string Ghanshyam Thakkar
2024-01-29 11:48 ` Patrick Steinhardt
2024-01-30 6:39 ` Ghanshyam Thakkar
2024-01-30 16:42 ` Junio C Hamano
2024-01-29 18:27 ` Junio C Hamano
2024-01-29 18:58 ` Junio C Hamano
2024-01-30 5:35 ` Ghanshyam Thakkar
2024-01-28 18:11 ` [RFC PATCH 2/2] checkout: remove HEAD special case Ghanshyam Thakkar
2024-01-29 11:48 ` Patrick Steinhardt
2024-02-02 15:03 ` [PATCH v2 0/2] add-patch: Support '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-02 15:03 ` [PATCH v2 1/2] add-patch: remove non-relevant NEEDSWORK comment Ghanshyam Thakkar
2024-02-02 15:03 ` [PATCH v2 2/2] add-patch: classify '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-02 17:08 ` Junio C Hamano
2024-02-02 17:43 ` Junio C Hamano
2024-02-02 17:53 ` Ghanshyam Thakkar
2024-02-02 17:51 ` Ghanshyam Thakkar
2024-02-02 17:31 ` [PATCH v2 0/2] add-patch: Support " Ghanshyam Thakkar
2024-02-03 11:25 ` [PATCH v3 0/2] add-patch: " Ghanshyam Thakkar
2024-02-06 22:50 ` [PATCH v4 0/3] '@' as a synonym for 'HEAD' in patch mode Ghanshyam Thakkar
2024-02-11 20:20 ` [PATCH v5 0/2] add-patch: classify '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-13 0:05 ` [PATCH v6 " Ghanshyam Thakkar
2024-02-14 11:06 ` Phillip Wood
2024-02-13 0:05 ` [PATCH v6 1/2] " Ghanshyam Thakkar
2024-02-13 0:05 ` [PATCH v6 2/2] add -p tests: remove PERL prerequisites Ghanshyam Thakkar
2024-02-11 20:20 ` [PATCH v5 1/2] add-patch: classify '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-12 21:45 ` Junio C Hamano
2024-02-11 20:20 ` [PATCH v5 2/2] add -p tests: remove PERL prerequisites Ghanshyam Thakkar
2024-02-06 22:50 ` [PATCH v4 1/3] add-patch: remove unnecessary NEEDSWORK comment Ghanshyam Thakkar
2024-02-07 10:51 ` Phillip Wood
2024-02-06 22:50 ` [PATCH v4 2/3] add-patch: classify '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-07 1:05 ` Junio C Hamano
2024-02-07 10:38 ` Phillip Wood
2024-02-09 15:57 ` Ghanshyam Thakkar
2024-02-06 22:50 ` [PATCH v4 3/3] add -p tests: remove Perl prerequisite Ghanshyam Thakkar
2024-02-07 10:50 ` Phillip Wood
2024-02-07 13:51 ` Phillip Wood
2024-02-07 16:02 ` Junio C Hamano
2024-02-07 16:58 ` Eric Sunshine
2024-02-03 11:25 ` [PATCH v3 1/2] add-patch: remove unnecessary NEEDSWORK comment Ghanshyam Thakkar
2024-02-03 11:25 ` [PATCH v3 2/2] add-patch: classify '@' as a synonym for 'HEAD' Ghanshyam Thakkar
2024-02-03 22:33 ` Junio C Hamano
2024-02-05 15:14 ` Ghanshyam Thakkar
2024-02-05 16:37 ` Phillip Wood [this message]
2024-02-05 20:38 ` Ghanshyam Thakkar
2024-02-05 23:07 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f9f26f1-5460-468e-a893-5caf7fbea981@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=shyamthakkar001@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).