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

[PATCH 00/27] nd/shallow-deepen updates

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 10, 2016, 12:26 UTC
Message-ID
<20160610122714.3341-1-pclouds@gmail.com>

This contains cleanups after Eric's comments (all good points, thanks!). Changed patches have Junio's s-o-b line removed, so it's easy to see which is changed and which is not. 09/27 is a new one, split out of 10/27.

Interdiff
diff --git a/builtin/clone.c b/builtin/clone.c
index 5ccf6b7..3849231 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -53,13 +53,6 @@ static struct string_list option_config;
 static struct string_list option_reference;
 static int option_dissociate;
 
-static int option_parse_deepen_not(const struct option *opt,
-				   const char *arg, int unset)
-{
-	string_list_append(&option_not, arg);
-	return 0;
-}
-
 static struct option builtin_clone_options[] = {
 	OPT__VERBOSITY(&option_verbosity),
 	OPT_BOOL(0, "progress", &option_progress,
@@ -97,9 +90,8 @@ 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")),
-	{ OPTION_CALLBACK, 0, "shallow-exclude", NULL, N_("revision"),
-		    N_("deepen history of shallow clone by excluding rev"),
-		    PARSE_OPT_NONEG, option_parse_deepen_not },
+	OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
+			N_("deepen history of shallow clone by excluding rev")),
 	OPT_BOOL(0, "single-branch", &option_single_branch,
 		    N_("clone only one branch, HEAD or --branch")),
 	OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 68b44ba..7b0ea1c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -51,13 +51,6 @@ static int shown_url = 0;
 static int refmap_alloc, refmap_nr;
 static const char **refmap_array;
 
-static int option_parse_deepen_not(const struct option *opt,
-				   const char *arg, int unset)
-{
-	string_list_append(&deepen_not, arg);
-	return 0;
-}
-
 static int option_parse_recurse_submodules(const struct option *opt,
 				   const char *arg, int unset)
 {
@@ -126,9 +119,8 @@ static struct option builtin_fetch_options[] = {
 		   N_("deepen history of shallow clone")),
 	OPT_STRING(0, "shallow-since", &deepen_since, N_("time"),
 		   N_("deepen history of shallow repository based on time")),
-	{ OPTION_CALLBACK, 0, "shallow-exclude", NULL, N_("revision"),
-		    N_("deepen history of shallow clone by excluding rev"),
-		    PARSE_OPT_NONEG, option_parse_deepen_not },
+	OPT_STRING_LIST(0, "shallow-exclude", &deepen_not, N_("revision"),
+			N_("deepen history of shallow clone by excluding rev")),
 	OPT_INTEGER(0, "deepen", &deepen_relative,
 		    N_("deepen history of shallow clone")),
 	{ OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
diff --git a/remote-curl.c b/remote-curl.c
index 3f1a8f5..d56412d 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -745,7 +745,6 @@ static int fetch_git(struct discovery *heads,
 {
 	struct rpc_state rpc;
 	struct strbuf preamble = STRBUF_INIT;
-	char *depth_arg = NULL;
 	int i, err;
 	struct argv_array args = ARGV_ARRAY_INIT;
 
@@ -755,10 +754,8 @@ static int fetch_git(struct discovery *heads,
 		argv_array_push(&args, "--include-tag");
 	if (options.thin)
 		argv_array_push(&args, "--thin");
-	if (options.verbosity >= 3) {
-		argv_array_push(&args, "-v");
-		argv_array_push(&args, "-v");
-	}
+	if (options.verbosity >= 3)
+		argv_array_pushl(&args, "-v", "-v", NULL);
 	if (options.check_self_contained_and_connected)
 		argv_array_push(&args, "--check-self-contained-and-connected");
 	if (options.cloning)
@@ -798,7 +795,6 @@ static int fetch_git(struct discovery *heads,
 		write_or_die(1, rpc.result.buf, rpc.result.len);
 	strbuf_release(&rpc.result);
 	strbuf_release(&preamble);
-	free(depth_arg);
 	argv_array_clear(&args);
 	return err;
 }
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index f512098..a908036 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -678,8 +678,7 @@ test_expect_success 'shallow clone exclude tag two' '
 test_expect_success 'fetch exclude tag one' '
 	git -C shallow12 fetch --shallow-exclude one origin &&
 	git -C shallow12 log --pretty=tformat:%s origin/master >actual &&
-	echo three >expected &&
-	echo two  >>expected &&
+	test_write_lines three two >expected &&
 	test_cmp expected actual
 '
 
diff --git a/t/t5539-fetch-http-shallow.sh b/t/t5539-fetch-http-shallow.sh
index 25f8968..5fbf67c 100755
--- a/t/t5539-fetch-http-shallow.sh
+++ b/t/t5539-fetch-http-shallow.sh
@@ -116,8 +116,7 @@ test_expect_success 'shallow clone exclude tag two' '
 test_expect_success 'fetch exclude tag one' '
 	git -C shallow12 fetch --shallow-exclude one origin &&
 	git -C shallow12 log --pretty=tformat:%s origin/master >actual &&
-	echo three >expected &&
-	echo two  >>expected &&
+	test_write_lines three two >expected &&
 	test_cmp expected actual
 '
 
diff --git a/transport-helper.c b/transport-helper.c
index b894b60..a5cdd77 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -272,9 +272,9 @@ static int strbuf_set_helper_option(struct helper_data *data,
 
 	if (!strcmp(buf->buf, "ok"))
 		ret = 0;
-	else if (starts_with(buf->buf, "error")) {
+	else if (starts_with(buf->buf, "error"))
 		ret = -1;
-	} else if (!strcmp(buf->buf, "unsupported"))
+	else if (!strcmp(buf->buf, "unsupported"))
 		ret = 1;
 	else {
 		warning("%s unexpectedly said: '%s'", data->name, buf->buf);
diff --git a/upload-pack.c b/upload-pack.c
index 18b914a..ef693bd 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -471,7 +471,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 	cmd->out = -1;
 
 	if (start_command(cmd))
-		return -1;
+		goto error;
 
 	/*
 	 * If rev-list --stdin encounters an unknown commit, it
@@ -491,8 +491,10 @@ static int do_reachable_revlist(struct child_process *cmd,
 		if (!is_our_ref(o))
 			continue;
 		memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
-		if (write_in_full(cmd->in, namebuf, 42) < 0)
-			return -1;
+		if (write_in_full(cmd->in, namebuf, 42) < 0) {
+			sigchain_pop(SIGPIPE);
+			goto error;
+		}
 	}
 	namebuf[40] = '\n';
 	for (i = 0; i < src->nr; i++) {
@@ -505,13 +507,23 @@ static int do_reachable_revlist(struct child_process *cmd,
 		if (reachable && o->type == OBJ_COMMIT)
 			o->flags |= TMP_MARK;
 		memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
-		if (write_in_full(cmd->in, namebuf, 41) < 0)
-			return -1;
+		if (write_in_full(cmd->in, namebuf, 41) < 0) {
+			sigchain_pop(SIGPIPE);
+			goto error;
+		}
 	}
 	close(cmd->in);
+	cmd->in = -1;
 
 	sigchain_pop(SIGPIPE);
 	return 0;
+
+error:
+	if (cmd->in >= 0)
+		close(cmd->in);
+	if (cmd->out >= 0)
+		close(cmd->out);
+	return -1;
 }
 
 static int get_reachable_list(struct object_array *src,
@@ -555,10 +567,10 @@ static int get_reachable_list(struct object_array *src,
 static int check_unreachable(struct object_array *src)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
-	int i, ret = do_reachable_revlist(&cmd, src, NULL);
 	char buf[1];
+	int i;
 
-	if (ret < 0)
+	if (do_reachable_revlist(&cmd, src, NULL) < 0)
 		return 0;
 
 	/*
@@ -567,8 +579,9 @@ static int check_unreachable(struct object_array *src)
 	 */
 	i = read_in_full(cmd.out, buf, 1);
 	if (i)
-		return 0;
+		goto error;
 	close(cmd.out);
+	cmd.out = -1;
 
 	/*
 	 * rev-list may have died by encountering a bad commit
@@ -576,10 +589,17 @@ static int check_unreachable(struct object_array *src)
 	 * even when it showed no commit.
 	 */
 	if (finish_command(&cmd))
-		return 0;
+		goto error;
 
 	/* All the non-tip ones are ancestors of what we advertised */
 	return 1;
+
+error:
+	if (cmd.in >= 0)
+		close(cmd.in);
+	if (cmd.out >= 0)
+		close(cmd.out);
+	return 0;
 }
 
 static void check_non_tip(void)
@@ -592,10 +612,12 @@ static void check_non_tip(void)
 	 * non-tip requests can never happen.
 	 */
 	if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
-		;		/* error */
-	else if (check_unreachable(&want_obj))
+		goto error;
+	if (check_unreachable(&want_obj))
+		/* All the non-tip ones are ancestors of what we advertised */
 		return;
 
+error:
 	/* Pick one of them (we know there at least is one) */
 	for (i = 0; i < want_obj.nr; i++) {
 		struct object *o = want_obj.objects[i].item;
@@ -993,7 +1015,7 @@ int main(int argc, char **argv)
 	check_replace_refs = 0;
 
 	for (i = 1; i < argc; i++) {
-		char *arg = argv[i];
+		const char *arg = argv[i];
 
 		if (arg[0] != '-')
 			break;
@@ -1009,8 +1031,8 @@ int main(int argc, char **argv)
 			strict = 1;
 			continue;
 		}
-		if (starts_with(arg, "--timeout=")) {
-			timeout = atoi(arg+10);
+		if (skip_prefix(arg, "--timeout=", &arg)) {
+			timeout = atoi(arg);
 			daemon_mode = 1;
 			continue;
 		}
-- 
2.8.2.524.g6ff3d78
Next: Nguyễn Thái Ngọc Duy
Message 1 of 64 in “nd/shallow-deepen updates”
  1. 00/27 nd/shallow-deepen updatesNguyễn Thái Ngọc Duy, Jun 10, 2016
  2. 08/27 upload-pack: tighten number parsing at "deepen" linesNguyễn Thái Ngọc Duy, Jun 10, 2016
  3. 09/27 upload-pack: make check_non_tip() clean things up errorNguyễn Thái Ngọc Duy, Jun 10, 2016
  4. Junio C HamanoJun 10, 2016
  5. 05/27 upload-pack: remove unused variable "backup"Nguyễn Thái Ngọc Duy, Jun 10, 2016
  6. Junio C HamanoJun 10, 2016
  7. 12/27 fetch-pack: use a common function for verbose printingNguyễn Thái Ngọc Duy, Jun 10, 2016
  8. 04/27 upload-pack: move "shallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  9. Junio C HamanoJun 10, 2016
  10. 11/27 fetch-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  11. 06/27 upload-pack: move "unshallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  12. Junio C HamanoJun 10, 2016
  13. 03/27 upload-pack: move shallow deepen code out of receive_needs()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  14. 02/27 transport-helper.c: refactor set_helper_option()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  15. 01/27 remote-curl.c: convert fetch_git() to use argv_arrayNguyễn Thái Ngọc Duy, Jun 10, 2016
  16. 07/27 upload-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  17. 10/27 upload-pack: move rev-list code out of check_non_tip()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  18. Junio C HamanoJun 10, 2016
  19. 25/27 upload-pack: split check_unreachable() in two, prep for get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  20. 16/27 upload-pack: add deepen-since to cut shallow repos based on timeNguyễn Thái Ngọc Duy, Jun 10, 2016
  21. 17/27 fetch: define shallow boundary with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 10, 2016
  22. 18/27 clone: define shallow clone boundary based on time with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 10, 2016
  23. 24/27 t5500, t5539: tests for shallow depth excluding a refNguyễn Thái Ngọc Duy, Jun 10, 2016
  24. 23/27 clone: define shallow clone boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 10, 2016
  25. 21/27 upload-pack: support define shallow boundary by excluding revisionsNguyễn Thái Ngọc Duy, Jun 10, 2016
  26. 26/27 upload-pack: add get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  27. 27/27 fetch, upload-pack: --deepen=N extends shallow boundary by N commitsNguyễn Thái Ngọc Duy, Jun 10, 2016
  28. 22/27 fetch: define shallow boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 10, 2016
  29. 14/27 fetch-pack: use a separate flag for fetch in deepening modeNguyễn Thái Ngọc Duy, Jun 10, 2016
  30. 20/27 refs: add expand_ref()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  31. 19/27 t5500, t5539: tests for shallow depth since a specific dateNguyễn Thái Ngọc Duy, Jun 10, 2016
  32. 15/27 shallow.c: implement a generic shallow boundary finder based on rev-listNguyễn Thái Ngọc Duy, Jun 10, 2016
  33. 13/27 fetch-pack.c: mark strings for translatingNguyễn Thái Ngọc Duy, Jun 10, 2016
  34. Eric SunshineJun 10, 2016
  35. Junio C HamanoJun 13, 2016
  36. Duy NguyenJun 14, 2016
  37. 00/27 nd/shallow-deepen updatesNguyễn Thái Ngọc Duy, Jun 12, 2016
  38. 01/27 remote-curl.c: convert fetch_git() to use argv_arrayNguyễn Thái Ngọc Duy, Jun 12, 2016
  39. 02/27 transport-helper.c: refactor set_helper_option()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  40. 03/27 upload-pack: move shallow deepen code out of receive_needs()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  41. 05/27 upload-pack: remove unused variable "backup"Nguyễn Thái Ngọc Duy, Jun 12, 2016
  42. 04/27 upload-pack: move "shallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  43. 06/27 upload-pack: move "unshallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  44. 07/27 upload-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  45. 08/27 upload-pack: tighten number parsing at "deepen" linesNguyễn Thái Ngọc Duy, Jun 12, 2016
  46. 09/27 upload-pack: make check_non_tip() clean things up on errorNguyễn Thái Ngọc Duy, Jun 12, 2016
  47. 11/27 fetch-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  48. 10/27 upload-pack: move rev-list code out of check_non_tip()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  49. 12/27 fetch-pack: use a common function for verbose printingNguyễn Thái Ngọc Duy, Jun 12, 2016
  50. 13/27 fetch-pack.c: mark strings for translatingNguyễn Thái Ngọc Duy, Jun 12, 2016
  51. 14/27 fetch-pack: use a separate flag for fetch in deepening modeNguyễn Thái Ngọc Duy, Jun 12, 2016
  52. 15/27 shallow.c: implement a generic shallow boundary finder based on rev-listNguyễn Thái Ngọc Duy, Jun 12, 2016
  53. 16/27 upload-pack: add deepen-since to cut shallow repos based on timeNguyễn Thái Ngọc Duy, Jun 12, 2016
  54. 17/27 fetch: define shallow boundary with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 12, 2016
  55. 18/27 clone: define shallow clone boundary based on time with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 12, 2016
  56. 20/27 refs: add expand_ref()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  57. 19/27 t5500, t5539: tests for shallow depth since a specific dateNguyễn Thái Ngọc Duy, Jun 12, 2016
  58. 22/27 fetch: define shallow boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 12, 2016
  59. 21/27 upload-pack: support define shallow boundary by excluding revisionsNguyễn Thái Ngọc Duy, Jun 12, 2016
  60. 24/27 t5500, t5539: tests for shallow depth excluding a refNguyễn Thái Ngọc Duy, Jun 12, 2016
  61. 23/27 clone: define shallow clone boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 12, 2016
  62. 25/27 upload-pack: split check_unreachable() in two, prep for get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  63. 26/27 upload-pack: add get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  64. 27/27 fetch, upload-pack: --deepen=N extends shallow boundary by N commitsNguyễn Thái Ngọc Duy, Jun 12, 2016

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.