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

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

Previous: Randall S. BeckerNext: Junio C Hamano
Message 6 of 7 in “[RFC] new subcommand: git sync”
  1. Jean-Marie LemetayerFeb 26, 2021
  2. Ævar Arnfjörð BjarmasonFeb 26, 2021
  3. Randall S. BeckerFeb 26, 2021
  4. Jean-Marie LemetayerMar 1, 2021
  5. Randall S. BeckerMar 1, 2021
  6. Junio C HamanoFeb 26, 2021
  7. Junio C HamanoFeb 26, 2021

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.