<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/ref-filter.h, branch v2.35.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.35.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.35.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-10-20T21:33:07Z</updated>
<entry>
<title>for-each-ref: delay parsing of --sort=&lt;atom&gt; options</title>
<updated>2021-10-20T21:33:07Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2021-10-20T19:23:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=98e7ab6d42beba8b35fefb3856b07ac20e89d1ca'/>
<id>urn:sha1:98e7ab6d42beba8b35fefb3856b07ac20e89d1ca</id>
<content type='text'>
The for-each-ref family of commands invoke parsers immediately when
it sees each --sort=&lt;atom&gt; option, and die before even seeing the
other options on the command line when the &lt;atom&gt; is unrecognised.

Instead, accumulate them in a string list, and have them parsed into
a ref_sorting structure after the command line parsing is done.  As
a consequence, "git branch --sort=bogus -h" used to fail to give the
brief help, which arguably may have been a feature, now does so,
which is more consistent with how other options work.

The patch is smaller than the actual extent of the "damage" to the
codebase, thanks to the fact that the original code consistently
used OPT_REF_SORT() macro to handle command line options.  We only
needed to replace the variable used for the list, and implementation
of the callback function used in the macro.

The old rule was for the users of the API to:

 - Declare ref_sorting and ref_sorting_tail variables;

 - OPT_REF_SORT() macro will instantiate ref_sorting instance (which
   may barf and die) and append it to the tail;

 - Append to the tail each ref_sorting read from the configuration
   by parsing in the config callback (which may barf and die);

 - See if ref_sorting is null and use ref_sorting_default() instead.

Now the rule is not all that different but is simpler:

 - Declare ref_sorting_options string list.

 - OPT_REF_SORT() macro will append it to the string list;

 - Append to the string list the sort key read from the
   configuration;

 - call ref_sorting_options() to turn the string list to ref_sorting
   structure (which also deals with the default value).

As side effects, this change also cleans up a few issues:

 - 95be717c (parse_opt_ref_sorting: always use with NONEG flag,
   2019-03-20) muses that "git for-each-ref --no-sort" should simply
   clear the sort keys accumulated so far; it now does.

 - The implementation detail of "struct ref_sorting" and the helper
   function parse_ref_sorting() can now be private to the ref-filter
   API implementation.

 - If you set branch.sort to a bogus value, the any "git branch"
   invocation, not only the listing mode, would abort with the
   original code; now it doesn't

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter API user: add and use a ref_sorting_release()</title>
<updated>2021-10-20T18:36:13Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-20T18:27:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e5fb028688f5811bd835c0bc47f8d7a379a0d152'/>
<id>urn:sha1:e5fb028688f5811bd835c0bc47f8d7a379a0d152</id>
<content type='text'>
Add a ref_sorting_release() and use it for some of the current API
users, the ref_sorting_default() function and its siblings will do a
malloc() which wasn't being free'd previously.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: drop broken-ref code entirely</title>
<updated>2021-09-27T19:36:45Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2021-09-24T18:48:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2d653c50364aeccb604f6b4680190824debf637a'/>
<id>urn:sha1:2d653c50364aeccb604f6b4680190824debf637a</id>
<content type='text'>
Now that none of our callers passes the INCLUDE_BROKEN flag, we can drop
it entirely, along with the code to plumb it through to the
for_each_fullref_in() functions.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Reviewed-by: Jonathan Tan &lt;jonathantanmy@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: add %(rest) atom</title>
<updated>2021-07-26T19:01:26Z</updated>
<author>
<name>ZheNing Hu</name>
<email>adlternative@gmail.com</email>
</author>
<published>2021-07-26T03:26:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b9dee075eb07713a49922f7e1f90a6a9de5c5e5f'/>
<id>urn:sha1:b9dee075eb07713a49922f7e1f90a6a9de5c5e5f</id>
<content type='text'>
%(rest) is a atom used for cat-file batch mode, which can split
the input lines at the first whitespace boundary, all characters
before that whitespace are considered to be the object name;
characters after that first run of whitespace (i.e., the "rest"
of the line) are output in place of the %(rest) atom.

In order to let "cat-file --batch=%(rest)" use the ref-filter
interface, add %(rest) atom for ref-filter.

Introduce the reject_atom() to reject the atom %(rest) for
"git for-each-ref", "git branch", "git tag" and "git verify-tag".

Reviewed-by: Jacob Keller &lt;jacob.keller@gmail.com&gt;
Suggected-by: Jacob Keller &lt;jacob.keller@gmail.com&gt;
Mentored-by: Christian Couder &lt;christian.couder@gmail.com&gt;
Mentored-by: Hariom Verma &lt;hariom18599@gmail.com&gt;
Signed-off-by: ZheNing Hu &lt;adlternative@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: use non-const ref_format in *_atom_parser()</title>
<updated>2021-07-26T19:01:26Z</updated>
<author>
<name>ZheNing Hu</name>
<email>adlternative@gmail.com</email>
</author>
<published>2021-07-26T03:26:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e85fcb355a38b5f01493efecdf0150a10ee471da'/>
<id>urn:sha1:e85fcb355a38b5f01493efecdf0150a10ee471da</id>
<content type='text'>
Use non-const ref_format in *_atom_parser(), which can help us
modify the members of ref_format in *_atom_parser().

Mentored-by: Christian Couder &lt;christian.couder@gmail.com&gt;
Mentored-by: Hariom Verma &lt;hariom18599@gmail.com&gt;
Signed-off-by: ZheNing Hu &lt;adlternative@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: get rid of show_ref_array_item</title>
<updated>2021-04-19T22:08:00Z</updated>
<author>
<name>ZheNing Hu</name>
<email>adlternative@gmail.com</email>
</author>
<published>2021-04-19T11:28:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=22f69a85edf29dba2278b55f14419e4ea48148d2'/>
<id>urn:sha1:22f69a85edf29dba2278b55f14419e4ea48148d2</id>
<content type='text'>
Inlining the exported function `show_ref_array_item()`,
which is not providing the right level of abstraction,
simplifies the API and can unlock improvements at the
former call sites.

Helped-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: ZheNing Hu &lt;adlternative@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>branch: sort detached HEAD based on a flag</title>
<updated>2021-01-07T23:13:21Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-01-07T09:51:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2708ce62d2105c4470399a2c839b6d451c9c148f'/>
<id>urn:sha1:2708ce62d2105c4470399a2c839b6d451c9c148f</id>
<content type='text'>
Change the ref-filter sorting of detached HEAD to check the
FILTER_REFS_DETACHED_HEAD flag, instead of relying on the ref
description filled-in by get_head_description() to start with "(",
which in turn we expect to ASCII-sort before any other reference.

For context, we'd like the detached line to appear first at the start
of "git branch -l", e.g.:

    $ git branch -l
    * (HEAD detached at &lt;hash&gt;)
      master

This doesn't change that, but improves on a fix made in
28438e84e04 (ref-filter: sort detached HEAD lines firstly, 2019-06-18)
and gives the Chinese translation the ability to use its preferred
punctuation marks again.

In Chinese the fullwidth versions of punctuation like "()" are
typically written as (U+FF08 fullwidth left parenthesis), (U+FF09
fullwidth right parenthesis) instead[1]. This form is used in both
po/zh_{CN,TW}.po in most cases where "()" is translated in a string.

Aside from that improvement to the Chinese translation, it also just
makes for cleaner code that we mark any special cases in the ref_array
we're sorting with flags and make the sort function aware of them,
instead of piggy-backing on the general-case of strcmp() doing the
right thing.

As seen in the amended tests this made reverse sorting a bit more
consistent. Before this we'd sometimes sort this message in the
middle, now it's consistently at the beginning or end, depending on
whether we're doing a normal or reverse sort. Having it at the end
doesn't make much sense either, but at least it behaves consistently
now. A follow-up commit will make this behavior under reverse sorting
even better.

I'm removing the "TRANSLATORS" comments that were in the old code
while I'm at it. Those were added in d4919bb288e (ref-filter: move
get_head_description() from branch.c, 2017-01-10). I think it's
obvious from context, string and translation memory in typical
translation tools that these are the same or similar string.

1. https://en.wikipedia.org/wiki/Chinese_punctuation#Marks_similar_to_European_punctuation

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: move ref_sorting flags to a bitfield</title>
<updated>2021-01-07T23:13:21Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-01-07T09:51:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7c269a7b162027d0465d52203e778903a2ddbdbf'/>
<id>urn:sha1:7c269a7b162027d0465d52203e778903a2ddbdbf</id>
<content type='text'>
Change the reverse/ignore_case/version sort flags in the ref_sorting
struct into a bitfield. Having three of them was already a bit
unwieldy, but it would be even more so if another flag needed a
function like ref_sorting_icase_all() introduced in
76f9e569adb (ref-filter: apply --ignore-case to all sorting keys,
2020-05-03).

A follow-up change will introduce such a flag, so let's move this over
to a bitfield. Instead of using the usual '#define' pattern I'm using
the "enum" pattern from builtin/rebase.c's b4c8eb024af (builtin
rebase: support --quiet, 2018-09-04).

Perhaps there's a more idiomatic way of doing the "for each in list
amend mask" pattern than this "mask/on" variable combo. This function
doesn't allow us to e.g. do any arbitrary changes to the bitfield for
multiple flags, but I think in this case that's fine. The common case
is that we're calling this with a list of one.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: make internal reachable-filter API more precise</title>
<updated>2020-09-18T22:41:55Z</updated>
<author>
<name>Aaron Lipman</name>
<email>alipman88@gmail.com</email>
</author>
<published>2020-09-18T21:58:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a1b19aa5d43c46fc570f6946ab5ad001dccc8cdf'/>
<id>urn:sha1:a1b19aa5d43c46fc570f6946ab5ad001dccc8cdf</id>
<content type='text'>
The internal reachable-filter API is a bit loose and imprecise; it
also bleeds unnecessarily into the public header. Tighten the API
by:

* renaming do_merge_filter() to reach_filter()

* separating parameters to explicitly identify what data is used
  by the function instead of passing an entire ref_filter_cbdata
  struct

* renaming and moving internal constants from header to source
  file

Signed-off-by: Aaron Lipman &lt;alipman88@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: allow merged and no-merged filters</title>
<updated>2020-09-16T19:38:10Z</updated>
<author>
<name>Aaron Lipman</name>
<email>alipman88@gmail.com</email>
</author>
<published>2020-09-16T02:08:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=21bf933928c02372633b88aa6c4d9d71271d42b3'/>
<id>urn:sha1:21bf933928c02372633b88aa6c4d9d71271d42b3</id>
<content type='text'>
Enable ref-filter to process multiple merged and no-merged filters, and
extend functionality to git branch, git tag and git for-each-ref. This
provides an easy way to check for branches that are "graduation
candidates:"

$ git branch --no-merged master --merged next

If passed more than one merged (or more than one no-merged) filter, refs
must be reachable from any one of the merged commits, and reachable from
none of the no-merged commits.

Signed-off-by: Aaron Lipman &lt;alipman88@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
