git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "Jakub Narebski" <jnareb@gmail.com>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
	git <git@vger.kernel.org>,
	computerdruid <computerdruid@gmail.com>, joey <joey@kitenet.net>,
	"René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Subject: Re: [PATCH] grep -A/-B/-Cinfinity to get full context
Date: Fri, 20 Aug 2010 19:02:09 +0530	[thread overview]
Message-ID: <20100820133206.GD9448@kytes> (raw)
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.

> 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.

> -		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.

> 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

  reply	other threads:[~2010-08-20 13:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-17  0:49 fully deepening a shallow clone Joey Hess
2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
2010-08-18 12:54   ` Daniel Johnson
2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
2010-08-19 14:31       ` Daniel Johnson
2010-08-19 22:15         ` Nguyen Thai Ngoc Duy
2010-08-19 20:49       ` Mikael Magnusson
2010-08-19 10:40     ` [PATCH 2/3] fetch-pack: use args.shallow to detect shallow clone instead of args.depth Nguyễn Thái Ngọc Duy
2010-08-19 10:40     ` [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again Nguyễn Thái Ngọc Duy
2010-08-19 21:22       ` Jakub Narebski
2010-08-19 22:11         ` Nguyen Thai Ngoc Duy
2010-08-20  9:22           ` Jakub Narebski
2010-08-20  9:28             ` Ramkumar Ramachandra
2010-08-20 11:55             ` [PATCH] grep -A/-B/-Cinfinity to get full context Jonathan Nieder
2010-08-20 13:32               ` Ramkumar Ramachandra [this message]
2010-08-18 15:48   ` fully deepening a shallow clone Joey Hess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100820133206.GD9448@kytes \
    --to=artagnon@gmail.com \
    --cc=computerdruid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=joey@kitenet.net \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).