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

[PATCH v2 4/4] pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESS

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 17, 2021, 10:57 UTC
Message-ID
<patch-4.4-e59a06c314-20210617T105537Z-avarab@gmail.com>
In-Reply-To
<cover-0.4-0000000000-20210617T105537Z-avarab@gmail.com>

Continue the work started in the preceding commit of porting pack-objects.c over to the new handle_stdin_line callback pattern. The common case for the users of this API is to do some of their own parsing or munging, and then have handle_revision_arg() handle the rest.

The existing users of the --stdin parsing always wanted a flag of "0" to be passed to handle_revision_arg(), but pack-objects.c wants to set custom flags. Let's support this common case by having a "revarg_flags" member in the "rev_info" struct.

This allows us to return REV_INFO_STDIN_LINE_PROCESS in the new get_object_list_handle_stdin_line() instead of REV_INFO_STDIN_LINE_CONTINUE, as read_revisions_from_stdin() will now pass down the right flag for us.

This also means that we can make the handle_revision_arg() function static. Now that the only external user of the API has been migrated over to the callback mechanism nothing external to revision.c needs to call handle_revision_arg() anymore.

That handle_revision_arg() function was made public in a combination of 5d6f0935e6d (revision.c: allow injecting revision parameters after setup_revisions()., 2006-09-05) and b5d97e6b0a0 (pack-objects: run rev-list equivalent internally., 2006-09-04).

This change leaves the briefly-used in preceding commits "void *stdin_line_priv" without any in-tree user, as builtin/pack-objects.c could be ported over to our new "revarg_flags" common case.

I'm leaving that "void *stdin_line_priv" in place anyway for two reasons:

 1. It's a common pattern to allow such a "void *" to be used for
    callback data, so we might as well follow that pattern here in
    anticipation of a future in-tree user.
 2. I have patches for such an in-tree user already in a series
    that'll be submitted after this one.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/pack-objects.c | 9 ++-------
 revision.c             | 4 ++--
 revision.h             | 8 ++++++--
 3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index cbb01f2b2d..0ab2d10853 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3748,7 +3748,6 @@ static void mark_bitmap_preferred_tips(void)
 static enum rev_info_stdin_line get_object_list_handle_stdin_line(
 	struct rev_info *revs, struct strbuf *line_sb, void *stdin_line_priv)
 {
-	int *flags = stdin_line_priv;
 	char *line = line_sb->buf;
 	size_t len = line_sb->len;
 
@@ -3756,7 +3755,7 @@ static enum rev_info_stdin_line get_object_list_handle_stdin_line(
 		return REV_INFO_STDIN_LINE_BREAK;
 	if (*line == '-') {
 		if (!strcmp(line, "--not")) {
-			*flags ^= UNINTERESTING;
+			revs->revarg_flags ^= UNINTERESTING;
 			write_bitmap_index = 0;
 			return REV_INFO_STDIN_LINE_CONTINUE;
 		}
@@ -3770,9 +3769,7 @@ static enum rev_info_stdin_line get_object_list_handle_stdin_line(
 		}
 		die(_("not a rev '%s'"), line);
 	}
-	if (handle_revision_arg(line, revs, *flags, REVARG_CANNOT_BE_FILENAME))
-			die(_("bad revision '%s'"), line);
-	return REV_INFO_STDIN_LINE_CONTINUE;
+	return REV_INFO_STDIN_LINE_PROCESS;
 }
 
 static void get_object_list(int ac, const char **av)
@@ -3781,7 +3778,6 @@ static void get_object_list(int ac, const char **av)
 	struct setup_revision_opt s_r_opt = {
 		.allow_exclude_promisor_objects = 1,
 	};
-	int flags = 0;
 
 	repo_init_revisions(the_repository, &revs, NULL);
 	save_commit_buffer = 0;
@@ -3791,7 +3787,6 @@ static void get_object_list(int ac, const char **av)
 
 	revs.stdin_handling = REV_INFO_STDIN_ALWAYS_READ;
 	revs.handle_stdin_line = get_object_list_handle_stdin_line;
-	revs.stdin_line_priv = &flags;
 	setup_revisions(ac, av, &revs, &s_r_opt);
 
 	if (use_bitmap_index && !get_object_list_from_bitmap(&revs))
diff --git a/revision.c b/revision.c
index 2ca2c38447..ad94a646f7 100644
--- a/revision.c
+++ b/revision.c
@@ -2089,7 +2089,7 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
 	return 0;
 }
 
-int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt)
+static int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt)
 {
 	int ret = handle_revision_arg_1(arg, revs, flags, revarg_opt);
 	if (!ret)
@@ -2145,7 +2145,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
 			}
 			die("options not supported in --stdin mode");
 		}
-		if (handle_revision_arg(sb.buf, revs, 0,
+		if (handle_revision_arg(sb.buf, revs, revs->revarg_flags,
 					REVARG_CANNOT_BE_FILENAME))
 			die("bad revision '%s'", sb.buf);
 	}
diff --git a/revision.h b/revision.h
index 5df1523a6c..c473567d82 100644
--- a/revision.h
+++ b/revision.h
@@ -157,11 +157,16 @@ struct rev_info {
 	 *   revision.c's normal processing of the line (after
 	 *   possibly munging the provided strbuf).
 	 *
+	 *   Change "revarg_flags" to affect the subsequent handling
+	 *   in handle_revision_arg()
+	 *
 	 * - Return REV_INFO_STDIN_LINE_BREAK to process no further
 	 *   lines, or anything further from the current line (just
 	 *   like REV_INFO_STDIN_LINE_CONTINUE).
 	 *
 	 * - Return REV_INFO_STDIN_LINE_CONTINUE to indicate that the
+	 *
+	 * - Return REV_INFO_STDIN_LINE_BREAK to indicate that the
 	 *   line is fully processed, moving onto the next line (if
 	 *   any)
 	 *
@@ -169,6 +174,7 @@ struct rev_info {
 	 * around.
 	 */
 	rev_info_stdin_line_func handle_stdin_line;
+	int revarg_flags;
 	void *stdin_line_priv;
 
 	/* topo-sort */
@@ -426,8 +432,6 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
 			const char * const usagestr[]);
 #define REVARG_CANNOT_BE_FILENAME 01
 #define REVARG_COMMITTISH 02
-int handle_revision_arg(const char *arg, struct rev_info *revs,
-			int flags, unsigned revarg_opt);
 
 /**
  * Reset the flags used by the revision walking api. You can use this to do
-- 
2.32.0.571.gdba276db2c
Previous: Jonathan TanNext: Ævar Arnfjörð Bjarmason
Message 14 of 35 in “pack-objects: use revision.c's --stdin parsing”
  1. 0/4 pack-objects: use revision.c's --stdin parsingÆvar Arnfjörð Bjarmason, Jun 8, 2021
  2. 2/4 revision.h: unify "disable_stdin" and "read_from_stdin"Ævar Arnfjörð Bjarmason, Jun 8, 2021
  3. 3/4 pack-objects.c: do stdin parsing via revision.c's APIÆvar Arnfjörð Bjarmason, Jun 8, 2021
  4. Junio C HamanoJun 9, 2021
  5. 1/4 upload-pack: run is_repository_shallow() before setup_revisions()Ævar Arnfjörð Bjarmason, Jun 8, 2021
  6. 4/4 pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESSÆvar Arnfjörð Bjarmason, Jun 8, 2021
  7. 0/4 pack-objects: use revision.c's --stdin parsingÆvar Arnfjörð Bjarmason, Jun 17, 2021
  8. 1/4 upload-pack: run is_repository_shallow() before setup_revisions()Ævar Arnfjörð Bjarmason, Jun 17, 2021
  9. 2/4 revision.h: unify "disable_stdin" and "read_from_stdin"Ævar Arnfjörð Bjarmason, Jun 17, 2021
  10. Emily ShafferJun 17, 2021
  11. Jonathan TanJun 18, 2021
  12. 3/4 pack-objects.c: do stdin parsing via revision.c's APIÆvar Arnfjörð Bjarmason, Jun 17, 2021
  13. Jonathan TanJun 18, 2021
  14. 4/4 pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESSÆvar Arnfjörð Bjarmason, Jun 17, 2021
  15. 0/4 pack-objects: use revision.c's --stdin parsingÆvar Arnfjörð Bjarmason, Jun 21, 2021
  16. 1/4 upload-pack: run is_repository_shallow() before setup_revisions()Ævar Arnfjörð Bjarmason, Jun 21, 2021
  17. 3/4 pack-objects.c: do stdin parsing via revision.c's APIÆvar Arnfjörð Bjarmason, Jun 21, 2021
  18. Junio C HamanoJul 8, 2021
  19. 2/4 revision.h: refactor "disable_stdin" and "read_from_stdin"Ævar Arnfjörð Bjarmason, Jun 21, 2021
  20. Junio C HamanoJul 8, 2021
  21. 4/4 pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESSÆvar Arnfjörð Bjarmason, Jun 21, 2021
  22. Junio C HamanoJul 8, 2021
  23. 0/5 revision.[ch]: add --stdin parsing API, use in pack-objectsÆvar Arnfjörð Bjarmason, Jul 9, 2021
  24. 1/5 upload-pack: run is_repository_shallow() before setup_revisions()Ævar Arnfjörð Bjarmason, Jul 9, 2021
  25. 2/5 revision.h: refactor "disable_stdin" and "read_from_stdin"Ævar Arnfjörð Bjarmason, Jul 9, 2021
  26. Junio C HamanoJul 9, 2021
  27. 4/5 pack-objects.c: do stdin parsing via revision.c's APIÆvar Arnfjörð Bjarmason, Jul 9, 2021
  28. 5/5 pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESSÆvar Arnfjörð Bjarmason, Jul 9, 2021
  29. 3/5 revision.[ch]: add a "handle_stdin_line" APIÆvar Arnfjörð Bjarmason, Jul 9, 2021
  30. 0/5 add --stdin parsing API, use in pack-objectsÆvar Arnfjörð Bjarmason, Jul 26, 2021
  31. 1/5 upload-pack: run is_repository_shallow() before setup_revisions()Ævar Arnfjörð Bjarmason, Jul 26, 2021
  32. 5/5 pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESSÆvar Arnfjörð Bjarmason, Jul 26, 2021
  33. 2/5 revision.h: refactor "disable_stdin" and "read_from_stdin"Ævar Arnfjörð Bjarmason, Jul 26, 2021
  34. 4/5 pack-objects.c: do stdin parsing via revision.c's APIÆvar Arnfjörð Bjarmason, Jul 26, 2021
  35. 3/5 revision.[ch]: add a "handle_stdin_line" APIÆvar Arnfjörð Bjarmason, Jul 26, 2021

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.