<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/refs.h, branch v2.10.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.10.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.10.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2016-07-25T21:13:33Z</updated>
<entry>
<title>Merge branch 'mh/ref-iterators'</title>
<updated>2016-07-25T21:13:33Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-07-25T21:13:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=87492cb24d9d8be8e18217b89ae5f090089ff31d'/>
<id>urn:sha1:87492cb24d9d8be8e18217b89ae5f090089ff31d</id>
<content type='text'>
The API to iterate over all the refs (i.e. for_each_ref(), etc.)
has been revamped.

* mh/ref-iterators:
  for_each_reflog(): reimplement using iterators
  dir_iterator: new API for iterating over a directory tree
  for_each_reflog(): don't abort for bad references
  do_for_each_ref(): reimplement using reference iteration
  refs: introduce an iterator interface
  ref_resolves_to_object(): new function
  entry_resolves_to_object(): rename function from ref_resolves_to_object()
  get_ref_cache(): only create an instance if there is a submodule
  remote rm: handle symbolic refs correctly
  delete_refs(): add a flags argument
  refs: use name "prefix" consistently
  do_for_each_ref(): move docstring to the header file
  refs: remove unnecessary "extern" keywords
</content>
</entry>
<entry>
<title>refs: introduce an iterator interface</title>
<updated>2016-06-20T18:38:20Z</updated>
<author>
<name>Michael Haggerty</name>
<email>mhagger@alum.mit.edu</email>
</author>
<published>2016-06-18T04:15:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3bc581b9406e1e9a3f879d379106ee1e3bc48f5c'/>
<id>urn:sha1:3bc581b9406e1e9a3f879d379106ee1e3bc48f5c</id>
<content type='text'>
Currently, the API for iterating over references is via a family of
for_each_ref()-type functions that invoke a callback function for each
selected reference. All of these eventually call do_for_each_ref(),
which knows how to do one thing: iterate in parallel through two
ref_caches, one for loose and one for packed refs, giving loose
references precedence over packed refs. This is rather complicated code,
and is quite specialized to the files backend. It also requires callers
to encapsulate their work into a callback function, which often means
that they have to define and use a "cb_data" struct to manage their
context.

The current design is already bursting at the seams, and will become
even more awkward in the upcoming world of multiple reference storage
backends:

* Per-worktree vs. shared references are currently handled via a kludge
  in git_path() rather than iterating over each part of the reference
  namespace separately and merging the results. This kludge will cease
  to work when we have multiple reference storage backends.

* The current scheme is inflexible. What if we sometimes want to bypass
  the ref_cache, or use it only for packed or only for loose refs? What
  if we want to store symbolic refs in one type of storage backend and
  non-symbolic ones in another?

In the future, each reference backend will need to define its own way of
iterating over references. The crux of the problem with the current
design is that it is impossible to compose for_each_ref()-style
iterations, because the flow of control is owned by the for_each_ref()
function. There is nothing that a caller can do but iterate through all
references in a single burst, so there is no way for it to interleave
references from multiple backends and present the result to the rest of
the world as a single compound backend.

This commit introduces a new iteration primitive for references: a
ref_iterator. A ref_iterator is a polymorphic object that a reference
storage backend can be asked to instantiate. There are three functions
that can be applied to a ref_iterator:

* ref_iterator_advance(): move to the next reference in the iteration
* ref_iterator_abort(): end the iteration before it is exhausted
* ref_iterator_peel(): peel the reference currently being looked at

Iterating using a ref_iterator leaves the flow of control in the hands
of the caller, which means that ref_iterators from multiple
sources (e.g., loose and packed refs) can be composed and presented to
the world as a single compound ref_iterator.

It also means that the backend code for implementing reference iteration
will sometimes be more complicated. For example, the
cache_ref_iterator (which iterates over a ref_cache) can't use the C
stack to recurse; instead, it must manage its own stack internally as
explicit data structures. There is also a lot of boilerplate connected
with object-oriented programming in C.

Eventually, end-user callers will be able to be written in a more
natural way—managing their own flow of control rather than having to
work via callbacks. Since there will only be a few reference backends
but there are many consumers of this API, this is a good tradeoff.

More importantly, we gain composability, and especially the possibility
of writing interchangeable parts that can work with any ref_iterator.

For example, merge_ref_iterator implements a generic way of merging the
contents of any two ref_iterators. It is used to merge loose + packed
refs as part of the implementation of the files_ref_iterator. But it
will also be possible to use it to merge other pairs of reference
sources (e.g., per-worktree vs. shared refs).

Another example is prefix_ref_iterator, which can be used to trim a
prefix off the front of reference names before presenting them to the
caller (e.g., "refs/heads/master" -&gt; "master").

In this patch, we introduce the iterator abstraction and many utilities,
and implement a reference iterator for the files ref storage backend.
(I've written several other obvious utilities, for example a generic way
to filter references being iterated over. These will probably be useful
in the future. But they are not needed for this patch series, so I am
not including them at this time.)

In a moment we will rewrite do_for_each_ref() to work via reference
iterators (allowing some special-purpose code to be discarded), and do
something similar for reflogs. In future patch series, we will expose
the ref_iterator abstraction in the public refs API so that callers can
use it directly.

Implementation note: I tried abstracting this a layer further to allow
generic iterators (over arbitrary types of objects) and generic
utilities like a generic merge_iterator. But the implementation in C was
very cumbersome, involving (in my opinion) too much boilerplate and too
much unsafe casting, some of which would have had to be done on the
caller side. However, I did put a few iterator-related constants in a
top-level header file, iterator.h, as they will be useful in a moment to
implement iteration over directory trees and possibly other types of
iterators in the future.

Signed-off-by: Ramsay Jones &lt;ramsay@ramsayjones.plus.com&gt;
Signed-off-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>delete_refs(): add a flags argument</title>
<updated>2016-06-20T18:38:18Z</updated>
<author>
<name>Michael Haggerty</name>
<email>mhagger@alum.mit.edu</email>
</author>
<published>2016-06-18T04:15:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c5f04dddb6cf5f76adfe145de3565411711255b8'/>
<id>urn:sha1:c5f04dddb6cf5f76adfe145de3565411711255b8</id>
<content type='text'>
This will be useful for passing REF_NODEREF through.

Signed-off-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>refs: remove unnecessary "extern" keywords</title>
<updated>2016-06-13T09:35:32Z</updated>
<author>
<name>Michael Haggerty</name>
<email>mhagger@alum.mit.edu</email>
</author>
<published>2016-03-31T04:19:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1354c9b2ded11a2bc24e04b98268a5969b44c666'/>
<id>urn:sha1:1354c9b2ded11a2bc24e04b98268a5969b44c666</id>
<content type='text'>
There's continuing work in this area, so clean up unneeded "extern"
keywords rather than schlepping them around. Also split up some overlong
lines and add parameter names in a couple of places.

Signed-off-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
</content>
</entry>
<entry>
<title>refs.h: fix misspelt "occurred" in a comment</title>
<updated>2016-06-10T21:53:32Z</updated>
<author>
<name>Peter Colberg</name>
<email>peter@colberg.org</email>
</author>
<published>2016-06-10T19:05:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dc72b5006f29e98e8a394a3bcc14c7a03ffbcd5e'/>
<id>urn:sha1:dc72b5006f29e98e8a394a3bcc14c7a03ffbcd5e</id>
<content type='text'>
Signed-off-by: Peter Colberg &lt;peter@colberg.org&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>refs: add a new function set_worktree_head_symref</title>
<updated>2016-04-04T19:57:21Z</updated>
<author>
<name>Kazuki Yamaguchi</name>
<email>k@rhe.jp</email>
</author>
<published>2016-03-27T14:37:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2233066e778e32dfab0471ea2ad8d1c7a94b7e39'/>
<id>urn:sha1:2233066e778e32dfab0471ea2ad8d1c7a94b7e39</id>
<content type='text'>
Add a new function set_worktree_head_symref, to update HEAD symref for
the specified worktree.

To update HEAD of a linked working tree,
create_symref("worktrees/$work_tree/HEAD", "refs/heads/$branch", msg)
could be used. However when it comes to updating HEAD of the main
working tree, it is unusable because it uses $GIT_DIR for
worktree-specific symrefs (HEAD).

The new function takes git_dir (real directory) as an argument, and
updates HEAD of the working tree. This function will be used when
renaming a branch.

Signed-off-by: Kazuki Yamaguchi &lt;k@rhe.jp&gt;
Acked-by: David Turner &lt;dturner@twopensource.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'dt/initial-ref-xn-commit-doc'</title>
<updated>2016-02-26T21:37:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-26T21:37:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=69616f7436ed52476180f602727b387408266873'/>
<id>urn:sha1:69616f7436ed52476180f602727b387408266873</id>
<content type='text'>
* dt/initial-ref-xn-commit-doc:
  refs: document transaction semantics
</content>
</entry>
<entry>
<title>refs: document transaction semantics</title>
<updated>2016-02-25T20:35:31Z</updated>
<author>
<name>David Turner</name>
<email>dturner@twopensource.com</email>
</author>
<published>2016-02-25T20:05:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=49386868de1cebebfb1e9f9527560e17197ad94f'/>
<id>urn:sha1:49386868de1cebebfb1e9f9527560e17197ad94f</id>
<content type='text'>
Add some comments on ref transaction semantics to refs.h

Signed-off-by: David Turner &lt;dturner@twopensource.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>create_symref: modernize variable names</title>
<updated>2015-12-29T18:33:09Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-12-29T05:56:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b9badadd06ae307c5e1e0e7c36985a1360cabc22'/>
<id>urn:sha1:b9badadd06ae307c5e1e0e7c36985a1360cabc22</id>
<content type='text'>
Once upon a time, create_symref() was used only to point
HEAD at a branch name, and the variable names reflect that
(e.g., calling the path git_HEAD). However, it is much more
generic these days (and has been for some time). Let's
update the variable names to make it easier to follow:

  - `ref_target` is now just `refname`. This is closer to
    the `ref` that is already in `cache.h`, but with the
    extra twist that "name" makes it clear this is the name
    and not a ref struct. Dropping "target" hopefully makes
    it clear that we are talking about the symref itself,
    not what it points to.

  - `git_HEAD` is now `ref_path`; the on-disk path
    corresponding to `ref`.

  - `refs_heads_master` is now just `target`; i.e., what the
    symref points at. This term also matches what is in
    the symlink(2) manpage (at least on Linux).

  - the buffer to hold the symref file's contents was simply
    called `ref`. It's now `buf` (admittedly also generic,
    but at least not actively introducing confusion with the
    other variable holding the refname).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Reviewed-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hideRefs: add support for matching full refs</title>
<updated>2015-11-05T19:25:02Z</updated>
<author>
<name>Lukas Fleischer</name>
<email>lfleischer@lfos.de</email>
</author>
<published>2015-11-03T07:58:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=78a766ab6eaaa91c2638158bd4fda06a93291da0'/>
<id>urn:sha1:78a766ab6eaaa91c2638158bd4fda06a93291da0</id>
<content type='text'>
In addition to matching stripped refs, one can now add hideRefs
patterns that the full (unstripped) ref is matched against. To
distinguish between stripped and full matches, those new patterns
must be prefixed with a circumflex (^).

This commit also removes support for the undocumented and unintended
hideRefs settings ".have" (suppressing all "have" lines) and
"capabilities^{}" (suppressing the capabilities line).

Signed-off-by: Lukas Fleischer &lt;lfleischer@lfos.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
