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

Re: [PATCH v2 1/3] rev-list: refactor --missing=<missing-action>

From
Junio C Hamano <gitster@pobox.com>
Date
May 15, 2024, 16:16 UTC
Message-ID
<xmqq4jaz1263.fsf@gitster.g>
In-Reply-To
<20240515132543.851987-2-christian.couder@gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 27 quoted lines
> Both `git rev-list` and `git pack-objects` support a
> `--missing=<missing-action>` feature, but they currently don't share
> any code for that.
>
> Refactor the support for `--missing=<missing-action>` in
> "builtin/rev-list.c" into new "missing.{c,h}" files. In a following
> commit, that refactored code will be used in "builtin/pack-objects.c"
> too.
>
> In yet a following commit, we are going to add support for a similar
> 'missing-action' feature to another command, and we are also going to
> reuse code from the new "missing.{c,h}" files.
>
> As `enum missing_action` and parse_missing_action_value() are moved to
> "missing.{c,h}", we need to modify the latter a bit, so that it stops
> updating any global variable, but instead returns the parsed value or
> -1 on error.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  Makefile           |  1 +
>  builtin/rev-list.c | 43 ++++++++-----------------------------------
>  missing.c          | 20 ++++++++++++++++++++
>  missing.h          | 17 +++++++++++++++++
>  4 files changed, 46 insertions(+), 35 deletions(-)
>  create mode 100644 missing.c
>  create mode 100644 missing.h
All makes sense.  Will queue.  Thanks.
Show 139 quoted lines
> diff --git a/Makefile b/Makefile
> index 0285db5630..e0ddcc2cbd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1062,6 +1062,7 @@ LIB_OBJS += merge-recursive.o
>  LIB_OBJS += merge.o
>  LIB_OBJS += midx.o
>  LIB_OBJS += midx-write.o
> +LIB_OBJS += missing.o
>  LIB_OBJS += name-hash.o
>  LIB_OBJS += negotiator/default.o
>  LIB_OBJS += negotiator/noop.o
> diff --git a/builtin/rev-list.c b/builtin/rev-list.c
> index 77803727e0..40aa770c47 100644
> --- a/builtin/rev-list.c
> +++ b/builtin/rev-list.c
> @@ -20,6 +20,7 @@
>  #include "reflog-walk.h"
>  #include "oidset.h"
>  #include "packfile.h"
> +#include "missing.h"
>  
>  static const char rev_list_usage[] =
>  "git rev-list [<options>] <commit>... [--] [<path>...]\n"
> @@ -71,12 +72,6 @@ static struct oidset omitted_objects;
>  static int arg_print_omitted; /* print objects omitted by filter */
>  
>  static struct oidset missing_objects;
> -enum missing_action {
> -	MA_ERROR = 0,    /* fail if any missing objects are encountered */
> -	MA_ALLOW_ANY,    /* silently allow ALL missing objects */
> -	MA_PRINT,        /* print ALL missing objects in special section */
> -	MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
> -};
>  static enum missing_action arg_missing_action;
>  
>  /* display only the oid of each object encountered */
> @@ -392,34 +387,6 @@ static void print_disk_usage(off_t size)
>  	strbuf_release(&sb);
>  }
>  
> -static inline int parse_missing_action_value(const char *value)
> -{
> -	if (!strcmp(value, "error")) {
> -		arg_missing_action = MA_ERROR;
> -		return 1;
> -	}
> -
> -	if (!strcmp(value, "allow-any")) {
> -		arg_missing_action = MA_ALLOW_ANY;
> -		fetch_if_missing = 0;
> -		return 1;
> -	}
> -
> -	if (!strcmp(value, "print")) {
> -		arg_missing_action = MA_PRINT;
> -		fetch_if_missing = 0;
> -		return 1;
> -	}
> -
> -	if (!strcmp(value, "allow-promisor")) {
> -		arg_missing_action = MA_ALLOW_PROMISOR;
> -		fetch_if_missing = 0;
> -		return 1;
> -	}
> -
> -	return 0;
> -}
> -
>  static int try_bitmap_count(struct rev_info *revs,
>  			    int filter_provided_objects)
>  {
> @@ -569,10 +536,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
>  	for (i = 1; i < argc; i++) {
>  		const char *arg = argv[i];
>  		if (skip_prefix(arg, "--missing=", &arg)) {
> +			int res;
>  			if (revs.exclude_promisor_objects)
>  				die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing");
> -			if (parse_missing_action_value(arg))
> +			res = parse_missing_action_value(arg);
> +			if (res >= 0) {
> +				if (res != MA_ERROR)
> +					fetch_if_missing = 0;
> +				arg_missing_action = res;
>  				break;
> +			}
>  		}
>  	}
>  
> diff --git a/missing.c b/missing.c
> new file mode 100644
> index 0000000000..ce3cf734a8
> --- /dev/null
> +++ b/missing.c
> @@ -0,0 +1,20 @@
> +#include "git-compat-util.h"
> +#include "missing.h"
> +#include "object-file.h"
> +
> +int parse_missing_action_value(const char *value)
> +{
> +	if (!strcmp(value, "error"))
> +		return MA_ERROR;
> +
> +	if (!strcmp(value, "allow-any"))
> +		return MA_ALLOW_ANY;
> +
> +	if (!strcmp(value, "print"))
> +		return MA_PRINT;
> +
> +	if (!strcmp(value, "allow-promisor"))
> +		return MA_ALLOW_PROMISOR;
> +
> +	return -1;
> +}
> diff --git a/missing.h b/missing.h
> new file mode 100644
> index 0000000000..1e378d6215
> --- /dev/null
> +++ b/missing.h
> @@ -0,0 +1,17 @@
> +#ifndef MISSING_H
> +#define MISSING_H
> +
> +enum missing_action {
> +	MA_ERROR = 0,      /* fail if any missing objects are encountered */
> +	MA_ALLOW_ANY,      /* silently allow ALL missing objects */
> +	MA_PRINT,          /* print ALL missing objects in special section */
> +	MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
> +};
> +
> +/*
> +  Return an `enum missing_action` in case parsing is successful or -1
> +  if parsing failed.
> +*/
> +int parse_missing_action_value(const char *value);
> +
> +#endif /* MISSING_H */
Previous: Christian CouderNext: Christian Couder
Message 32 of 46 in “Implement filtering repacks”
  1. 0/3 Implement filtering repacksChristian Couder, Oct 12, 2022
  2. 1/3 pack-objects: allow --filter without --stdoutChristian Couder, Oct 12, 2022
  3. 2/3 repack: add --filter=<filter-spec> optionChristian Couder, Oct 12, 2022
  4. 3/3 repack: introduce --force to force filteringChristian Couder, Oct 12, 2022
  5. Junio C HamanoOct 14, 2022
  6. Christian CouderOct 20, 2022
  7. Taylor BlauOct 28, 2022
  8. Junio C HamanoOct 28, 2022
  9. Christian CouderNov 7, 2022
  10. Christian CouderNov 7, 2022
  11. 0/2 Implement filtering repacksChristian Couder, Oct 25, 2022
  12. 1/2 pack-objects: allow --filter without --stdoutChristian Couder, Oct 25, 2022
  13. 2/2 repack: add --filter=<filter-spec> optionChristian Couder, Oct 25, 2022
  14. Taylor BlauOct 28, 2022
  15. Christian CouderNov 7, 2022
  16. 0/2 Implement filtering repacksChristian Couder, Nov 22, 2022
  17. 1/2 pack-objects: allow --filter without --stdoutChristian Couder, Nov 22, 2022
  18. 2/2 repack: add --filter=<filter-spec> optionChristian Couder, Nov 22, 2022
  19. Junio C HamanoNov 23, 2022
  20. Christian CouderDec 21, 2022
  21. Junio C HamanoNov 23, 2022
  22. 0/3 Implement filtering repacksChristian Couder, Dec 21, 2022
  23. 1/3 pack-objects: allow --filter without --stdoutChristian Couder, Dec 21, 2022
  24. Patrick SteinhardtJan 4, 2023
  25. 2/3 repack: add --filter=<filter-spec> optionChristian Couder, Dec 21, 2022
  26. Patrick SteinhardtJan 4, 2023
  27. Junio C HamanoJan 5, 2023
  28. 3/3 gc: add gc.repackFilter config optionChristian Couder, Dec 21, 2022
  29. Patrick SteinhardtJan 4, 2023
  30. 0/3 upload-pack: support a missing-actionChristian Couder, May 15, 2024
  31. 1/3 rev-list: refactor --missing=<missing-action>Christian Couder, May 15, 2024
  32. Junio C HamanoMay 15, 2024
  33. 2/3 pack-objects: use the missing action APIChristian Couder, May 15, 2024
  34. Junio C HamanoMay 15, 2024
  35. Christian CouderMay 24, 2024
  36. 3/3 upload-pack: allow configuring a missing-actionChristian Couder, May 15, 2024
  37. Junio C HamanoMay 15, 2024
  38. Christian CouderMay 24, 2024
  39. Junio C HamanoMay 24, 2024
  40. Christian CouderMay 28, 2024
  41. Junio C HamanoMay 28, 2024
  42. Christian CouderMay 31, 2024
  43. Junio C HamanoJun 1, 2024
  44. Christian CouderJun 3, 2024
  45. Junio C HamanoJun 3, 2024
  46. Christian CouderMay 15, 2024

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.