Re: [PATCH 1/2] git-sh-setup: refactor ident-parsing functions
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 12, 2012, 20:08 UTC
- Message-ID
- <7vzk2mh9dm.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20121112194434.GB4623@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> Changing the interface for get_author_ident_from_commit would be a pain, > but if we just wanted to help filter-branch, we could do something like > this:
Yes, that is the direction I was alluding to.
Callers of get_author_ident_from_commit can also do the same and avoid rebuilding the same $pick_author_script over and over again, or get_author_ident_from_commit can do so for its callers.
Show 44 quoted lines
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 5314249..7a693ba 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -74,7 +74,7 @@ finish_ident() {
> }
>
> set_ident () {
> - parse_ident_from_commit author AUTHOR committer COMMITTER
> + parse_ident_from_commit_via_script "$ident_script"
> finish_ident AUTHOR
> finish_ident COMMITTER
> }
> @@ -93,6 +93,7 @@ if [ "$(is_bare_repository)" = false ]; then
> require_clean_work_tree 'rewrite branches'
> fi
>
> +ident_script=$(pick_ident_script author AUTHOR committer COMMITTER)
> tempdir=.git-rewrite
> filter_env=
> filter_tree=
> diff --git a/git-sh-setup.sh b/git-sh-setup.sh
> index 22f0aed..1e20e17 100644
> --- a/git-sh-setup.sh
> +++ b/git-sh-setup.sh
> @@ -225,10 +225,17 @@ pick_ident_script () {
> echo '/^$/q'
> }
>
> +# Feed a pick_ident_script return value to sed. Use this instead of
> +# parse_ident_from_commit below if you are going to be parsing commits in a
> +# tight loop and want to save a process.
> +parse_ident_from_commit_via_script() {
> + LANG=C LC_ALL=C sed -ne "$1"
> +}
> +
> # Create a pick-script as above and feed it to sed. Stdout is suitable for
> # feeding to eval.
> parse_ident_from_commit () {
> - LANG=C LC_ALL=C sed -ne "$(pick_ident_script "$@")"
> + parse_ident_from_commit_via_script "$(pick_ident_script "$@")"
> }
>
> # Parse the author from a commit given as an argument. Stdout is suitable for