git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Restore ls-remote reference pattern matching

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Dec 9, 2007, 05:16 UTC
Message-ID
<Pine.LNX.4.64.0712082346310.5349@iabervon.org>
In-Reply-To
<7vodd0tuuu.fsf@gitster.siamese.dyndns.org>
On Sat, 8 Dec 2007, Junio C Hamano wrote:
Show 22 quoted lines
> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> > How's this? I vaguely tested it, and it doesn't break existing tests, and 
> > it matches my guess at how the old code worked, at least maybe.
> 
> Well, contrib/examples/git-ls-remote.sh is your friend and you do not
> have to "guess".
> 
> It did, for each ref $path it got from peek-remote, this:
> 
> 		for pat
> 		do
> 			case "/$path" in
> 			*/$pat )
> 				match=yes
> 				break ;;
> 			esac
> 		done
> 
> I do not think pathspec_match() matches the string in a way compatible
> with the above loop, and calling get_pathspec(prefix, argv) with
> anything but a real path is a misuse of the interface.

I'd found the same code ("git log -p -- git-ls-remote.sh" also reveals it, and I couldn't remember it's contrib/examples that things end up in), but I don't really follow that shell syntax.

> I think if you do fnmatch(3) that would be compatible with the shell
> loop.

Maybe: --- cut here --- I entirely missed that "git ls-remote <repo> <ref-pattern>..." is supposed to work. This restores it.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
This matches git-name-rev --refs=<ref-pattern>, anyway, which is the 
closest example I could find. If this isn't the desired behavior, it's 
probably easier to just edit this instead of trying to explain the right 
thing to me.
 builtin-ls-remote.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/builtin-ls-remote.c b/builtin-ls-remote.c
index 56f3f88..d936c28 100644
--- a/builtin-ls-remote.c
+++ b/builtin-ls-remote.c
@@ -17,6 +17,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	const char **refpatterns = NULL;
 
 	setup_git_directory_gently(&nongit);
 
@@ -50,9 +51,12 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		break;
 	}
 
-	if (!dest || i != argc - 1)
+	if (!dest)
 		usage(ls_remote_usage);
 
+	if (argc > i + 1)
+		refpatterns = argv + i;
+
 	remote = nongit ? NULL : remote_get(dest);
 	if (remote && !remote->url_nr)
 		die("remote %s has no configured URL", dest);
@@ -66,8 +70,18 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		return 1;
 
 	while (ref) {
-		if (check_ref_type(ref, flags))
-			printf("%s	%s\n", sha1_to_hex(ref->old_sha1), ref->name);
+		if (check_ref_type(ref, flags)) {
+			int match = 0;
+			if (refpatterns) {
+				for (i = 0; refpatterns[i]; i++) {
+					if (!fnmatch(refpatterns[i], ref->name, 0))
+						match = 1;
+				}
+			} else
+				match = 1;
+			if (match)
+				printf("%s	%s\n", sha1_to_hex(ref->old_sha1), ref->name);
+		}
 		ref = ref->next;
 	}
 	return 0;
-- 
1.5.3.6.886.gb204
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 10 in “Restore ls-remote reference pattern matching”
  1. Restore ls-remote reference pattern matchingDaniel Barkalow, Dec 9, 2007
  2. Junio C HamanoDec 9, 2007
  3. Daniel BarkalowDec 9, 2007
  4. Junio C HamanoDec 9, 2007
  5. Sergey VlasovDec 9, 2007
  6. Eyvind BernhardsenDec 9, 2007
  7. Junio C HamanoDec 9, 2007
  8. Junio C HamanoDec 9, 2007
  9. Eyvind BernhardsenDec 10, 2007
  10. Junio C HamanoDec 10, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.