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

[PATCH 1/2] git-fetch--tool pick-rref

From
Junio C Hamano <junkio@cox.net>
Date
Apr 5, 2007, 10:22 UTC
Message-ID
<7v7isrrugx.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0704031427050.6730@woody.linux-foundation.org>

This script helper takes list of fully qualified refnames and results from ls-remote and grabs only the lines for the named refs from the latter.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
  Linus Torvalds <torvalds@linux-foundation.org> writes:
  > On Tue, 3 Apr 2007, Linus Torvalds wrote:
  >> 
  >> Yes, we could definitely skip the re-lookup if we had a "don't really 
  >> care, I can recreate the object myself" flag (ie anybody who is going to 
  >> write that object)
  >
  > Side note: with "alternates" files, you might well *always* have the 
  > objects. If you do
  >
  > 	git clone -l -s ...
  >
  > to create various branches, and then pull between them, you'll actually 
  > end up in the situation that you'll always find the objects and get back 
  > to the really expensive case..
  Ah, that's true.  If you "git clone -l -s A B", create new
  objects in A and pull from B, the transfer would not exclude
  new objects as they are not visible from B's refs.
  In that scenario, the keep-pack behaviour is already worse than
  the unpack-objects behaviour.  The former creates a packfile
  that duplicates objects that are in A while the latter, although
  expensive, ends up doing nothing.
  I wonder if we can have a backdoor to avoid any object transfer
  in such a case to begin with...
  ... and this two patch series does exactly that.
 builtin-fetch--tool.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index e9d6764..be341c1 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -436,10 +436,87 @@ static int expand_refs_wildcard(const char *ls_remote_result, int numrefs,
 	return 0;
 }
 
+static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_result)
+{
+	int err = 0;
+	int lrr_count = lrr_count, i, pass;
+	const char *cp;
+	struct lrr {
+		const char *line;
+		const char *name;
+		int namelen;
+		int shown;
+	} *lrr_list = lrr_list;
+
+	for (pass = 0; pass < 2; pass++) {
+		/* pass 0 counts and allocates, pass 1 fills... */
+		cp = ls_remote_result;
+		i = 0;
+		while (1) {
+			const char *np;
+			while (*cp && isspace(*cp))
+				cp++;
+			if (!*cp)
+				break;
+			np = strchr(cp, '\n');
+			if (!np)
+				np = cp + strlen(cp);
+			if (pass) {
+				lrr_list[i].line = cp;
+				lrr_list[i].name = cp + 41;
+				lrr_list[i].namelen = np - (cp + 41);
+			}
+			i++;
+			cp = np;
+		}
+		if (!pass) {
+			lrr_count = i;
+			lrr_list = xcalloc(lrr_count, sizeof(*lrr_list));
+		}
+	}
+
+	while (1) {
+		const char *next;
+		int rreflen;
+		int i;
+
+		while (*rref && isspace(*rref))
+			rref++;
+		if (!*rref)
+			break;
+		next = strchr(rref, '\n');
+		if (!next)
+			next = rref + strlen(rref);
+		rreflen = next - rref;
+
+		for (i = 0; i < lrr_count; i++) {
+			struct lrr *lrr = &(lrr_list[i]);
+
+			if (rreflen == lrr->namelen &&
+			    !memcmp(lrr->name, rref, rreflen)) {
+				if (!lrr->shown)
+					printf("%.*s\n",
+					       sha1_only ? 40 : lrr->namelen + 41,
+					       lrr->line);
+				lrr->shown = 1;
+				break;
+			}
+		}
+		if (lrr_count <= i) {
+			error("pick-rref: %.*s not found", rreflen, rref);
+			err = 1;
+		}
+		rref = next;
+	}
+	free(lrr_list);
+	return err;
+}
+
 int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
 {
 	int verbose = 0;
 	int force = 0;
+	int sopt = 0;
 
 	while (1 < argc) {
 		const char *arg = argv[1];
@@ -447,6 +524,8 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
 			verbose = 1;
 		else if (!strcmp("-f", arg))
 			force = 1;
+		else if (!strcmp("-s", arg))
+			sopt = 1;
 		else
 			break;
 		argc--;
@@ -491,6 +570,11 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
 			reflist = get_stdin();
 		return parse_reflist(reflist);
 	}
+	if (!strcmp("pick-rref", argv[1])) {
+		if (argc != 4)
+			return error("pick-rref takes 2 args");
+		return pick_rref(sopt, argv[2], argv[3]);
+	}
 	if (!strcmp("expand-refs-wildcard", argv[1])) {
 		const char *reflist;
 		if (argc < 4)
-- 
1.5.1.45.g1ddb
Previous: Junio C HamanoNext: Junio C Hamano
Message 24 of 58 in “git-index-pack really does suck..”
  1. Linus TorvaldsApr 3, 2007
  2. Linus TorvaldsApr 3, 2007
  3. Nicolas PitreApr 3, 2007
  4. Nicolas PitreApr 3, 2007
  5. Chris LeeApr 3, 2007
  6. Nicolas PitreApr 3, 2007
  7. Chris LeeApr 3, 2007
  8. Linus TorvaldsApr 3, 2007
  9. Nicolas PitreApr 3, 2007
  10. Junio C HamanoApr 3, 2007
  11. Linus TorvaldsApr 3, 2007
  12. Nicolas PitreApr 3, 2007
  13. Chris LeeApr 3, 2007
  14. Linus TorvaldsApr 3, 2007
  15. Linus TorvaldsApr 3, 2007
  16. Shawn O. PearceApr 3, 2007
  17. Linus TorvaldsApr 3, 2007
  18. Shawn O. PearceApr 3, 2007
  19. Linus TorvaldsApr 3, 2007
  20. Linus TorvaldsApr 3, 2007
  21. Junio C HamanoApr 3, 2007
  22. Shawn O. PearceApr 3, 2007
  23. Junio C HamanoApr 3, 2007
  24. 1/2 git-fetch--tool pick-rrefJunio C Hamano, Apr 5, 2007
  25. 2/2 git-fetch: use fetch--tool pick-rref to avoid local fetch from alternateJunio C Hamano, Apr 5, 2007
  26. Shawn O. PearceApr 5, 2007
  27. Junio C HamanoApr 5, 2007
  28. Nicolas PitreApr 3, 2007
  29. Shawn O. PearceApr 3, 2007
  30. Junio C HamanoApr 3, 2007
  31. Shawn O. PearceApr 3, 2007
  32. Jeff KingApr 3, 2007
  33. Dana HowApr 3, 2007
  34. Linus TorvaldsApr 3, 2007
  35. David LangApr 3, 2007
  36. Nicolas PitreApr 3, 2007
  37. Nicolas PitreApr 3, 2007
  38. Linus TorvaldsApr 3, 2007
  39. Nicolas PitreApr 3, 2007
  40. Shawn O. PearceApr 3, 2007
  41. Linus TorvaldsApr 3, 2007
  42. Nicolas PitreApr 3, 2007
  43. Junio C HamanoApr 3, 2007
  44. Shawn O. PearceApr 3, 2007
  45. Nicolas PitreApr 3, 2007
  46. Linus TorvaldsApr 3, 2007
  47. Nicolas PitreApr 3, 2007
  48. David LangApr 3, 2007
  49. Alex RiesenApr 4, 2007
  50. David LangApr 6, 2007
  51. Junio C HamanoApr 6, 2007
  52. Junio C HamanoApr 6, 2007
  53. David LangApr 6, 2007
  54. Junio C HamanoApr 6, 2007
  55. David LangApr 6, 2007
  56. Linus TorvaldsApr 3, 2007
  57. Junio C HamanoApr 3, 2007
  58. Nicolas PitreApr 3, 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.