git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] refs: allow @{n} to work with n-sized reflog
@ 2021-01-02  1:36 Denton Liu
  2021-01-02 22:30 ` Martin Ågren
                   ` (4 more replies)
  0 siblings, 5 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-02  1:36 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

This sequence works

	$ git checkout -b newbranch
	$ git commit --allow-empty -m one
	$ git show -s newbranch@{1}

and shows the state that was immediately after the newbranch was
created.

But then if you do

	$ git reflog expire --expire=now refs/heads/newbranch
	$ git commit --allow=empty -m two
	$ git show -s newbranch@{1}

you'd be scolded with

	fatal: log for 'newbranch' only has 1 entries

While it is true that it has only 1 entry, we have enough
information in that single entry that records the transition between
the state in which the tip of the branch was pointing at commit
'one' to the new commit 'two' built on it, so we should be able to
answer "what object newbranch was pointing at?". But we refuse to
do so.

Make @{0} the special case where we use the new side to look up that
entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
of the reflog.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c                      | 48 +++++++++++++++++++++++++++----------
 t/t1503-rev-parse-verify.sh | 17 +++++++++++--
 2 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/refs.c b/refs.c
index 13dc2c3291..c35c61a009 100644
--- a/refs.c
+++ b/refs.c
@@ -887,12 +887,16 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
+	int at_indexed_ent;
 
 	cb->reccnt++;
 	cb->tz = tz;
 	cb->date = timestamp;
 
-	if (timestamp <= cb->at_time || cb->cnt == 0) {
+	if (cb->cnt > 0)
+		cb->cnt--;
+	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
+	if (timestamp <= cb->at_time || at_indexed_ent) {
 		if (cb->msg)
 			*cb->msg = xstrdup(message);
 		if (cb->cutoff_time)
@@ -905,28 +909,41 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
 		 */
-		if (!is_null_oid(&cb->ooid)) {
-			oidcpy(cb->oid, noid);
-			if (!oideq(&cb->ooid, noid))
-				warning(_("log for ref %s has gap after %s"),
+		if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
+			warning(_("log for ref %s has gap after %s"),
 					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
-		}
-		else if (cb->date == cb->at_time)
+		if (at_indexed_ent)
+			oidcpy(cb->oid, ooid);
+		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
 			oidcpy(cb->oid, noid);
 		else if (!oideq(noid, cb->oid))
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
-		oidcpy(&cb->ooid, ooid);
-		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
-		return 1;
 	}
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
-	if (cb->cnt > 0)
-		cb->cnt--;
-	return 0;
+	return cb->found_it;
+}
+
+static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
+				  const char *email, timestamp_t timestamp,
+				  int tz, const char *message, void *cb_data)
+{
+	struct read_ref_at_cb *cb = cb_data;
+
+	if (cb->msg)
+		*cb->msg = xstrdup(message);
+	if (cb->cutoff_time)
+		*cb->cutoff_time = timestamp;
+	if (cb->cutoff_tz)
+		*cb->cutoff_tz = tz;
+	if (cb->cutoff_cnt)
+		*cb->cutoff_cnt = cb->reccnt;
+	oidcpy(cb->oid, noid);
+	/* We just want the first entry */
+	return 1;
 }
 
 static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
@@ -967,6 +984,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
+	if (cb.cnt == 0) {
+		refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
+		return 0;
+	}
+
 	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
index dc9fe3cbf1..ed4a366e85 100755
--- a/t/t1503-rev-parse-verify.sh
+++ b/t/t1503-rev-parse-verify.sh
@@ -86,8 +86,8 @@ test_expect_success 'fails silently when using -q' '
 test_expect_success 'fails silently when using -q with deleted reflogs' '
 	ref=$(git rev-parse HEAD) &&
 	git update-ref --create-reflog -m "message for refs/test" refs/test "$ref" &&
-	git reflog delete --updateref --rewrite refs/test@{0} &&
-	test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
+	git reflog delete --updateref --rewrite refs/test@{1} &&
+	test_must_fail git rev-parse -q --verify refs/test@{1} >error 2>&1 &&
 	test_must_be_empty error
 '
 
@@ -139,6 +139,19 @@ test_expect_success 'master@{n} for various n' '
 	test_must_fail git rev-parse --verify master@{$Np1}
 '
 
+test_expect_success '@{1} works with only one reflog entry' '
+	git checkout -B newbranch &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	git commit --allow-empty -mexpired &&
+	git rev-parse --verify newbranch@{1}
+'
+
+test_expect_success '@{0} works with empty reflog' '
+	git checkout -B newbranch &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	git rev-parse --verify newbranch@{0}
+'
+
 test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' '
 	ln -s does-not-exist .git/refs/heads/broken &&
 	test_must_fail git rev-parse --verify broken
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
@ 2021-01-02 22:30 ` Martin Ågren
  2021-01-03  1:24 ` Denton Liu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Martin Ågren @ 2021-01-02 22:30 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano

On Sat, 2 Jan 2021 at 02:41, Denton Liu <liu.denton@gmail.com> wrote:
>
> But then if you do
>
>         $ git reflog expire --expire=now refs/heads/newbranch
>         $ git commit --allow=empty -m two
>         $ git show -s newbranch@{1}
>
> you'd be scolded with
>
>         fatal: log for 'newbranch' only has 1 entries
>
> While it is true that it has only 1 entry, we have enough
> information in that single entry that records the transition between
> the state in which the tip of the branch was pointing at commit
> 'one' to the new commit 'two' built on it, so we should be able to
> answer "what object newbranch was pointing at?". But we refuse to
> do so.

The basic idea seems to make sense to me...

> Make @{0} the special case where we use the new side to look up that
> entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
> of the reflog.

> --- a/refs.c
> +++ b/refs.c
> @@ -887,12 +887,16 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>                 const char *message, void *cb_data)
>  {
>         struct read_ref_at_cb *cb = cb_data;
> +       int at_indexed_ent;
>
>         cb->reccnt++;
>         cb->tz = tz;
>         cb->date = timestamp;
>
> -       if (timestamp <= cb->at_time || cb->cnt == 0) {
> +       if (cb->cnt > 0)
> +               cb->cnt--;
> +       at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
> +       if (timestamp <= cb->at_time || at_indexed_ent) {

... but I can't really say anything about the implementation.

> +test_expect_success '@{1} works with only one reflog entry' '
> +       git checkout -B newbranch &&
> +       git reflog expire --expire=now refs/heads/newbranch &&
> +       git commit --allow-empty -mexpired &&

Minor nit: not sure about "expired" -- maybe "first after expiration".

> +       git rev-parse --verify newbranch@{1}
> +'

Should this capture the output and compare it to, e.g., `git rev-parse
newbranch^`?

> +test_expect_success '@{0} works with empty reflog' '
> +       git checkout -B newbranch &&
> +       git reflog expire --expire=now refs/heads/newbranch &&
> +       git rev-parse --verify newbranch@{0}
> +'

Same here, but comparing to `git rev-parse newbranch`? Both of these
checks seem worthwhile to make sure that we don't just answer
*something*, but that we actually get the right answer, as per your
"redefinition".

Speaking of redefinition, does this warrant an update of the
documentation? That's a genuine question -- having browsed git-reflog(1)
and gitrevisions(7) a bit, I'm not sure.

Martin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
  2021-01-02 22:30 ` Martin Ågren
@ 2021-01-03  1:24 ` Denton Liu
  2021-01-05  8:52 ` SZEDER Gábor
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-03  1:24 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

On Fri, Jan 01, 2021 at 05:36:06PM -0800, Denton Liu wrote:
> This sequence works
> 
> 	$ git checkout -b newbranch
> 	$ git commit --allow-empty -m one
> 	$ git show -s newbranch@{1}
> 
> and shows the state that was immediately after the newbranch was
> created.
> 
> But then if you do
> 
> 	$ git reflog expire --expire=now refs/heads/newbranch
> 	$ git commit --allow=empty -m two
> 	$ git show -s newbranch@{1}
> 
> you'd be scolded with
> 
> 	fatal: log for 'newbranch' only has 1 entries
> 
> While it is true that it has only 1 entry, we have enough
> information in that single entry that records the transition between
> the state in which the tip of the branch was pointing at commit
> 'one' to the new commit 'two' built on it, so we should be able to
> answer "what object newbranch was pointing at?". But we refuse to
> do so.
> 
> Make @{0} the special case where we use the new side to look up that
> entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
> of the reflog.
> 
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>

I forgot to mention that the original thread that spawned this idea is
here:

	https://lore.kernel.org/git/xmqqzh8zgcfp.fsf@gitster.c.googlers.com/

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
  2021-01-02 22:30 ` Martin Ågren
  2021-01-03  1:24 ` Denton Liu
@ 2021-01-05  8:52 ` SZEDER Gábor
  2021-01-06  5:55 ` Junio C Hamano
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
  4 siblings, 0 replies; 21+ messages in thread
From: SZEDER Gábor @ 2021-01-05  8:52 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano

On Fri, Jan 01, 2021 at 05:36:06PM -0800, Denton Liu wrote:
> This sequence works
> 
> 	$ git checkout -b newbranch
> 	$ git commit --allow-empty -m one
> 	$ git show -s newbranch@{1}
> 
> and shows the state that was immediately after the newbranch was
> created.
> 
> But then if you do
> 
> 	$ git reflog expire --expire=now refs/heads/newbranch
> 	$ git commit --allow=empty -m two
> 	$ git show -s newbranch@{1}
> 
> you'd be scolded with
> 
> 	fatal: log for 'newbranch' only has 1 entries
> 
> While it is true that it has only 1 entry, we have enough
> information in that single entry that records the transition between
> the state in which the tip of the branch was pointing at commit
> 'one' to the new commit 'two' built on it, so we should be able to
> answer "what object newbranch was pointing at?". But we refuse to
> do so.

Great!  I've run into this issue quite a while ago with regular 'git
gc' expiring too old reflog entries, and wondered while the @{N}
notation errored out while the information was clearly still there in
the reflog.

https://public-inbox.org/git/20130619125059.GD20052@goldbirke/T/#u

> @@ -139,6 +139,19 @@ test_expect_success 'master@{n} for various n' '
>  	test_must_fail git rev-parse --verify master@{$Np1}
>  '
>  
> +test_expect_success '@{1} works with only one reflog entry' '
> +	git checkout -B newbranch &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git commit --allow-empty -mexpired &&
> +	git rev-parse --verify newbranch@{1}
> +'
> +
> +test_expect_success '@{0} works with empty reflog' '
> +	git checkout -B newbranch &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git rev-parse --verify newbranch@{0}
> +'

I agree with Martin about these tests: not failing is one thing, but
we should make sure that the right value is printed.

>  test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' '
>  	ln -s does-not-exist .git/refs/heads/broken &&
>  	test_must_fail git rev-parse --verify broken
> -- 
> 2.30.0
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
                   ` (2 preceding siblings ...)
  2021-01-05  8:52 ` SZEDER Gábor
@ 2021-01-06  5:55 ` Junio C Hamano
  2021-01-06  8:25   ` Denton Liu
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
  4 siblings, 1 reply; 21+ messages in thread
From: Junio C Hamano @ 2021-01-06  5:55 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> This sequence works
>
> 	$ git checkout -b newbranch
> 	$ git commit --allow-empty -m one
> 	$ git show -s newbranch@{1}
>
> and shows the state that was immediately after the newbranch was
> created.
>
> But then if you do
>
> 	$ git reflog expire --expire=now refs/heads/newbranch
> 	$ git commit --allow=empty -m two
> 	$ git show -s newbranch@{1}
>
> you'd be scolded with
>
> 	fatal: log for 'newbranch' only has 1 entries
>
> While it is true that it has only 1 entry, we have enough
> information in that single entry that records the transition between
> the state in which the tip of the branch was pointing at commit
> 'one' to the new commit 'two' built on it, so we should be able to
> answer "what object newbranch was pointing at?". But we refuse to
> do so.

Yeah, I am often hit and irritated by this behaviour.

> Make @{0} the special case where we use the new side to look up that
> entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
> of the reflog.

OK.

> diff --git a/refs.c b/refs.c
> index 13dc2c3291..c35c61a009 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -887,12 +887,16 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>  		const char *message, void *cb_data)
>  {
>  	struct read_ref_at_cb *cb = cb_data;
> +	int at_indexed_ent;
>  
>  	cb->reccnt++;
>  	cb->tz = tz;
>  	cb->date = timestamp;
>  
> -	if (timestamp <= cb->at_time || cb->cnt == 0) {
> +	if (cb->cnt > 0)
> +		cb->cnt--;
> +	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);

The code treats two cases identically (i.e. the case where cb->cnt
was originally zero, and one).  Is that intended?

I thought the code was to special case only <ref>@{0}, but with this
conditional decrement, cb->cnt==0 would not be usable by the rest
of the code as the "we must read the new side instead" signal. Is
that why null-ness of ooid is also tested here?  It is hard to tell
the intention because "at_indexed_ent" does not quite tell me what
the code wants to use the variable for.

> +	if (timestamp <= cb->at_time || at_indexed_ent) {
>  		if (cb->msg)
>  			*cb->msg = xstrdup(message);
>  		if (cb->cutoff_time)
> @@ -905,28 +909,41 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>  		 * we have not yet updated cb->[n|o]oid so they still
>  		 * hold the values for the previous record.
>  		 */
> -		if (!is_null_oid(&cb->ooid)) {
> -			oidcpy(cb->oid, noid);
> -			if (!oideq(&cb->ooid, noid))
> -				warning(_("log for ref %s has gap after %s"),
> +		if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
> +			warning(_("log for ref %s has gap after %s"),
>  					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
> -		}
> -		else if (cb->date == cb->at_time)
> +		if (at_indexed_ent)
> +			oidcpy(cb->oid, ooid);
> +		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
>  			oidcpy(cb->oid, noid);
>  		else if (!oideq(noid, cb->oid))
>  			warning(_("log for ref %s unexpectedly ended on %s"),
>  				cb->refname, show_date(cb->date, cb->tz,
>  						       DATE_MODE(RFC2822)));
> -		oidcpy(&cb->ooid, ooid);
> -		oidcpy(&cb->noid, noid);
>  		cb->found_it = 1;
> -		return 1;
>  	}
>  	oidcpy(&cb->ooid, ooid);
>  	oidcpy(&cb->noid, noid);
> -	if (cb->cnt > 0)
> -		cb->cnt--;
> -	return 0;
> +	return cb->found_it;
> +}
> +
> +static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
> +				  const char *email, timestamp_t timestamp,
> +				  int tz, const char *message, void *cb_data)
> +{
> +	struct read_ref_at_cb *cb = cb_data;
> +
> +	if (cb->msg)
> +		*cb->msg = xstrdup(message);
> +	if (cb->cutoff_time)
> +		*cb->cutoff_time = timestamp;
> +	if (cb->cutoff_tz)
> +		*cb->cutoff_tz = tz;
> +	if (cb->cutoff_cnt)
> +		*cb->cutoff_cnt = cb->reccnt;
> +	oidcpy(cb->oid, noid);
> +	/* We just want the first entry */
> +	return 1;
>  }

The similarity of this to read_ref_at_ent_oldest is somehow
striking.  Do we really need to invent a new callback?

>  static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
> @@ -967,6 +984,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
>  	cb.cutoff_cnt = cutoff_cnt;
>  	cb.oid = oid;
>  
> +	if (cb.cnt == 0) {
> +		refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
> +		return 0;
> +	}
> +
>  	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
>  
>  	if (!cb.reccnt) {
> diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
> index dc9fe3cbf1..ed4a366e85 100755
> --- a/t/t1503-rev-parse-verify.sh
> +++ b/t/t1503-rev-parse-verify.sh
> @@ -86,8 +86,8 @@ test_expect_success 'fails silently when using -q' '
>  test_expect_success 'fails silently when using -q with deleted reflogs' '
>  	ref=$(git rev-parse HEAD) &&
>  	git update-ref --create-reflog -m "message for refs/test" refs/test "$ref" &&
> -	git reflog delete --updateref --rewrite refs/test@{0} &&
> -	test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
> +	git reflog delete --updateref --rewrite refs/test@{1} &&
> +	test_must_fail git rev-parse -q --verify refs/test@{1} >error 2>&1 &&
>  	test_must_be_empty error
>  '
>  
> @@ -139,6 +139,19 @@ test_expect_success 'master@{n} for various n' '
>  	test_must_fail git rev-parse --verify master@{$Np1}
>  '
>  
> +test_expect_success '@{1} works with only one reflog entry' '
> +	git checkout -B newbranch &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git commit --allow-empty -mexpired &&
> +	git rev-parse --verify newbranch@{1}
> +'
> +
> +test_expect_success '@{0} works with empty reflog' '
> +	git checkout -B newbranch &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git rev-parse --verify newbranch@{0}
> +'
> +
>  test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' '
>  	ln -s does-not-exist .git/refs/heads/broken &&
>  	test_must_fail git rev-parse --verify broken

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-06  5:55 ` Junio C Hamano
@ 2021-01-06  8:25   ` Denton Liu
  2021-01-06 21:02     ` Junio C Hamano
  0 siblings, 1 reply; 21+ messages in thread
From: Denton Liu @ 2021-01-06  8:25 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Hi Junio,

On Tue, Jan 05, 2021 at 09:55:29PM -0800, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > This sequence works
> >
> > 	$ git checkout -b newbranch
> > 	$ git commit --allow-empty -m one
> > 	$ git show -s newbranch@{1}
> >
> > and shows the state that was immediately after the newbranch was
> > created.
> >
> > But then if you do
> >
> > 	$ git reflog expire --expire=now refs/heads/newbranch
> > 	$ git commit --allow=empty -m two
> > 	$ git show -s newbranch@{1}
> >
> > you'd be scolded with
> >
> > 	fatal: log for 'newbranch' only has 1 entries
> >
> > While it is true that it has only 1 entry, we have enough
> > information in that single entry that records the transition between
> > the state in which the tip of the branch was pointing at commit
> > 'one' to the new commit 'two' built on it, so we should be able to
> > answer "what object newbranch was pointing at?". But we refuse to
> > do so.
> 
> Yeah, I am often hit and irritated by this behaviour.

Yep, this was inspired by one of your emails ;)

> > diff --git a/refs.c b/refs.c
> > index 13dc2c3291..c35c61a009 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -887,12 +887,16 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
> >  		const char *message, void *cb_data)
> >  {
> >  	struct read_ref_at_cb *cb = cb_data;
> > +	int at_indexed_ent;
> >  
> >  	cb->reccnt++;
> >  	cb->tz = tz;
> >  	cb->date = timestamp;
> >  
> > -	if (timestamp <= cb->at_time || cb->cnt == 0) {
> > +	if (cb->cnt > 0)
> > +		cb->cnt--;
> > +	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
> 
> The code treats two cases identically (i.e. the case where cb->cnt
> was originally zero, and one).  Is that intended?

It shouldn't be possible for cb->cnt == 0 on the first iteration
because there's a special-case check at [0]. As a result, it can only be
-1 or >= 1 on the first iteration.

The -1 case happens when we're doing date-based lookup and that's what
this if is intended to handle.

In the case where it's >= 1, we will always enter the if and it will
always pre-decrement. This essentially gets us the n-1 behaviour.

> I thought the code was to special case only <ref>@{0}, but with this
> conditional decrement, cb->cnt==0 would not be usable by the rest
> of the code as the "we must read the new side instead" signal. Is
> that why null-ness of ooid is also tested here?  It is hard to tell
> the intention because "at_indexed_ent" does not quite tell me what
> the code wants to use the variable for.

The null-ness of the ooid is needed because on the last entry of the
reflog, ooid will be null so we should skip that.

"at_indexed_ent" is meant to signal when we are indexing the reflog
numerically (as opposed to by date), we have arrived at the correct
entry. If you have a more fitting name, I'm open to suggestions.

> > +	if (timestamp <= cb->at_time || at_indexed_ent) {
> >  		if (cb->msg)
> >  			*cb->msg = xstrdup(message);
> >  		if (cb->cutoff_time)
> > @@ -905,28 +909,41 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
> >  		 * we have not yet updated cb->[n|o]oid so they still
> >  		 * hold the values for the previous record.
> >  		 */
> > -		if (!is_null_oid(&cb->ooid)) {
> > -			oidcpy(cb->oid, noid);
> > -			if (!oideq(&cb->ooid, noid))
> > -				warning(_("log for ref %s has gap after %s"),
> > +		if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
> > +			warning(_("log for ref %s has gap after %s"),
> >  					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
> > -		}
> > -		else if (cb->date == cb->at_time)
> > +		if (at_indexed_ent)
> > +			oidcpy(cb->oid, ooid);
> > +		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
> >  			oidcpy(cb->oid, noid);
> >  		else if (!oideq(noid, cb->oid))
> >  			warning(_("log for ref %s unexpectedly ended on %s"),
> >  				cb->refname, show_date(cb->date, cb->tz,
> >  						       DATE_MODE(RFC2822)));
> > -		oidcpy(&cb->ooid, ooid);
> > -		oidcpy(&cb->noid, noid);
> >  		cb->found_it = 1;
> > -		return 1;
> >  	}
> >  	oidcpy(&cb->ooid, ooid);
> >  	oidcpy(&cb->noid, noid);
> > -	if (cb->cnt > 0)
> > -		cb->cnt--;
> > -	return 0;
> > +	return cb->found_it;
> > +}
> > +
> > +static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
> > +				  const char *email, timestamp_t timestamp,
> > +				  int tz, const char *message, void *cb_data)
> > +{
> > +	struct read_ref_at_cb *cb = cb_data;
> > +
> > +	if (cb->msg)
> > +		*cb->msg = xstrdup(message);
> > +	if (cb->cutoff_time)
> > +		*cb->cutoff_time = timestamp;
> > +	if (cb->cutoff_tz)
> > +		*cb->cutoff_tz = tz;
> > +	if (cb->cutoff_cnt)
> > +		*cb->cutoff_cnt = cb->reccnt;
> > +	oidcpy(cb->oid, noid);
> > +	/* We just want the first entry */
> > +	return 1;
> >  }
> 
> The similarity of this to read_ref_at_ent_oldest is somehow
> striking.  Do we really need to invent a new callback?

Unfortunately, yes. The alternative is to add a flag into
`struct read_ref_at_cb` and we could conditionally choose whether or not
to copy noid or ooid but this seems like the lesser of two evils.

The duplicated part,

	if (cb->msg)
		*cb->msg = xstrdup(message);
	if (cb->cutoff_time)
		*cb->cutoff_time = timestamp;
	if (cb->cutoff_tz)
		*cb->cutoff_tz = tz;
	if (cb->cutoff_cnt)
		*cb->cutoff_cnt = cb->reccnt;

is actually repeated three times -- once in each of the callbacks. I
considered extracting factoring it out into a function but I was on the
fence because the function would still have some duplication since it'd
still require cb, message, timestamp and tz to all be passed in.

> >  static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
> > @@ -967,6 +984,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
> >  	cb.cutoff_cnt = cutoff_cnt;
> >  	cb.oid = oid;
> >  
> > +	if (cb.cnt == 0) {
> > +		refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
> > +		return 0;
> > +	}
> > +

[0]

> >  	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
> >  
> >  	if (!cb.reccnt) {

Thanks,
Denton

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 0/2] refs: allow @{n} to work with n-sized reflog
  2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
                   ` (3 preceding siblings ...)
  2021-01-06  5:55 ` Junio C Hamano
@ 2021-01-06  9:01 ` Denton Liu
  2021-01-06  9:01   ` [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
                     ` (3 more replies)
  4 siblings, 4 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-06  9:01 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

When there is only one reflog entry (perhaps caused by expiring the
reflog and then making a single commit) @{1} errors out even though
there is technically enough information to do the lookup. Look at the
old side of the reflog instead of the new side so that this does not
fail. This is explained in more detail in the commit of the last patch.

This idea was given by Junio at [0].

[0]: https://lore.kernel.org/git/xmqqzh8zgcfp.fsf@gitster.c.googlers.com/

Changes since v1:

* Factor out set_read_ref_cutoffs()

* Check the output of rev-parse to ensure that the intended commit is
  returned

Denton Liu (2):
  refs: factor out set_read_ref_cutoffs()
  refs: allow @{n} to work with n-sized reflog

 refs.c                      | 118 ++++++++++++++++++++----------------
 t/t1503-rev-parse-verify.sh |   4 +-
 t/t1508-at-combinations.sh  |  16 +++++
 3 files changed, 84 insertions(+), 54 deletions(-)

Range-diff against v1:
-:  ---------- > 1:  8f14ec3997 refs: factor out set_read_ref_cutoffs()
1:  0c6885f15f ! 2:  18a35506b8 refs: allow @{n} to work with n-sized reflog
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
      	struct read_ref_at_cb *cb = cb_data;
     +	int at_indexed_ent;
      
    - 	cb->reccnt++;
      	cb->tz = tz;
      	cb->date = timestamp;
      
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
     +		cb->cnt--;
     +	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
     +	if (timestamp <= cb->at_time || at_indexed_ent) {
    - 		if (cb->msg)
    - 			*cb->msg = xstrdup(message);
    - 		if (cb->cutoff_time)
    -@@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
    + 		set_read_ref_cutoffs(cb, timestamp, tz, message);
    + 		/*
      		 * we have not yet updated cb->[n|o]oid so they still
      		 * hold the values for the previous record.
      		 */
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
      			warning(_("log for ref %s unexpectedly ended on %s"),
      				cb->refname, show_date(cb->date, cb->tz,
      						       DATE_MODE(RFC2822)));
    +-		cb->reccnt++;
     -		oidcpy(&cb->ooid, ooid);
     -		oidcpy(&cb->noid, noid);
      		cb->found_it = 1;
     -		return 1;
      	}
    + 	cb->reccnt++;
      	oidcpy(&cb->ooid, ooid);
      	oidcpy(&cb->noid, noid);
     -	if (cb->cnt > 0)
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
     +{
     +	struct read_ref_at_cb *cb = cb_data;
     +
    -+	if (cb->msg)
    -+		*cb->msg = xstrdup(message);
    -+	if (cb->cutoff_time)
    -+		*cb->cutoff_time = timestamp;
    -+	if (cb->cutoff_tz)
    -+		*cb->cutoff_tz = tz;
    -+	if (cb->cutoff_cnt)
    -+		*cb->cutoff_cnt = cb->reccnt;
    ++	set_read_ref_cutoffs(cb, timestamp, tz, message);
     +	oidcpy(cb->oid, noid);
     +	/* We just want the first entry */
     +	return 1;
    @@ t/t1503-rev-parse-verify.sh: test_expect_success 'fails silently when using -q'
      	test_must_be_empty error
      '
      
    -@@ t/t1503-rev-parse-verify.sh: test_expect_success 'master@{n} for various n' '
    - 	test_must_fail git rev-parse --verify master@{$Np1}
    - '
    +
    + ## t/t1508-at-combinations.sh ##
    +@@ t/t1508-at-combinations.sh: test_expect_success 'create path with @' '
    + check "@:normal" blob content
    + check "@:fun@ny" blob content
      
     +test_expect_success '@{1} works with only one reflog entry' '
    -+	git checkout -B newbranch &&
    ++	git checkout -B newbranch master &&
     +	git reflog expire --expire=now refs/heads/newbranch &&
    -+	git commit --allow-empty -mexpired &&
    -+	git rev-parse --verify newbranch@{1}
    ++	git commit --allow-empty -m "first after expiration" &&
    ++	git rev-parse newbranch~ >expect &&
    ++	git rev-parse newbranch@{1} >actual &&
    ++	test_cmp expect actual
     +'
     +
     +test_expect_success '@{0} works with empty reflog' '
    -+	git checkout -B newbranch &&
    ++	git checkout -B newbranch master &&
     +	git reflog expire --expire=now refs/heads/newbranch &&
    -+	git rev-parse --verify newbranch@{0}
    ++	git rev-parse newbranch >expect &&
    ++	git rev-parse newbranch@{0} >actual &&
    ++	test_cmp expect actual
     +'
    -+
    - test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' '
    - 	ln -s does-not-exist .git/refs/heads/broken &&
    - 	test_must_fail git rev-parse --verify broken
    + test_done
-- 
2.30.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs()
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
@ 2021-01-06  9:01   ` Denton Liu
  2021-01-06  9:01   ` [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-06  9:01 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

This block of code is duplicated twice. In a future commit, it will be
duplicated for a third time. Factor out the common functionality into
set_read_ref_cutoffs().

In the case of read_ref_at_ent(), we are incrementing `cb->reccnt` at the
beginning of the function. Move these to right before the return so that
the `cb->reccnt - 1` is changed to `cb->reccnt` and it can be cleanly
factored out into set_read_ref_cutoffs(). The duplication of the
increment statements will be removed in a future patch.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/refs.c b/refs.c
index 13dc2c3291..bfdd04aefd 100644
--- a/refs.c
+++ b/refs.c
@@ -882,25 +882,30 @@ struct read_ref_at_cb {
 	int *cutoff_cnt;
 };
 
+static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
+		timestamp_t timestamp, int tz, const char *message)
+{
+	if (cb->msg)
+		*cb->msg = xstrdup(message);
+	if (cb->cutoff_time)
+		*cb->cutoff_time = timestamp;
+	if (cb->cutoff_tz)
+		*cb->cutoff_tz = tz;
+	if (cb->cutoff_cnt)
+		*cb->cutoff_cnt = cb->reccnt;
+}
+
 static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *email, timestamp_t timestamp, int tz,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	cb->reccnt++;
 	cb->tz = tz;
 	cb->date = timestamp;
 
 	if (timestamp <= cb->at_time || cb->cnt == 0) {
-		if (cb->msg)
-			*cb->msg = xstrdup(message);
-		if (cb->cutoff_time)
-			*cb->cutoff_time = timestamp;
-		if (cb->cutoff_tz)
-			*cb->cutoff_tz = tz;
-		if (cb->cutoff_cnt)
-			*cb->cutoff_cnt = cb->reccnt - 1;
+		set_read_ref_cutoffs(cb, timestamp, tz, message);
 		/*
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
@@ -917,11 +922,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
+		cb->reccnt++;
 		oidcpy(&cb->ooid, ooid);
 		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
 		return 1;
 	}
+	cb->reccnt++;
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
 	if (cb->cnt > 0)
@@ -935,14 +942,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	if (cb->msg)
-		*cb->msg = xstrdup(message);
-	if (cb->cutoff_time)
-		*cb->cutoff_time = timestamp;
-	if (cb->cutoff_tz)
-		*cb->cutoff_tz = tz;
-	if (cb->cutoff_cnt)
-		*cb->cutoff_cnt = cb->reccnt;
+	set_read_ref_cutoffs(cb, timestamp, tz, message);
 	oidcpy(cb->oid, ooid);
 	if (is_null_oid(cb->oid))
 		oidcpy(cb->oid, noid);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
  2021-01-06  9:01   ` [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
@ 2021-01-06  9:01   ` Denton Liu
  2021-01-06  9:59     ` SZEDER Gábor
  2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
  2021-01-07 10:43   ` [PATCH v3 3/2] fixup! " Denton Liu
  3 siblings, 1 reply; 21+ messages in thread
From: Denton Liu @ 2021-01-06  9:01 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

This sequence works

	$ git checkout -b newbranch
	$ git commit --allow-empty -m one
	$ git show -s newbranch@{1}

and shows the state that was immediately after the newbranch was
created.

But then if you do

	$ git reflog expire --expire=now refs/heads/newbranch
	$ git commit --allow=empty -m two
	$ git show -s newbranch@{1}

you'd be scolded with

	fatal: log for 'newbranch' only has 1 entries

While it is true that it has only 1 entry, we have enough
information in that single entry that records the transition between
the state in which the tip of the branch was pointing at commit
'one' to the new commit 'two' built on it, so we should be able to
answer "what object newbranch was pointing at?". But we refuse to
do so.

Make @{0} the special case where we use the new side to look up that
entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
of the reflog.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c                      | 42 ++++++++++++++++++++++++-------------
 t/t1503-rev-parse-verify.sh |  4 ++--
 t/t1508-at-combinations.sh  | 16 ++++++++++++++
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/refs.c b/refs.c
index bfdd04aefd..9eb26d456d 100644
--- a/refs.c
+++ b/refs.c
@@ -900,40 +900,49 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
+	int at_indexed_ent;
 
 	cb->tz = tz;
 	cb->date = timestamp;
 
-	if (timestamp <= cb->at_time || cb->cnt == 0) {
+	if (cb->cnt > 0)
+		cb->cnt--;
+	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
+	if (timestamp <= cb->at_time || at_indexed_ent) {
 		set_read_ref_cutoffs(cb, timestamp, tz, message);
 		/*
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
 		 */
-		if (!is_null_oid(&cb->ooid)) {
-			oidcpy(cb->oid, noid);
-			if (!oideq(&cb->ooid, noid))
-				warning(_("log for ref %s has gap after %s"),
+		if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
+			warning(_("log for ref %s has gap after %s"),
 					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
-		}
-		else if (cb->date == cb->at_time)
+		if (at_indexed_ent)
+			oidcpy(cb->oid, ooid);
+		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
 			oidcpy(cb->oid, noid);
 		else if (!oideq(noid, cb->oid))
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
-		cb->reccnt++;
-		oidcpy(&cb->ooid, ooid);
-		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
-		return 1;
 	}
 	cb->reccnt++;
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
-	if (cb->cnt > 0)
-		cb->cnt--;
-	return 0;
+	return cb->found_it;
+}
+
+static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
+				  const char *email, timestamp_t timestamp,
+				  int tz, const char *message, void *cb_data)
+{
+	struct read_ref_at_cb *cb = cb_data;
+
+	set_read_ref_cutoffs(cb, timestamp, tz, message);
+	oidcpy(cb->oid, noid);
+	/* We just want the first entry */
+	return 1;
 }
 
 static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
@@ -967,6 +976,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
+	if (cb.cnt == 0) {
+		refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
+		return 0;
+	}
+
 	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
index dc9fe3cbf1..a7e9b4863d 100755
--- a/t/t1503-rev-parse-verify.sh
+++ b/t/t1503-rev-parse-verify.sh
@@ -86,8 +86,8 @@ test_expect_success 'fails silently when using -q' '
 test_expect_success 'fails silently when using -q with deleted reflogs' '
 	ref=$(git rev-parse HEAD) &&
 	git update-ref --create-reflog -m "message for refs/test" refs/test "$ref" &&
-	git reflog delete --updateref --rewrite refs/test@{0} &&
-	test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
+	git reflog delete --updateref --rewrite refs/test@{1} &&
+	test_must_fail git rev-parse -q --verify refs/test@{1} >error 2>&1 &&
 	test_must_be_empty error
 '
 
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 4a9964e9dc..15aac6e77a 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -99,4 +99,20 @@ test_expect_success 'create path with @' '
 check "@:normal" blob content
 check "@:fun@ny" blob content
 
+test_expect_success '@{1} works with only one reflog entry' '
+	git checkout -B newbranch master &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	git commit --allow-empty -m "first after expiration" &&
+	git rev-parse newbranch~ >expect &&
+	git rev-parse newbranch@{1} >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success '@{0} works with empty reflog' '
+	git checkout -B newbranch master &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	git rev-parse newbranch >expect &&
+	git rev-parse newbranch@{0} >actual &&
+	test_cmp expect actual
+'
 test_done
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog
  2021-01-06  9:01   ` [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
@ 2021-01-06  9:59     ` SZEDER Gábor
  0 siblings, 0 replies; 21+ messages in thread
From: SZEDER Gábor @ 2021-01-06  9:59 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Martin Ågren, Junio C Hamano

On Wed, Jan 06, 2021 at 01:01:54AM -0800, Denton Liu wrote:
> diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
> index 4a9964e9dc..15aac6e77a 100755
> --- a/t/t1508-at-combinations.sh
> +++ b/t/t1508-at-combinations.sh
> @@ -99,4 +99,20 @@ test_expect_success 'create path with @' '
>  check "@:normal" blob content
>  check "@:fun@ny" blob content
>  
> +test_expect_success '@{1} works with only one reflog entry' '
> +	git checkout -B newbranch master &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git commit --allow-empty -m "first after expiration" &&
> +	git rev-parse newbranch~ >expect &&
> +	git rev-parse newbranch@{1} >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success '@{0} works with empty reflog' '
> +	git checkout -B newbranch master &&
> +	git reflog expire --expire=now refs/heads/newbranch &&
> +	git rev-parse newbranch >expect &&
> +	git rev-parse newbranch@{0} >actual &&
> +	test_cmp expect actual

You could use 'test_cmp_rev' in these two tests to spare a few lines
and to get a bit friendlier error message on failure.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] refs: allow @{n} to work with n-sized reflog
  2021-01-06  8:25   ` Denton Liu
@ 2021-01-06 21:02     ` Junio C Hamano
  0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2021-01-06 21:02 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

>> > -	if (timestamp <= cb->at_time || cb->cnt == 0) {
>> > +	if (cb->cnt > 0)
>> > +		cb->cnt--;
>> > +	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
>> 
>> The code treats two cases identically (i.e. the case where cb->cnt
>> was originally zero, and one).  Is that intended?
>
> It shouldn't be possible for cb->cnt == 0 on the first iteration
> because there's a special-case check at [0]. As a result, it can only be
> -1 or >= 1 on the first iteration.
>
> The -1 case happens when we're doing date-based lookup and that's what
> this if is intended to handle.

I knew about -1; it wasn't apparent that the caller won't call us
with cnt==0.  Perhaps it deserves a mention in an in-code comment.

> "at_indexed_ent" is meant to signal when we are indexing the reflog
> numerically (as opposed to by date), we have arrived at the correct
> entry. If you have a more fitting name, I'm open to suggestions.

When querying for <ref>@{24}, all the entries are indexed
numerically (counted), not just the 24th one, and that contributed
to my puzzlement.

I offhand do not think of a "name", but "at target", "found",
"reached count", are phrases that come to my mind as starting
points.

Thanks.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v3 0/2] refs: allow @{n} to work with n-sized reflog
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
  2021-01-06  9:01   ` [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
  2021-01-06  9:01   ` [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
@ 2021-01-07 10:36   ` Denton Liu
  2021-01-07 10:36     ` [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
                       ` (2 more replies)
  2021-01-07 10:43   ` [PATCH v3 3/2] fixup! " Denton Liu
  3 siblings, 3 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-07 10:36 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

When there is only one reflog entry (perhaps caused by expiring the
reflog and then making a single commit) @{1} errors out even though
there is technically enough information to do the lookup. Look at the
old side of the reflog instead of the new side so that this does not
fail. This is explained in more detail in the commit of the last patch.

This idea was given by Junio at [0].

[0]: https://lore.kernel.org/git/xmqqzh8zgcfp.fsf@gitster.c.googlers.com/

Changes since v1:

* Factor out set_read_ref_cutoffs()

* Check the output of rev-parse to ensure that the intended commit is
  returned

Changes since v2:

* Rename at_indexed_ent -> reached_count

* Add an in-code comment to document that cb->cnt can't be 0 in the first
  iteration of read_ref_at_ent()

* Make test cases use test_cmp_rev() for brevity and better errors

Denton Liu (2):
  refs: factor out set_read_ref_cutoffs()
  refs: allow @{n} to work with n-sized reflog

 refs.c                      | 122 +++++++++++++++++++++---------------
 t/t1503-rev-parse-verify.sh |   4 +-
 t/t1508-at-combinations.sh  |  12 ++++
 3 files changed, 84 insertions(+), 54 deletions(-)

Range-diff against v2:
1:  8f14ec3997 = 1:  8f14ec3997 refs: factor out set_read_ref_cutoffs()
2:  18a35506b8 ! 2:  c88c997eab refs: allow @{n} to work with n-sized reflog
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
      		const char *message, void *cb_data)
      {
      	struct read_ref_at_cb *cb = cb_data;
    -+	int at_indexed_ent;
    ++	int reached_count;
      
      	cb->tz = tz;
      	cb->date = timestamp;
      
     -	if (timestamp <= cb->at_time || cb->cnt == 0) {
    ++	/*
    ++	 * It is not possible for cb->cnt == 0 on the first itertion because
    ++	 * that special case is handled in read_ref_at().
    ++	 */
     +	if (cb->cnt > 0)
     +		cb->cnt--;
    -+	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
    -+	if (timestamp <= cb->at_time || at_indexed_ent) {
    ++	reached_count = cb->cnt == 0 && !is_null_oid(ooid);
    ++	if (timestamp <= cb->at_time || reached_count) {
      		set_read_ref_cutoffs(cb, timestamp, tz, message);
      		/*
      		 * we have not yet updated cb->[n|o]oid so they still
    @@ refs.c: static int read_ref_at_ent(struct object_id *ooid, struct object_id *noi
      					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
     -		}
     -		else if (cb->date == cb->at_time)
    -+		if (at_indexed_ent)
    ++		if (reached_count)
     +			oidcpy(cb->oid, ooid);
     +		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
      			oidcpy(cb->oid, noid);
    @@ t/t1508-at-combinations.sh: test_expect_success 'create path with @' '
     +	git checkout -B newbranch master &&
     +	git reflog expire --expire=now refs/heads/newbranch &&
     +	git commit --allow-empty -m "first after expiration" &&
    -+	git rev-parse newbranch~ >expect &&
    -+	git rev-parse newbranch@{1} >actual &&
    -+	test_cmp expect actual
    ++	test_cmp_rev newbranch~ newbranch@{1}
     +'
     +
     +test_expect_success '@{0} works with empty reflog' '
     +	git checkout -B newbranch master &&
     +	git reflog expire --expire=now refs/heads/newbranch &&
    -+	git rev-parse newbranch >expect &&
    -+	git rev-parse newbranch@{0} >actual &&
    -+	test_cmp expect actual
    ++	test_cmp_rev newbranch newbranch@{0}
     +'
      test_done
-- 
2.30.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs()
  2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
@ 2021-01-07 10:36     ` Denton Liu
  2021-01-07 10:36     ` [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
  2021-01-10 14:44     ` [PATCH v3 0/2] " SZEDER Gábor
  2 siblings, 0 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-07 10:36 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

This block of code is duplicated twice. In a future commit, it will be
duplicated for a third time. Factor out the common functionality into
set_read_ref_cutoffs().

In the case of read_ref_at_ent(), we are incrementing `cb->reccnt` at the
beginning of the function. Move these to right before the return so that
the `cb->reccnt - 1` is changed to `cb->reccnt` and it can be cleanly
factored out into set_read_ref_cutoffs(). The duplication of the
increment statements will be removed in a future patch.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/refs.c b/refs.c
index 13dc2c3291..bfdd04aefd 100644
--- a/refs.c
+++ b/refs.c
@@ -882,25 +882,30 @@ struct read_ref_at_cb {
 	int *cutoff_cnt;
 };
 
+static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
+		timestamp_t timestamp, int tz, const char *message)
+{
+	if (cb->msg)
+		*cb->msg = xstrdup(message);
+	if (cb->cutoff_time)
+		*cb->cutoff_time = timestamp;
+	if (cb->cutoff_tz)
+		*cb->cutoff_tz = tz;
+	if (cb->cutoff_cnt)
+		*cb->cutoff_cnt = cb->reccnt;
+}
+
 static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *email, timestamp_t timestamp, int tz,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	cb->reccnt++;
 	cb->tz = tz;
 	cb->date = timestamp;
 
 	if (timestamp <= cb->at_time || cb->cnt == 0) {
-		if (cb->msg)
-			*cb->msg = xstrdup(message);
-		if (cb->cutoff_time)
-			*cb->cutoff_time = timestamp;
-		if (cb->cutoff_tz)
-			*cb->cutoff_tz = tz;
-		if (cb->cutoff_cnt)
-			*cb->cutoff_cnt = cb->reccnt - 1;
+		set_read_ref_cutoffs(cb, timestamp, tz, message);
 		/*
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
@@ -917,11 +922,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
+		cb->reccnt++;
 		oidcpy(&cb->ooid, ooid);
 		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
 		return 1;
 	}
+	cb->reccnt++;
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
 	if (cb->cnt > 0)
@@ -935,14 +942,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	if (cb->msg)
-		*cb->msg = xstrdup(message);
-	if (cb->cutoff_time)
-		*cb->cutoff_time = timestamp;
-	if (cb->cutoff_tz)
-		*cb->cutoff_tz = tz;
-	if (cb->cutoff_cnt)
-		*cb->cutoff_cnt = cb->reccnt;
+	set_read_ref_cutoffs(cb, timestamp, tz, message);
 	oidcpy(cb->oid, ooid);
 	if (is_null_oid(cb->oid))
 		oidcpy(cb->oid, noid);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog
  2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
  2021-01-07 10:36     ` [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
@ 2021-01-07 10:36     ` Denton Liu
  2021-01-10 20:31       ` Simon Ruderich
  2021-01-10 14:44     ` [PATCH v3 0/2] " SZEDER Gábor
  2 siblings, 1 reply; 21+ messages in thread
From: Denton Liu @ 2021-01-07 10:36 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano

This sequence works

	$ git checkout -b newbranch
	$ git commit --allow-empty -m one
	$ git show -s newbranch@{1}

and shows the state that was immediately after the newbranch was
created.

But then if you do

	$ git reflog expire --expire=now refs/heads/newbranch
	$ git commit --allow=empty -m two
	$ git show -s newbranch@{1}

you'd be scolded with

	fatal: log for 'newbranch' only has 1 entries

While it is true that it has only 1 entry, we have enough
information in that single entry that records the transition between
the state in which the tip of the branch was pointing at commit
'one' to the new commit 'two' built on it, so we should be able to
answer "what object newbranch was pointing at?". But we refuse to
do so.

Make @{0} the special case where we use the new side to look up that
entry. Otherwise, look up @{n} using the old side of the (n-1)th entry
of the reflog.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c                      | 46 ++++++++++++++++++++++++++-----------
 t/t1503-rev-parse-verify.sh |  4 ++--
 t/t1508-at-combinations.sh  | 12 ++++++++++
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/refs.c b/refs.c
index bfdd04aefd..e70dcd33f7 100644
--- a/refs.c
+++ b/refs.c
@@ -900,40 +900,53 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
+	int reached_count;
 
 	cb->tz = tz;
 	cb->date = timestamp;
 
-	if (timestamp <= cb->at_time || cb->cnt == 0) {
+	/*
+	 * It is not possible for cb->cnt == 0 on the first itertion because
+	 * that special case is handled in read_ref_at().
+	 */
+	if (cb->cnt > 0)
+		cb->cnt--;
+	reached_count = cb->cnt == 0 && !is_null_oid(ooid);
+	if (timestamp <= cb->at_time || reached_count) {
 		set_read_ref_cutoffs(cb, timestamp, tz, message);
 		/*
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
 		 */
-		if (!is_null_oid(&cb->ooid)) {
-			oidcpy(cb->oid, noid);
-			if (!oideq(&cb->ooid, noid))
-				warning(_("log for ref %s has gap after %s"),
+		if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
+			warning(_("log for ref %s has gap after %s"),
 					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
-		}
-		else if (cb->date == cb->at_time)
+		if (reached_count)
+			oidcpy(cb->oid, ooid);
+		else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
 			oidcpy(cb->oid, noid);
 		else if (!oideq(noid, cb->oid))
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
-		cb->reccnt++;
-		oidcpy(&cb->ooid, ooid);
-		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
-		return 1;
 	}
 	cb->reccnt++;
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
-	if (cb->cnt > 0)
-		cb->cnt--;
-	return 0;
+	return cb->found_it;
+}
+
+static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
+				  const char *email, timestamp_t timestamp,
+				  int tz, const char *message, void *cb_data)
+{
+	struct read_ref_at_cb *cb = cb_data;
+
+	set_read_ref_cutoffs(cb, timestamp, tz, message);
+	oidcpy(cb->oid, noid);
+	/* We just want the first entry */
+	return 1;
 }
 
 static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
@@ -967,6 +980,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
+	if (cb.cnt == 0) {
+		refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
+		return 0;
+	}
+
 	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
index dc9fe3cbf1..a7e9b4863d 100755
--- a/t/t1503-rev-parse-verify.sh
+++ b/t/t1503-rev-parse-verify.sh
@@ -86,8 +86,8 @@ test_expect_success 'fails silently when using -q' '
 test_expect_success 'fails silently when using -q with deleted reflogs' '
 	ref=$(git rev-parse HEAD) &&
 	git update-ref --create-reflog -m "message for refs/test" refs/test "$ref" &&
-	git reflog delete --updateref --rewrite refs/test@{0} &&
-	test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
+	git reflog delete --updateref --rewrite refs/test@{1} &&
+	test_must_fail git rev-parse -q --verify refs/test@{1} >error 2>&1 &&
 	test_must_be_empty error
 '
 
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 4a9964e9dc..528a77287c 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -99,4 +99,16 @@ test_expect_success 'create path with @' '
 check "@:normal" blob content
 check "@:fun@ny" blob content
 
+test_expect_success '@{1} works with only one reflog entry' '
+	git checkout -B newbranch master &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	git commit --allow-empty -m "first after expiration" &&
+	test_cmp_rev newbranch~ newbranch@{1}
+'
+
+test_expect_success '@{0} works with empty reflog' '
+	git checkout -B newbranch master &&
+	git reflog expire --expire=now refs/heads/newbranch &&
+	test_cmp_rev newbranch newbranch@{0}
+'
 test_done
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v3 3/2] fixup! refs: allow @{n} to work with n-sized reflog
  2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
                     ` (2 preceding siblings ...)
  2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
@ 2021-01-07 10:43   ` Denton Liu
  3 siblings, 0 replies; 21+ messages in thread
From: Denton Liu @ 2021-01-07 10:43 UTC (permalink / raw)
  To: Git Mailing List

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t1508-at-combinations.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 528a77287c..e4521b7b97 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -111,4 +111,5 @@ test_expect_success '@{0} works with empty reflog' '
 	git reflog expire --expire=now refs/heads/newbranch &&
 	test_cmp_rev newbranch newbranch@{0}
 '
+
 test_done
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v3 0/2] refs: allow @{n} to work with n-sized reflog
  2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
  2021-01-07 10:36     ` [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
  2021-01-07 10:36     ` [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
@ 2021-01-10 14:44     ` SZEDER Gábor
  2021-01-10 20:24       ` Junio C Hamano
  2 siblings, 1 reply; 21+ messages in thread
From: SZEDER Gábor @ 2021-01-10 14:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Denton Liu, Git Mailing List, Martin Ågren

Junio,

On Thu, Jan 07, 2021 at 02:36:57AM -0800, Denton Liu wrote:
> When there is only one reflog entry (perhaps caused by expiring the
> reflog and then making a single commit) @{1} errors out even though
> there is technically enough information to do the lookup. Look at the
> old side of the reflog instead of the new side so that this does not
> fail. This is explained in more detail in the commit of the last patch.

> Denton Liu (2):
>   refs: factor out set_read_ref_cutoffs()
>   refs: allow @{n} to work with n-sized reflog

Topic 'dl/reflog-with-single-entry', i.e. these two patches queued
directly on top of v2.29.2, break the test case "61 - valid ref of the
form "n", n < N" in 't3903-stash.sh'.  Queueing them on top of
something already containing commit 4f44c5659b (stash: simplify reflog
emptiness check, 2020-10-24) fixes this issue.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v3 0/2] refs: allow @{n} to work with n-sized reflog
  2021-01-10 14:44     ` [PATCH v3 0/2] " SZEDER Gábor
@ 2021-01-10 20:24       ` Junio C Hamano
  0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2021-01-10 20:24 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Denton Liu, Git Mailing List, Martin Ågren

SZEDER Gábor <szeder.dev@gmail.com> writes:

> Junio,
>
> On Thu, Jan 07, 2021 at 02:36:57AM -0800, Denton Liu wrote:
>> When there is only one reflog entry (perhaps caused by expiring the
>> reflog and then making a single commit) @{1} errors out even though
>> there is technically enough information to do the lookup. Look at the
>> old side of the reflog instead of the new side so that this does not
>> fail. This is explained in more detail in the commit of the last patch.
>
>> Denton Liu (2):
>>   refs: factor out set_read_ref_cutoffs()
>>   refs: allow @{n} to work with n-sized reflog
>
> Topic 'dl/reflog-with-single-entry', i.e. these two patches queued
> directly on top of v2.29.2, break the test case "61 - valid ref of the
> form "n", n < N" in 't3903-stash.sh'.  Queueing them on top of
> something already containing commit 4f44c5659b (stash: simplify reflog
> emptiness check, 2020-10-24) fixes this issue.

Thanks for carefully watching ;-)

There is no reason why this fix needs to be backported down to 2.29
track, I would think.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog
  2021-01-07 10:36     ` [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
@ 2021-01-10 20:31       ` Simon Ruderich
  2021-01-12  6:14         ` [PATCH v3] fixup! " Denton Liu
  0 siblings, 1 reply; 21+ messages in thread
From: Simon Ruderich @ 2021-01-10 20:31 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Martin Ågren, SZEDER Gábor,
	Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

On Thu, Jan 07, 2021 at 02:36:59AM -0800, Denton Liu wrote:
> diff --git a/refs.c b/refs.c
> index bfdd04aefd..e70dcd33f7 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -900,40 +900,53 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>  		const char *message, void *cb_data)
>  {
>  	struct read_ref_at_cb *cb = cb_data;
> +	int reached_count;
>
>  	cb->tz = tz;
>  	cb->date = timestamp;
>
> -	if (timestamp <= cb->at_time || cb->cnt == 0) {
> +	/*
> +	 * It is not possible for cb->cnt == 0 on the first itertion because

s/itertion/iteration/

Regards
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v3] fixup! refs: allow @{n} to work with n-sized reflog
  2021-01-10 20:31       ` Simon Ruderich
@ 2021-01-12  6:14         ` Denton Liu
  2021-01-12  6:18           ` Denton Liu
  0 siblings, 1 reply; 21+ messages in thread
From: Denton Liu @ 2021-01-12  6:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano,
	Simon Ruderich

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index e70dcd33f7..03968ad787 100644
--- a/refs.c
+++ b/refs.c
@@ -906,7 +906,7 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 	cb->date = timestamp;
 
 	/*
-	 * It is not possible for cb->cnt == 0 on the first itertion because
+	 * It is not possible for cb->cnt == 0 on the first iteration because
 	 * that special case is handled in read_ref_at().
 	 */
 	if (cb->cnt > 0)
-- 
2.30.0.284.gd98b1dd5ea


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v3] fixup! refs: allow @{n} to work with n-sized reflog
  2021-01-12  6:14         ` [PATCH v3] fixup! " Denton Liu
@ 2021-01-12  6:18           ` Denton Liu
  2021-01-12  6:27             ` Junio C Hamano
  0 siblings, 1 reply; 21+ messages in thread
From: Denton Liu @ 2021-01-12  6:18 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Martin Ågren, SZEDER Gábor, Junio C Hamano,
	Simon Ruderich

Please disregard, I see that the fixup has already been included.

-Denton

On Mon, Jan 11, 2021 at 10:14:14PM -0800, Denton Liu wrote:
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  refs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/refs.c b/refs.c
> index e70dcd33f7..03968ad787 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -906,7 +906,7 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>  	cb->date = timestamp;
>  
>  	/*
> -	 * It is not possible for cb->cnt == 0 on the first itertion because
> +	 * It is not possible for cb->cnt == 0 on the first iteration because
>  	 * that special case is handled in read_ref_at().
>  	 */
>  	if (cb->cnt > 0)
> -- 
> 2.30.0.284.gd98b1dd5ea
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v3] fixup! refs: allow @{n} to work with n-sized reflog
  2021-01-12  6:18           ` Denton Liu
@ 2021-01-12  6:27             ` Junio C Hamano
  0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2021-01-12  6:27 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Martin Ågren, SZEDER Gábor,
	Simon Ruderich

Denton Liu <liu.denton@gmail.com> writes:

> Please disregard, I see that the fixup has already been included.

Being careful never hurts; it may make duplicated work from time to
time, but that is better than fixes falling thru the cracks.

Thanks.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-01-12  6:31 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
2021-01-02 22:30 ` Martin Ågren
2021-01-03  1:24 ` Denton Liu
2021-01-05  8:52 ` SZEDER Gábor
2021-01-06  5:55 ` Junio C Hamano
2021-01-06  8:25   ` Denton Liu
2021-01-06 21:02     ` Junio C Hamano
2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
2021-01-06  9:01   ` [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
2021-01-06  9:01   ` [PATCH v2 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
2021-01-06  9:59     ` SZEDER Gábor
2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
2021-01-07 10:36     ` [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
2021-01-07 10:36     ` [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
2021-01-10 20:31       ` Simon Ruderich
2021-01-12  6:14         ` [PATCH v3] fixup! " Denton Liu
2021-01-12  6:18           ` Denton Liu
2021-01-12  6:27             ` Junio C Hamano
2021-01-10 14:44     ` [PATCH v3 0/2] " SZEDER Gábor
2021-01-10 20:24       ` Junio C Hamano
2021-01-07 10:43   ` [PATCH v3 3/2] fixup! " Denton Liu

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).