threads / patch / 62445

patch, 2 partsA few --shallow-exclude fixes

Subject: [PATCH 0/2] A few --shallow-exclude fixes

## tl;dr

7 messages between Nov 4, 2024 and Nov 5, 2024. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

Elijah Newren via GitGitGadget· Nov 4, 2024, 19:02 UTC · lore

Here's a couple patches to fix up an error message and the documentation around the --shallow-exclude option.

Elijah Newren (2):
  upload-pack: fix ambiguous error message
  doc: correct misleading descriptions for --shallow-exclude
 Documentation/fetch-options.txt  | 2 +-
 Documentation/git-clone.txt      | 2 +-
 Documentation/git-fetch-pack.txt | 2 +-
 builtin/clone.c                  | 2 +-
 builtin/fetch.c                  | 4 ++--
 builtin/pull.c                   | 4 ++--
 t/t5500-fetch-pack.sh            | 7 +++++++
 upload-pack.c                    | 6 +++++-
 8 files changed, 20 insertions(+), 9 deletions(-)
base-commit: 8f8d6eee531b3fa1a8ef14f169b0cb5035f7a772
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1822%2Fnewren%2Fshallow-exclude-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1822/newren/shallow-exclude-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1822
-- 
gitgitgadget
Elijah Newren via GitGitGadget· Nov 4, 2024, 19:02 UTC · re: Elijah Newren via GitGitGadget · lore

[PATCH 1/2] upload-pack: fix ambiguous error message

From: Elijah Newren <newren@gmail.com>

upload-pack.c takes any --shallow-exclude argument(s) from clone/fetch/etc. and passes them through expand_ref(). If it does not get back exactly one ref from the call to expand_ref(), it will die with the following error:

    fatal: git upload-pack: ambiguous deepen-not: %s

Given that the documentation suggests to users that --shallow-exclude accepts a revision rather than a ref (which will be corrected in a subsequent commit), users may try to pass a revision. In such a case, expand_ref() will return 0 matches, but the error message we print will be misleading since "ambiguous" suggests there are multiple matches. Provide a clearer error message for such a case.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t5500-fetch-pack.sh | 7 +++++++
 upload-pack.c         | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
Show changes to 2 files +12 −1

t/t5500-fetch-pack.sh, upload-pack.c

diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 8da8e7fe423..6552da78d19 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -926,6 +926,13 @@ test_expect_success 'fetch exclude tag one' '
 	test_cmp expected actual
 '
 
+test_expect_success 'fetch exclude tag one as revision' '
+	test_when_finished rm -f rev err &&
+	git -C shallow-exclude rev-parse one >rev &&
+	test_must_fail git -C shallow12 fetch --shallow-exclude $(cat rev) origin 2>err &&
+	grep "deepen-not is not a ref:" err
+'
+
 test_expect_success 'fetching deepen' '
 	test_create_repo shallow-deepen &&
 	(
diff --git a/upload-pack.c b/upload-pack.c
index 6d6e0f9f980..640d45295e1 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1025,10 +1025,14 @@ static int process_deepen_not(const char *line, struct oidset *deepen_not, int *
 {
 	const char *arg;
 	if (skip_prefix(line, "deepen-not ", &arg)) {
+		int cnt;
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
+		cnt = expand_ref(the_repository, arg, strlen(arg), &oid, &ref);
+		if (cnt > 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
+		if (cnt < 1)
+			die("git upload-pack: deepen-not is not a ref: %s", line);
 		oidset_insert(deepen_not, &oid);
 		free(ref);
 		*deepen_rev_list = 1;
-- 
gitgitgadget
Patrick Steinhardt· Nov 5, 2024, 06:27 UTC · re: Elijah Newren via GitGitGadget · lore

Re: [PATCH 1/2] upload-pack: fix ambiguous error message

On Mon, Nov 04, 2024 at 07:02:43PM +0000, Elijah Newren via GitGitGadget wrote:
Show 17 quoted lines
> diff --git a/upload-pack.c b/upload-pack.c
> index 6d6e0f9f980..640d45295e1 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -1025,10 +1025,14 @@ static int process_deepen_not(const char *line, struct oidset *deepen_not, int *
>  {
>  	const char *arg;
>  	if (skip_prefix(line, "deepen-not ", &arg)) {
> +		int cnt;
>  		char *ref = NULL;
>  		struct object_id oid;
> -		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
> +		cnt = expand_ref(the_repository, arg, strlen(arg), &oid, &ref);
> +		if (cnt > 1)
>  			die("git upload-pack: ambiguous deepen-not: %s", line);
> +		if (cnt < 1)
> +			die("git upload-pack: deepen-not is not a ref: %s", line);

I was wondering whether `expand_ref()` could ever return negative, but after reading through its implementation that doesn't seem to be the case. It's somewhat misleading that it returns `int`, as `size_t` would convey the return value in a better spirit.

Anyway, that is not an issue of this patch series, and the change looks good.

Patrick
Elijah Newren via GitGitGadget· Nov 4, 2024, 19:02 UTC · re: Elijah Newren via GitGitGadget · lore

[PATCH 2/2] doc: correct misleading descriptions for --shallow-exclude

From: Elijah Newren <newren@gmail.com>

The documentation for the --shallow-exclude option to clone/fetch/etc. claims that the option takes a revision, but it does not. As per upload-pack.c's process_deepen_not(), it passes the option to expand_ref() and dies if it does not find exactly one ref matching the name passed. Further, this has always been the case ever since these options were introduced by the commits merged in a460ea4a3cb1 (Merge branch 'nd/shallow-deepen', 2016-10-10). Fix the documentation to match the implementation.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/fetch-options.txt  | 2 +-
 Documentation/git-clone.txt      | 2 +-
 Documentation/git-fetch-pack.txt | 2 +-
 builtin/clone.c                  | 2 +-
 builtin/fetch.c                  | 4 ++--
 builtin/pull.c                   | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)
Show changes to 6 files +8 −6

Documentation/fetch-options.txt, Documentation/git-clone.txt, Documentation/git-fetch-pack.txt, builtin/clone.c, builtin/fetch.c, builtin/pull.c

diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 9dc7ac8dbdc..b01372e4b3c 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -29,7 +29,7 @@
 	Deepen or shorten the history of a shallow repository to
 	include all reachable commits after <date>.
 
---shallow-exclude=<revision>::
+--shallow-exclude=<ref>::
 	Deepen or shorten the history of a shallow repository to
 	exclude commits reachable from a specified remote branch or tag.
 	This option can be specified multiple times.
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 116ad648201..7acb4cb1761 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -255,7 +255,7 @@ corresponding `--mirror` and `--no-tags` options instead.
 `--shallow-since=<date>`::
 	Create a shallow clone with a history after the specified time.
 
-`--shallow-exclude=<revision>`::
+`--shallow-exclude=<ref>`::
 	Create a shallow clone with a history, excluding commits
 	reachable from a specified remote branch or tag.  This option
 	can be specified multiple times.
diff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt
index b3467664d30..b5223576a75 100644
--- a/Documentation/git-fetch-pack.txt
+++ b/Documentation/git-fetch-pack.txt
@@ -91,7 +91,7 @@ be in a separate packet, and the list must end with a flush packet.
 	Deepen or shorten the history of a shallow repository to
 	include all reachable commits after <date>.
 
---shallow-exclude=<revision>::
+--shallow-exclude=<ref>::
 	Deepen or shorten the history of a shallow repository to
 	exclude commits reachable from a specified remote branch or tag.
 	This option can be specified multiple times.
diff --git a/builtin/clone.c b/builtin/clone.c
index 59fcb317a68..93fe6d69659 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -147,7 +147,7 @@ static struct option builtin_clone_options[] = {
 		    N_("create a shallow clone of that depth")),
 	OPT_STRING(0, "shallow-since", &option_since, N_("time"),
 		    N_("create a shallow clone since a specific time")),
-	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
+	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("ref"),
 			N_("deepen history of shallow clone, excluding rev")),
 	OPT_BOOL(0, "single-branch", &option_single_branch,
 		    N_("clone only one branch, HEAD or --branch")),
diff --git a/builtin/fetch.c b/builtin/fetch.c
index d9027e4dc92..18eff4e5fa1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2216,8 +2216,8 @@ int cmd_fetch(int argc,
 			   N_("deepen history of shallow clone")),
 		OPT_STRING(0, "shallow-since", &deepen_since, N_("time"),
 			   N_("deepen history of shallow repository based on time")),
-		OPT_STRING_LIST(0, "shallow-exclude", &deepen_not, N_("revision"),
-				N_("deepen history of shallow clone, excluding rev")),
+		OPT_STRING_LIST(0, "shallow-exclude", &deepen_not, N_("ref"),
+				N_("deepen history of shallow clone, excluding ref")),
 		OPT_INTEGER(0, "deepen", &deepen_relative,
 			    N_("deepen history of shallow clone")),
 		OPT_SET_INT_F(0, "unshallow", &unshallow,
diff --git a/builtin/pull.c b/builtin/pull.c
index 388ef3d1306..edc56907aa2 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -218,8 +218,8 @@ static struct option pull_options[] = {
 	OPT_PASSTHRU_ARGV(0, "shallow-since", &opt_fetch, N_("time"),
 		N_("deepen history of shallow repository based on time"),
 		0),
-	OPT_PASSTHRU_ARGV(0, "shallow-exclude", &opt_fetch, N_("revision"),
-		N_("deepen history of shallow clone, excluding rev"),
+	OPT_PASSTHRU_ARGV(0, "shallow-exclude", &opt_fetch, N_("ref"),
+		N_("deepen history of shallow clone, excluding ref"),
 		0),
 	OPT_PASSTHRU_ARGV(0, "deepen", &opt_fetch, N_("n"),
 		N_("deepen history of shallow clone"),
-- 
gitgitgadget
Patrick Steinhardt· Nov 5, 2024, 06:27 UTC · re: Elijah Newren via GitGitGadget · lore

Re: [PATCH 2/2] doc: correct misleading descriptions for --shallow-exclude

On Mon, Nov 04, 2024 at 07:02:44PM +0000, Elijah Newren via GitGitGadget wrote:
Show 11 quoted lines
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 59fcb317a68..93fe6d69659 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -147,7 +147,7 @@ static struct option builtin_clone_options[] = {
>  		    N_("create a shallow clone of that depth")),
>  	OPT_STRING(0, "shallow-since", &option_since, N_("time"),
>  		    N_("create a shallow clone since a specific time")),
> -	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
> +	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("ref"),
>  			N_("deepen history of shallow clone, excluding rev")),

We also need to replace "rev" with "ref" here. We already do that in the other cases.

Patrick
Junio C Hamano· Nov 5, 2024, 06:55 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 2/2] doc: correct misleading descriptions for --shallow-exclude

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> On Mon, Nov 04, 2024 at 07:02:44PM +0000, Elijah Newren via GitGitGadget wrote:
>> diff --git a/builtin/clone.c b/builtin/clone.c
>> index 59fcb317a68..93fe6d69659 100644
>> --- a/builtin/clone.c
>> +++ b/builtin/clone.c
>> @@ -147,7 +147,7 @@ static struct option builtin_clone_options[] = {
>>  		    N_("create a shallow clone of that depth")),
>>  	OPT_STRING(0, "shallow-since", &option_since, N_("time"),
>>  		    N_("create a shallow clone since a specific time")),
>> -	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
>> +	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("ref"),
>>  			N_("deepen history of shallow clone, excluding rev")),
>
> We also need to replace "rev" with "ref" here. We already do that in the
> other cases.

Ah, I missed that one. Let me locally amend, as there does not seem to be any other issues.

Junio C Hamano· Nov 5, 2024, 01:27 UTC · re: Elijah Newren via GitGitGadget · lore

Re: [PATCH 0/2] A few --shallow-exclude fixes

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> Here's a couple patches to fix up an error message and the documentation
> around the --shallow-exclude option.
>
> Elijah Newren (2):
>   upload-pack: fix ambiguous error message
>   doc: correct misleading descriptions for --shallow-exclude
Both patches look sensible.
Will queue.  Thanks.

← back to recent threads