git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Andreas Heiduk <asheiduk@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] add setup step to filter-branch
Date: Mon, 05 Jun 2017 11:15:18 +0900	[thread overview]
Message-ID: <xmqq1sqzuqmh.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170603101755.13619-1-asheiduk@gmail.com> (Andreas Heiduk's message of "Sat, 3 Jun 2017 12:17:54 +0200")

Andreas Heiduk <asheiduk@gmail.com> writes:

> A specific `--setup` step in `git filter-branch` makes it much easier
> to define the initial values of variables used in the real filters.
> Also sourcing/defining utility functions here instead of
> `--env-filter` improves performance and minimizes clogging the output
> in case of errors.
>
> Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
> ---

I was placed on To: line, but I do not have a strong opinion on this
change, either for or against.

"filter-branch" program itself may probably already be hard to port
to C, but I need to point out that this makes it even harder than it
currently is [*1*], and it is likely that it has to stay implemented
in shell forever, though.  I do not mind that future myself, but
those on platforms with weaker implementation of shells might.

[Footnote]

 *1* The issue is *not* that these individual filter commands expect
     <command> written as a shell scriptlet; it is that these
     scriptlets expect to be evaled inside a single shell process,
     making an update to a shell variable in one command visible to
     the next command that runs.


>  Documentation/git-filter-branch.txt | 16 +++++++++++-----
>  git-filter-branch.sh                | 18 +++++++++++++-----
>  2 files changed, 24 insertions(+), 10 deletions(-)
>
> diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
> index 6e4bb0220..45c849d8c 100644
> --- a/Documentation/git-filter-branch.txt
> +++ b/Documentation/git-filter-branch.txt
> @@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches
>  SYNOPSIS
>  --------
>  [verse]
> -'git filter-branch' [--env-filter <command>] [--tree-filter <command>]
> -	[--index-filter <command>] [--parent-filter <command>]
> -	[--msg-filter <command>] [--commit-filter <command>]
> -	[--tag-name-filter <command>] [--subdirectory-filter <directory>]
> -	[--prune-empty]
> +'git filter-branch' [--setup <command>] [--env-filter <command>]
> +	[--tree-filter <command>] [--index-filter <command>]
> +	[--parent-filter <command>] [--msg-filter <command>]
> +	[--commit-filter <command>] [--tag-name-filter <command>]
> +	[--subdirectory-filter <directory>] [--prune-empty]
>  	[--original <namespace>] [-d <directory>] [-f | --force]
>  	[--] [<rev-list options>...]
>  
> @@ -82,6 +82,12 @@ multiple commits.
>  OPTIONS
>  -------
>  
> +--setup <command>::
> +	This is not a real filter executed for each commit but a one
> +	time setup just before the loop. Therefore no commit-specific
> +	variables are defined yet.  Functions or variables defined here
> +	can be used or modified in the following filter steps.
> +
>  --env-filter <command>::
>  	This filter may be used if you only need to modify the environment
>  	in which the commit will be performed.  Specifically, you might
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index aafaf708d..2758ae5eb 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -81,11 +81,12 @@ set_ident () {
>  	finish_ident COMMITTER
>  }
>  
> -USAGE="[--env-filter <command>] [--tree-filter <command>]
> -	[--index-filter <command>] [--parent-filter <command>]
> -	[--msg-filter <command>] [--commit-filter <command>]
> -	[--tag-name-filter <command>] [--subdirectory-filter <directory>]
> -	[--original <namespace>] [-d <directory>] [-f | --force]
> +USAGE="[--setup <command>] [--env-filter <command>]
> +	[--tree-filter <command>] [--index-filter <command>]
> +	[--parent-filter <command>] [--msg-filter <command>]
> +	[--commit-filter <command>] [--tag-name-filter <command>]
> +	[--subdirectory-filter <directory>] [--original <namespace>]
> +	[-d <directory>] [-f | --force]
>  	[<rev-list options>...]"
>  
>  OPTIONS_SPEC=
> @@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then
>  fi
>  
>  tempdir=.git-rewrite
> +filter_setup=
>  filter_env=
>  filter_tree=
>  filter_index=
> @@ -148,6 +150,9 @@ do
>  	-d)
>  		tempdir="$OPTARG"
>  		;;
> +	--setup)
> +		filter_setup="$OPTARG"
> +		;;
>  	--env-filter)
>  		filter_env="$OPTARG"
>  		;;
> @@ -317,6 +322,9 @@ else
>  	need_index=
>  fi
>  
> +eval "$filter_setup" < /dev/null ||
> +	die "filter setup failed: $filter_setup"
> +
>  while read commit parents; do
>  	git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))

  parent reply	other threads:[~2017-06-05  2:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-03 10:17 [PATCH 1/2] add setup step to filter-branch Andreas Heiduk
2017-06-03 10:17 ` [PATCH 2/2] add [--] to usage of filter-branch Andreas Heiduk
2017-06-05  8:51   ` Andreas Heiduk
2017-06-09 13:14     ` Junio C Hamano
2017-06-09 14:33       ` Andreas Heiduk
2017-06-05  2:15 ` Junio C Hamano [this message]
2017-06-09  5:49   ` [PATCH 1/2] add setup step to filter-branch Jeff King
2017-06-09 13:11     ` Junio C Hamano
2017-06-10  8:54 ` [PATCH v2 " Andreas Heiduk
2017-06-10  8:54   ` [PATCH v2 2/2] add [--] to usage of filter-branch Andreas Heiduk

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqq1sqzuqmh.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=asheiduk@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).