threads / patch / 41231

patchpush --force-with-lease: Fix ref status reporting

Subject: [PATCH] push --force-with-lease: Fix ref status reporting

## tl;dr

3 messages between Jan 21, 2016 and Jan 26, 2016. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Andrew Wheeler· Jan 21, 2016, 03:17 UTC · lore
From: Andrew Wheeler <awheeler@motorola.com>

The --force--with-lease push option leads to less detailed status information than --force. In particular, the output indicates that a reference was fast-forwarded, even when it was force-updated.

Modify the --force-with-lease ref status logic to leverage the --force ref status logic when the "lease" conditions are met.

Signed-off-by: Andrew Wheeler <awheeler@motorola.com>
---
 remote.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
Show changes to remote.c +9 −7
diff --git a/remote.c b/remote.c
index 9d34b5a..bad6213 100644
--- a/remote.c
+++ b/remote.c
@@ -1545,11 +1545,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		}
 
 		/*
-		 * Bypass the usual "must fast-forward" check but
-		 * replace it with a weaker "the old value must be
-		 * this value we observed".  If the remote ref has
-		 * moved and is now different from what we expect,
-		 * reject any push.
+		 * If the remote ref has moved and is now different
+		 * from what we expect, reject any push.
 		 *
 		 * It also is an error if the user told us to check
 		 * with the remote-tracking branch to find the value
@@ -1560,10 +1557,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 			if (ref->expect_old_no_trackback ||
 			    oidcmp(&ref->old_oid, &ref->old_oid_expect))
 				reject_reason = REF_STATUS_REJECT_STALE;
+			else
+				/* If the ref isn't stale then force the update. */
+				force_ref_update = 1;
 		}
 
 		/*
-		 * The usual "must fast-forward" rules.
+		 * If the update isn't already rejected then check
+		 * the usual "must fast-forward" rules.
 		 *
 		 * Decide whether an individual refspec A:B can be
 		 * pushed.  The push will succeed if any of the
@@ -1580,9 +1581,10 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		 *
 		 * (4) it is forced using the +A:B notation, or by
 		 *     passing the --force argument
+		 *
 		 */
 
-		else if (!ref->deletion && !is_null_oid(&ref->old_oid)) {
+		if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
 			if (starts_with(ref->name, "refs/tags/"))
 				reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
 			else if (!has_object_file(&ref->old_oid))
-- 
1.7.11.2
Junio C Hamano· Jan 25, 2016, 19:37 UTC · re: Andrew Wheeler · lore

Re: [PATCH] push --force-with-lease: Fix ref status reporting

Andrew Wheeler <agwheeler@gmail.com> writes:
Show 10 quoted lines
> From: Andrew Wheeler <awheeler@motorola.com>
>
> The --force--with-lease push option leads to less
> detailed status information than --force. In particular,
> the output indicates that a reference was fast-forwarded,
> even when it was force-updated.
>
> Modify the --force-with-lease ref status logic to leverage
> the --force ref status logic when the "lease" conditions
> are met.

The description of the observed problem makes sense. Thanks for working on this.

Show 21 quoted lines
> Signed-off-by: Andrew Wheeler <awheeler@motorola.com>
> ---
>  remote.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/remote.c b/remote.c
> index 9d34b5a..bad6213 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -1545,11 +1545,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
>  		}
>  
>  		/*
> -		 * Bypass the usual "must fast-forward" check but
> -		 * replace it with a weaker "the old value must be
> -		 * this value we observed".  If the remote ref has
> -		 * moved and is now different from what we expect,
> -		 * reject any push.
> +		 * If the remote ref has moved and is now different
> +		 * from what we expect, reject any push.
>  		 *

This simplification of the comment makes sense, especially with the code that results from the change of the last "else if".

Show 23 quoted lines
>  		 * It also is an error if the user told us to check
>  		 * with the remote-tracking branch to find the value
> @@ -1560,10 +1557,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
>  			if (ref->expect_old_no_trackback ||
>  			    oidcmp(&ref->old_oid, &ref->old_oid_expect))
>  				reject_reason = REF_STATUS_REJECT_STALE;
> +			else
> +				/* If the ref isn't stale then force the update. */
> +				force_ref_update = 1;
>  		}
>  
>  		/*
> -		 * The usual "must fast-forward" rules.
> +		 * If the update isn't already rejected then check
> +		 * the usual "must fast-forward" rules.
>  		 *
>  		 * Decide whether an individual refspec A:B can be
>  		 * pushed.  The push will succeed if any of the
> @@ -1580,9 +1581,10 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
>  		 *
>  		 * (4) it is forced using the +A:B notation, or by
>  		 *     passing the --force argument
> +		 *
This new blank line is probably unwanted.
Show 7 quoted lines
>  		 */
>  
> -		else if (!ref->deletion && !is_null_oid(&ref->old_oid)) {
> +		if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
>  			if (starts_with(ref->name, "refs/tags/"))
>  				reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
>  			else if (!has_object_file(&ref->old_oid))

OK. So the idea is that a successful force-with-lease push would have a zero reject_reason at this point, and the if/else cascade would still trigger and would set it to STATUS_REJECT_NEEDS_FORCE, just like a usual forced push without a lease. And then because the local variable force_ref_update is set, it would report the forced success exactly the same way as the usual forced push.

Sounds very sensible.

Do we want to make sure that other people will not break this fix in the future by adding a few tests, perhaps to t/t5533?

Thanks.
Andrew Wheeler· Jan 26, 2016, 02:36 UTC · re: Junio C Hamano · lore

Re: [PATCH] push --force-with-lease: Fix ref status reporting

On Mon, Jan 25, 2016 at 1:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
> >                *     passing the --force argument
> > +              *
>
> This new blank line is probably unwanted.
Show 5 quoted lines
> Do we want to make sure that other people will not break this fix in
> the future by adding a few tests, perhaps to t/t5533?
>
> Thanks.
>

Great idea. I'll add some tests to t/t5533, remove that blank line above, and share a new patch.

Thanks for the review!
-andrew

← back to recent threads