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

Re: [PATCH] grep -A/-B/-Cinfinity to get full context

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Aug 20, 2010, 13:32 UTC
Message-ID
<20100820133206.GD9448@kytes>
In-Reply-To
<20100820115527.GR10407@burratino>
Hi Jonathan,
Jonathan Nieder writes:
> Just a proof of concept.
> 
> Cc: René Scharfe <rene.scharfe@lsrfire.ath.cx>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Elegant. OPT_INTEGER for integers without the ability to represent infinity, and OPT_INT_INF for integers with definite representation for infinity.

Show 13 quoted lines
> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
> index 312e3b2..f152a3f 100644
> --- a/Documentation/technical/api-parse-options.txt
> +++ b/Documentation/technical/api-parse-options.txt
> @@ -160,6 +160,12 @@ There are some macros to easily define options:
>  	Introduce an option with integer argument.
>  	The integer is put into `int_var`.
>  
> +`OPT_INT_INF(short, long, &int_var, inf_val, description)`::
> +	Introduce an option with integer argument.
> +	The integer is put into `int_var`.  If the special value
> +	"inf" (or "infinity") is used as an argument, then `inf_val`
> +	is put into `int_var`.

Nice. You're making the caller pass the `inf_val` argument - this way, each caller can figure out some integer that's outside its sane range and use that to represent infinity.

Show 8 quoted lines
> -		OPT_INTEGER('B', NULL, &opt.pre_context,
> +		OPT_INT_INF('B', NULL, &opt.pre_context, -1,
>  			"show <n> context lines before matches"),
> -		OPT_INTEGER('A', NULL, &opt.post_context,
> +		OPT_INT_INF('A', NULL, &opt.post_context, -1,
>  			"show <n> context lines after matches"),
>  		OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM",
>  			context_callback),
For many cases, -1 is probably a good value to choose.
Show 11 quoted lines
> diff --git a/parse-options.h b/parse-options.h
> index 7435cdb..6ae041a 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -126,6 +126,9 @@ struct option {
>  #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
>  #define OPT_UYN(s, l, v, h)         { OPTION_CALLBACK, (s), (l), (v), NULL, \
>  				      (h), PARSE_OPT_NOARG, &parse_opt_tertiary }
> +#define OPT_INT_INF(s, l, v, i, h) \
> +	{ OPTION_CALLBACK, (s), (l), (v), "n", (h), 0, \
> +	  parse_opt_infinity_cb, (intptr_t)(i) }
Okay, you've used the same character "n" for OPT_INTEGER and OPT_INT_INF.
Thanks for the pleasant reading.
-- Ram
Previous: Jonathan NiederNext: Joey Hess
Message 15 of 16 in “fully deepening a shallow clone”
  1. Joey HessAug 17, 2010
  2. Nguyen Thai Ngoc DuyAug 18, 2010
  3. Daniel JohnsonAug 18, 2010
  4. 1/3 clone: do not accept --depth on local clonesNguyễn Thái Ngọc Duy, Aug 19, 2010
  5. Daniel JohnsonAug 19, 2010
  6. Nguyen Thai Ngoc DuyAug 19, 2010
  7. Mikael MagnussonAug 19, 2010
  8. 2/3 fetch-pack: use args.shallow to detect shallow clone instead of args.depthNguyễn Thái Ngọc Duy, Aug 19, 2010
  9. 3/3 {fetch,upload}-pack: allow --depth=0 to deepen into full repo againNguyễn Thái Ngọc Duy, Aug 19, 2010
  10. Jakub NarebskiAug 19, 2010
  11. Nguyen Thai Ngoc DuyAug 19, 2010
  12. Jakub NarebskiAug 20, 2010
  13. Ramkumar RamachandraAug 20, 2010
  14. grep -A/-B/-Cinfinity to get full contextJonathan Nieder, Aug 20, 2010
  15. Ramkumar RamachandraAug 20, 2010
  16. Joey HessAug 18, 2010

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.