<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/ref-filter.c, branch v2.23.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.23.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.23.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2019-07-19T18:30:23Z</updated>
<entry>
<title>Merge branch 'ma/ref-filter-leakfix'</title>
<updated>2019-07-19T18:30:23Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-07-19T18:30:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8619522ad1670ea82c0895f2bfe6c75e06df32e7'/>
<id>urn:sha1:8619522ad1670ea82c0895f2bfe6c75e06df32e7</id>
<content type='text'>
Leakfix.

* ma/ref-filter-leakfix:
  ref-filter: fix memory leak in `free_array_item()`
</content>
</entry>
<entry>
<title>Merge branch 'tb/ref-filter-multiple-patterns'</title>
<updated>2019-07-19T18:30:21Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-07-19T18:30:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b4b8c35729985a8f1f5e22f82259a2499efbc37a'/>
<id>urn:sha1:b4b8c35729985a8f1f5e22f82259a2499efbc37a</id>
<content type='text'>
"git for-each-ref" with multiple patterns have been optimized.

* tb/ref-filter-multiple-patterns:
  ref-filter.c: find disjoint pattern prefixes
</content>
</entry>
<entry>
<title>ref-filter: fix memory leak in `free_array_item()`</title>
<updated>2019-07-10T20:27:13Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2019-07-10T18:36:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=14d30cdfc047fdff33c359f17cbb070f2faed009'/>
<id>urn:sha1:14d30cdfc047fdff33c359f17cbb070f2faed009</id>
<content type='text'>
We treat the `value` pointer as a pointer to a struct and free its `s`
field. But `value` is in fact an array of structs. As a result, we only
free the first `s` out of `used_atom_cnt`-many and leak the rest. Make
sure we free all items in `value`.

In the caller, `ref_array_clear()`, this means we need to be careful not
to zero `used_atom_cnt` until after we've called `free_array_item()`. We
could move just a single line, but let's keep related things close
together instead, by first handling `array`, then `used_atom`.

Signed-off-by: Martin Ågren &lt;martin.agren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'md/sort-detached-head-first'</title>
<updated>2019-07-09T22:25:42Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-07-09T22:25:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=92f66fd43b6968da9f14478aa9060ce85f8e3586'/>
<id>urn:sha1:92f66fd43b6968da9f14478aa9060ce85f8e3586</id>
<content type='text'>
"git branch --list" learned to always output the detached HEAD as
the first item (when the HEAD is detached, of course), regardless
of the locale.

* md/sort-detached-head-first:
  ref-filter: sort detached HEAD lines firstly
</content>
</entry>
<entry>
<title>Merge branch 'nb/branch-show-other-worktrees-head'</title>
<updated>2019-07-09T22:25:33Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-07-09T22:25:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=99eea645832d376a3b214b78a57adabf1fa96547'/>
<id>urn:sha1:99eea645832d376a3b214b78a57adabf1fa96547</id>
<content type='text'>
"git branch --list" learned to show branches that are checked out
in other worktrees connected to the same repository prefixed with
'+', similar to the way the currently checked out branch is shown
with '*' in front.

* nb/branch-show-other-worktrees-head:
  branch: add worktree info on verbose output
  branch: update output to include worktree info
  ref-filter: add worktreepath atom
</content>
</entry>
<entry>
<title>ref-filter.c: find disjoint pattern prefixes</title>
<updated>2019-06-27T20:14:06Z</updated>
<author>
<name>Taylor Blau</name>
<email>me@ttaylorr.com</email>
</author>
<published>2019-06-26T22:41:48Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b31e2680c46c43ece716080040e90b3a787b0bad'/>
<id>urn:sha1:b31e2680c46c43ece716080040e90b3a787b0bad</id>
<content type='text'>
Since cfe004a5a9 (ref-filter: limit traversal to prefix, 2017-05-22),
the ref-filter code has sought to limit the traversals to a prefix of
the given patterns.

That code stopped short of handling more than one pattern, because it
means invoking 'for_each_ref_in' multiple times. If we're not careful
about which patterns overlap, we will output the same refs multiple
times.

For instance, consider the set of patterns 'refs/heads/a/*',
'refs/heads/a/b/c', and 'refs/tags/v1.0.0'. If we naÃ¯vely ran:

  for_each_ref_in("refs/heads/a/*", ...);
  for_each_ref_in("refs/heads/a/b/c", ...);
  for_each_ref_in("refs/tags/v1.0.0", ...);

we would see 'refs/heads/a/b/c' (and everything underneath it) twice.

Instead, we want to partition the patterns into disjoint sets, where we
know that no ref will be matched by any two patterns in different sets.
In the above, these are:

  - {'refs/heads/a/*', 'refs/heads/a/b/c'}, and
  - {'refs/tags/v1.0.0'}

Given one of these disjoint sets, what is a suitable pattern to pass to
'for_each_ref_in'? One approach is to compute the longest common prefix
over all elements in that disjoint set, and let the caller cull out the
refs they didn't want. Computing the longest prefix means that in most
cases, we won't match too many things the caller would like to ignore.

The longest common prefixes of the above are:

  - {'refs/heads/a/*', 'refs/heads/a/b/c'} -&gt; refs/heads/a/*
  - {'refs/tags/v1.0.0'}                   -&gt; refs/tags/v1.0.0

We instead invoke:

  for_each_ref_in("refs/heads/a/*", ...);
  for_each_ref_in("refs/tags/v1.0.0", ...);

Which provides us with the refs we were looking for with a minimal
amount of extra cruft, but never a duplicate of the ref we asked for.

Implemented here is an algorithm which accomplishes the above, which
works as follows:

  1. Lexicographically sort the given list of patterns.

  2. Initialize 'prefix' to the empty string, where our goal is to
     build each element in the above set of longest common prefixes.

  3. Consider each pattern in the given set, and emit 'prefix' if it
     reaches the end of a pattern, or touches a wildcard character. The
     end of a string is treated as if it precedes a wildcard. (Note that
     there is some room for future work to detect that, e.g., 'a?b' and
     'abc' are disjoint).

  4. Otherwise, recurse on step (3) with the slice of the list
     corresponding to our current prefix (i.e., the subset of patterns
     that have our prefix as a literal string prefix.)

This algorithm is 'O(kn + n log(n))', where 'k' is max(len(pattern)) for
each pattern in the list, and 'n' is len(patterns).

By discovering this set of interesting patterns, we reduce the runtime
of multi-pattern 'git for-each-ref' (and other ref traversals) from
O(N) to O(n log(N)), where 'N' is the total number of packed references.

Running 'git for-each-ref refs/tags/a refs/tags/b' on a repository with
10,000,000 refs in 'refs/tags/huge-N', my best-of-five times drop from:

  real    0m5.805s
  user    0m5.188s
  sys     0m0.468s

to:

  real    0m0.001s
  user    0m0.000s
  sys     0m0.000s

On linux.git, the times to dig out two of the latest -rc tags drops from
0.002s to 0.001s, so the change on repositories with fewer tags is much
less noticeable.

Co-authored-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Taylor Blau &lt;me@ttaylorr.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: sort detached HEAD lines firstly</title>
<updated>2019-06-19T15:24:41Z</updated>
<author>
<name>Matthew DeVore</name>
<email>matvore@google.com</email>
</author>
<published>2019-06-18T22:29:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=28438e84e046984afc76dc891a49bd0862d555f7'/>
<id>urn:sha1:28438e84e046984afc76dc891a49bd0862d555f7</id>
<content type='text'>
Before this patch, "git branch" would put "(HEAD detached...)" and "(no
branch, rebasing...)" lines before all the other branches *in most
cases* except for when using Chinese-language messages. zh_CN generally
uses a full-width "(" symbol (codepoint FF08) to match the full-width
proportions of Chinese characters, and the translated strings we had did
use them. This meant that the detached HEAD line would appear after all
local refs and even after the remote refs if there were any.

AFAIK, it is sometimes not jarring to see the half-width parenthesis in
"full-width" text as in the CJK languages, for instance when there are
no characters preceding or following the parenthesized text fragment. By
removing the parenthesis from the localizable text, we can share strings
with wt-status.c and remove a cautionary comment to translators.

Remove the ( from the localizable portion of messages so the sorting
happens properly regardless of locale.

Helped-by: Johannes Schindelin &lt;Johannes.Schindelin@gmx.de&gt;
Helped-by: Jonathan Nieder &lt;jrnieder@gmail.com&gt;
Signed-off-by: Matthew DeVore &lt;matvore@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'dr/ref-filter-push-track-fix'</title>
<updated>2019-05-08T15:37:26Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-05-08T15:37:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f560a4d1598106258f43d0d5cc04cae3e6aa93e2'/>
<id>urn:sha1:f560a4d1598106258f43d0d5cc04cae3e6aa93e2</id>
<content type='text'>
%(push:track) token used in the --format option to "git
for-each-ref" and friends was not showing the right branch, which
has been fixed.

* dr/ref-filter-push-track-fix:
  ref-filter: use correct branch for %(push:track)
</content>
</entry>
<entry>
<title>ref-filter: add worktreepath atom</title>
<updated>2019-05-07T04:45:53Z</updated>
<author>
<name>Nickolai Belakovski</name>
<email>nbelakovski@gmail.com</email>
</author>
<published>2019-04-29T05:19:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2582083fa1830632e298727e973440907345267f'/>
<id>urn:sha1:2582083fa1830632e298727e973440907345267f</id>
<content type='text'>
Add an atom providing the path of the linked worktree where this ref is
checked out, if it is checked out in any linked worktrees, and empty
string otherwise.

Signed-off-by: Nickolai Belakovski &lt;nbelakovski@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>ref-filter: use correct branch for %(push:track)</title>
<updated>2019-04-18T00:17:41Z</updated>
<author>
<name>Damien Robert</name>
<email>damien.olivier.robert+git@gmail.com</email>
</author>
<published>2019-04-16T12:16:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c646d0934ec2056d816ad1ecc23f6620aba2c6da'/>
<id>urn:sha1:c646d0934ec2056d816ad1ecc23f6620aba2c6da</id>
<content type='text'>
In ref-filter.c, when processing the atom %(push:track), the
ahead/behind values are computed using `stat_tracking_info` which refers
to the upstream branch.

Fix that by introducing a new flag `for_push` in `stat_tracking_info`
in remote.c, which does the same thing but for the push branch.
Update the few callers of `stat_tracking_info` to handle this flag. This
ensure that whenever we use this function in the future, we are careful
to specify is this should apply to the upstream or the push branch.

This bug was not detected in t/t6300-for-each-ref.sh because in the test
for push:track, both the upstream and the push branches were behind by 1
from the local branch. Change the test so that the upstream branch is
behind by 1 while the push branch is ahead by 1. This allows us to test
that %(push:track) refers to the correct branch.

This changes the expected value of some following tests (by introducing
new references), so update them too.

Signed-off-by: Damien Robert &lt;damien.olivier.robert+git@gmail.com&gt;
Reviewed-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
