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

Re: [PATCH v2 00/21] object_id part 7

From
Jeff King <peff@peff.net>
Date
Mar 28, 2017, 17:35 UTC
Message-ID
<20170328173536.ylwesrj7jbreztcy@sigill.intra.peff.net>
In-Reply-To
<20170328111315.i6rhhy4pj6hhf4bs@genre.crustytoothpaste.net>
On Tue, Mar 28, 2017 at 11:13:15AM +0000, brian m. carlson wrote:
Show 12 quoted lines
> > I suggested an additional cleanup around "linelen" in one patch. In the
> > name of keeping the number of re-rolls sane, I'm OK if we skip that for
> > now (the only reason I mentioned it at all is that you have to justify
> > the caveat in the commit message; with the fix, that justification can
> > go away).
> 
> Let's leave it as it is, assuming Junio's okay with it.  I can send in a
> few more patches to clean that up and use skip_prefix that we can drop
> on top and graduate separately.
> 
> I think the justification is useful as it is, since it explains why we
> no longer want to check that particular value for historical reasons.

I thought I'd knock this out quickly before I forgot about it. But it actually isn't so simple.

The main caller in read_head_info() does indeed just pass strlen(line) as the length in each case. But the cert parser really does need us to respect the line length. So we either have to pass it in, or tie off the string.

The latter looks something like the patch below (on top of a minor tweak around "eol" handling). It's sufficiently ugly that it may not count as an actual cleanup, though. I'm OK if we just drop the idea.

---
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 58de2a1a9..561a982e7 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1483,13 +1483,10 @@ static void execute_commands(struct command *commands,
 }
 
 static struct command **queue_command(struct command **tail,
-				      const char *line,
-				      int linelen)
+				      const char *line)
 {
 	struct object_id old_oid, new_oid;
 	struct command *cmd;
-	const char *refname;
-	int reflen;
 	const char *p;
 
 	if (parse_oid_hex(line, &old_oid, &p) ||
@@ -1498,9 +1495,7 @@ static struct command **queue_command(struct command **tail,
 	    *p++ != ' ')
 		die("protocol error: expected old/new/ref, got '%s'", line);
 
-	refname = p;
-	reflen = linelen - (p - line);
-	FLEX_ALLOC_MEM(cmd, ref_name, refname, reflen);
+	FLEX_ALLOC_STR(cmd, ref_name, p);
 	oidcpy(&cmd->old_oid, &old_oid);
 	oidcpy(&cmd->new_oid, &new_oid);
 	*tail = cmd;
@@ -1510,7 +1505,7 @@ static struct command **queue_command(struct command **tail,
 static void queue_commands_from_cert(struct command **tail,
 				     struct strbuf *push_cert)
 {
-	const char *boc, *eoc;
+	char *boc, *eoc;
 
 	if (*tail)
 		die("protocol error: got both push certificate and unsigned commands");
@@ -1523,10 +1518,17 @@ static void queue_commands_from_cert(struct command **tail,
 	eoc = push_cert->buf + parse_signature(push_cert->buf, push_cert->len);
 
 	while (boc < eoc) {
-		const char *eol = memchr(boc, '\n', eoc - boc);
+		char *eol = memchr(boc, '\n', eoc - boc);
+		char tmp;
+
 		if (!eol)
 			eol = eoc;
-		tail = queue_command(tail, boc, eol - boc);
+
+		tmp = *eol;
+		*eol = '\0';
+		tail = queue_command(tail, boc);
+		*eol = tmp;
+
 		boc = eol + 1;
 	}
 }
@@ -1590,7 +1592,7 @@ static struct command *read_head_info(struct oid_array *shallow)
 			continue;
 		}
 
-		p = queue_command(p, line, linelen);
+		p = queue_command(p, line);
 	}
 
 	if (push_cert.len)
Previous: brian m. carlsonNext: Jeff King
Message 36 of 40 in “object_id part 7”
  1. 00/21 object_id part 7brian m. carlson, Mar 26, 2017
  2. 08/21 fsck: convert init_skiplist to struct object_idbrian m. carlson, Mar 26, 2017
  3. 12/21 sha1_name: convert disambiguate_hint_fn to take object_idbrian m. carlson, Mar 26, 2017
  4. 16/21 Make sha1_array_append take a struct object_id *brian m. carlson, Mar 26, 2017
  5. Jeff KingMar 28, 2017
  6. Junio C HamanoMar 28, 2017
  7. brian m. carlsonMar 29, 2017
  8. Junio C HamanoMar 29, 2017
  9. brian m. carlsonMar 29, 2017
  10. 09/21 parse-options-cb: convert sha1_array_append caller to struct object_idbrian m. carlson, Mar 26, 2017
  11. 18/21 Convert sha1_array_lookup to take struct object_idbrian m. carlson, Mar 26, 2017
  12. 17/21 Convert remaining callers of sha1_array_lookup to object_idbrian m. carlson, Mar 26, 2017
  13. 10/21 test-sha1-array: convert most code to struct object_idbrian m. carlson, Mar 26, 2017
  14. 21/21 Documentation: update and rename api-sha1-array.txtbrian m. carlson, Mar 26, 2017
  15. 07/21 builtin/receive-pack: convert portions to struct object_idbrian m. carlson, Mar 26, 2017
  16. Jeff KingMar 28, 2017
  17. brian m. carlsonMar 29, 2017
  18. Jeff KingMar 30, 2017
  19. 20/21 Rename sha1_array to oid_arraybrian m. carlson, Mar 26, 2017
  20. 05/21 builtin/pull: convert portions to struct object_idbrian m. carlson, Mar 26, 2017
  21. 19/21 Convert sha1_array_for_each_unique and for_each_abbrev to object_idbrian m. carlson, Mar 26, 2017
  22. 06/21 builtin/receive-pack: fix incorrect pointer arithmeticbrian m. carlson, Mar 26, 2017
  23. Jeff KingMar 28, 2017
  24. Junio C HamanoMar 28, 2017
  25. 14/21 builtin/pull: convert to struct object_idbrian m. carlson, Mar 26, 2017
  26. 01/21 Define new hash-size constants for allocating memorybrian m. carlson, Mar 26, 2017
  27. 03/21 Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZbrian m. carlson, Mar 26, 2017
  28. 11/21 sha1_name: convert struct disambiguate_state to object_idbrian m. carlson, Mar 26, 2017
  29. 15/21 sha1-array: convert internal storage for struct sha1_array to object_idbrian m. carlson, Mar 26, 2017
  30. Jeff KingMar 28, 2017
  31. 13/21 submodule: convert check_for_new_submodule_commits to object_idbrian m. carlson, Mar 26, 2017
  32. 02/21 Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZbrian m. carlson, Mar 26, 2017
  33. 04/21 builtin/diff: convert to struct object_idbrian m. carlson, Mar 26, 2017
  34. Jeff KingMar 28, 2017
  35. brian m. carlsonMar 28, 2017
  36. Jeff KingMar 28, 2017
  37. Jeff KingMar 28, 2017
  38. Junio C HamanoMar 28, 2017
  39. Jeff KingMar 28, 2017
  40. Junio C HamanoMar 28, 2017

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.