Re: [RFC] new subcommand: git sync
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 26, 2021, 22:31 UTC
- Message-ID
- <xmqq35xisbp3.fsf@gitster.g>
- In-Reply-To
- <87tupy7sx6.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> B.t.w. you can probably speed up & simplify your script a lot by making > use of IFS="" in the shell and not calling N for-each-ref commands when > it seems to me that one invocation would do. Just dump the N fields you > need split on some token, and split on that token in your loop.
A hidden gem in for-each-ref is its ability to quote the placeholder values in a language specific way, and that is to allow the --format to generate a script that can be eval'ed. E.g.
$ git for-each-ref --shell \
--format='doit %(authorname) %(subject)' refs/heads/ab/\* |
head -n 3
doit 'Ævar Arnfjörð Bjarmason' 'branch: show "HEAD detached" first ...'
doit 'Ævar Arnfjörð Bjarmason' 'CoC: update to version 2.0 + local ...'
doit 'Ævar Arnfjörð Bjarmason' 'config.mak.uname: remove unused NEE...'so that you can prepare
doit () {
person=$1 subject=$2
... do things on the branch data ...
}beforehand and then eval the output from the script you wrote with "git for-each-ref".