<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.c, branch v2.15.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.15.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.15.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2017-10-21T12:30:07Z</updated>
<entry>
<title>worktree: handle broken symrefs in find_shared_symref()</title>
<updated>2017-10-21T12:30:07Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-10-19T17:49:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dbd2b55cb7b06e94096b8c18852a94732e3f76a8'/>
<id>urn:sha1:dbd2b55cb7b06e94096b8c18852a94732e3f76a8</id>
<content type='text'>
The refs_resolve_ref_unsafe() function may return NULL even
with a REF_ISSYMREF flag if a symref points to a broken ref.
As a result, it's possible for find_shared_symref() to
segfault when it passes NULL to strcmp().

This is hard to trigger for most code paths. We typically
pass HEAD to the function as the symref to resolve, and
programs like "git branch" will bail much earlier if HEAD
isn't valid.

I did manage to trigger it through one very obscure
sequence:

  # You have multiple notes refs which conflict.
  git notes add -m base
  git notes --ref refs/notes/foo add -m foo

  # There's left-over cruft in NOTES_MERGE_REF that
  # makes it a broken symref (in this case we point
  # to a syntactically invalid ref).
  echo "ref: refs/heads/master.lock" &gt;.git/NOTES_MERGE_REF

  # You try to merge the notes. We read the broken value in
  # order to complain that another notes-merge is
  # in-progress, but we segfault in find_shared_symref().
  git notes merge refs/notes/foo

This is obviously silly and almost certainly impossible to
trigger accidentally, but it does show that the bug is
triggerable from at least one code path. In addition, it
would trigger if we saw a transient filesystem error when
resolving the pointed-to ref.

We can fix this by treating NULL the same as a non-matching
symref. Arguably we'd prefer to know if a symref points to
"refs/heads/foo", but "refs/heads/foo" is broken. But
refs_resolve_ref_unsafe() isn't capable of giving us that
information, so this is the best we can do.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed</title>
<updated>2017-09-24T01:18:18Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-09-23T09:44:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e691b027b60034ed3362fc4d6065b6be85bf234b'/>
<id>urn:sha1:e691b027b60034ed3362fc4d6065b6be85bf234b</id>
<content type='text'>
This allows us to get rid of two write-only variables, one of them
being a SHA1 buffer.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'nd/prune-in-worktree'</title>
<updated>2017-09-19T01:47:53Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-09-19T01:47:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8a044c7f1d56cef657be342e40de0795d688e882'/>
<id>urn:sha1:8a044c7f1d56cef657be342e40de0795d688e882</id>
<content type='text'>
"git gc" and friends when multiple worktrees are used off of a
single repository did not consider the index and per-worktree refs
of other worktrees as the root for reachability traversal, making
objects that are in use only in other worktrees to be subject to
garbage collection.

* nd/prune-in-worktree:
  refs.c: reindent get_submodule_ref_store()
  refs.c: remove fallback-to-main-store code get_submodule_ref_store()
  rev-list: expose and document --single-worktree
  revision.c: --reflog add HEAD reflog from all worktrees
  files-backend: make reflog iterator go through per-worktree reflog
  revision.c: --all adds HEAD from all worktrees
  refs: remove dead for_each_*_submodule()
  refs.c: move for_each_remote_ref_submodule() to submodule.c
  revision.c: use refs_for_each*() instead of for_each_*_submodule()
  refs: add refs_head_ref()
  refs: move submodule slash stripping code to get_submodule_ref_store
  refs.c: refactor get_submodule_ref_store(), share common free block
  revision.c: --indexed-objects add objects from all worktrees
  revision.c: refactor add_index_objects_to_pending()
  refs.c: use is_dir_sep() in resolve_gitlink_ref()
  revision.h: new flag in struct rev_info wrt. worktree-related refs
</content>
</entry>
<entry>
<title>Merge branch 'nd/worktree-kill-parse-ref'</title>
<updated>2017-09-10T08:08:24Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-09-10T08:08:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=79553b94f966f3cec6156a68001650ca26a584c4'/>
<id>urn:sha1:79553b94f966f3cec6156a68001650ca26a584c4</id>
<content type='text'>
"git branch -M a b" while on a branch that is completely unrelated
to either branch a or branch b misbehaved when multiple worktree
was in use.  This has been fixed.

* nd/worktree-kill-parse-ref:
  branch: fix branch renaming not updating HEADs correctly
</content>
</entry>
<entry>
<title>revision.c: --all adds HEAD from all worktrees</title>
<updated>2017-08-24T21:56:43Z</updated>
<author>
<name>Nguyễn Thái Ngọc Duy</name>
<email>pclouds@gmail.com</email>
</author>
<published>2017-08-23T12:36:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d0c39a49ccb5dfe7feba4325c3374d99ab123c59'/>
<id>urn:sha1:d0c39a49ccb5dfe7feba4325c3374d99ab123c59</id>
<content type='text'>
Unless single_worktree is set, --all now adds HEAD from all worktrees.

Since reachable.c code does not use setup_revisions(), we need to call
other_head_refs_submodule() explicitly there to have the same effect on
"git prune", so that we won't accidentally delete objects needed by some
other HEADs.

A new FIXME is added because we would need something like

    int refs_other_head_refs(struct ref_store *, each_ref_fn, cb_data);

in addition to other_head_refs() to handle it, which might require

    int get_submodule_worktrees(const char *submodule, int flags);

It could be a separate topic to reduce the scope of this one.

Signed-off-by: Nguyễn Thái Ngọc Duy &lt;pclouds@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>branch: fix branch renaming not updating HEADs correctly</title>
<updated>2017-08-24T21:15:18Z</updated>
<author>
<name>Nguyễn Thái Ngọc Duy</name>
<email>pclouds@gmail.com</email>
</author>
<published>2017-08-24T10:41:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=31824d180d4f975e6b130cd9a33a9a0baef3d7ca'/>
<id>urn:sha1:31824d180d4f975e6b130cd9a33a9a0baef3d7ca</id>
<content type='text'>
There are two bugs that sort of work together and cause
problems. Let's start with one in replace_each_worktree_head_symref.

Before fa099d2322 (worktree.c: kill parse_ref() in favor of
refs_resolve_ref_unsafe() - 2017-04-24), this code looks like this:

    if (strcmp(oldref, worktrees[i]-&gt;head_ref))
            continue;
    set_worktree_head_symref(...);

After fa099d2322, it is possible that head_ref can be NULL. However,
the updated code takes the wrong exit. In the error case (NULL
head_ref), we should "continue;" to the next worktree. The updated
code makes us _skip_ "continue;" and update HEAD anyway.

The NULL head_ref is triggered by the second bug in add_head_info (in
the same commit). With the flag RESOLVE_REF_READING, resolve_ref_unsafe()
will abort if it cannot resolve the target ref. For orphan checkouts,
HEAD always points to an unborned branch, resolving target ref will
always fail. Now we have NULL head_ref. Now we always update HEAD.

Correct the logic in replace_ function so that we don't accidentally
update HEAD on error. As it turns out, correcting the logic bug above
breaks branch renaming completely, thanks to the second bug.

"git branch -[Mm]" does two steps (on a normal checkout, no orphan!):

 - rename the branch on disk (e.g. refs/heads/abc to refs/heads/def)
 - update HEAD if it points to the branch being renamed.

At the second step, since the branch pointed to by HEAD (e.g. "abc") no
longer exists on disk, we run into a temporary orphan checkout situation
that has been just corrected to _not_ update HEAD. But we need to update
HEAD since it's not actually an orphan checkout. We need to update HEAD
to move out of that orphan state.

Correct add_head_info(), remove RESOLVE_REF_READING flag. With the flag
gone, we should always return good "head_ref" in orphan checkouts (either
temporary or permanent). With good head_ref, things start to work again.

Noticed-by: Nish Aravamudan &lt;nish.aravamudan@canonical.com&gt;
Signed-off-by: Nguyễn Thái Ngọc Duy &lt;pclouds@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>path: convert strbuf_git_common_path to take a 'struct repository'</title>
<updated>2017-06-24T01:24:34Z</updated>
<author>
<name>Brandon Williams</name>
<email>bmwill@google.com</email>
</author>
<published>2017-06-22T18:43:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b337172c834b854903fb523416b53fe354b6e2a5'/>
<id>urn:sha1:b337172c834b854903fb523416b53fe354b6e2a5</id>
<content type='text'>
Signed-off-by: Brandon Williams &lt;bmwill@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'js/plug-leaks'</title>
<updated>2017-05-29T03:34:44Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-05-29T03:34:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=849e671b52e11d4a2f70d577dd2c806f3ca756fe'/>
<id>urn:sha1:849e671b52e11d4a2f70d577dd2c806f3ca756fe</id>
<content type='text'>
Fix memory leaks pointed out by Coverity (and people).

* js/plug-leaks: (26 commits)
  checkout: fix memory leak
  submodule_uses_worktrees(): plug memory leak
  show_worktree(): plug memory leak
  name-rev: avoid leaking memory in the `deref` case
  remote: plug memory leak in match_explicit()
  add_reflog_for_walk: avoid memory leak
  shallow: avoid memory leak
  line-log: avoid memory leak
  receive-pack: plug memory leak in update()
  fast-export: avoid leaking memory in handle_tag()
  mktree: plug memory leaks reported by Coverity
  pack-redundant: plug memory leak
  setup_discovered_git_dir(): plug memory leak
  setup_bare_git_dir(): help static analysis
  split_commit_in_progress(): simplify &amp; fix memory leak
  checkout: fix memory leak
  cat-file: fix memory leak
  mailinfo &amp; mailsplit: check for EOF while parsing
  status: close file descriptor after reading git-rebase-todo
  difftool: address a couple of resource/memory leaks
  ...
</content>
</entry>
<entry>
<title>Merge branch 'nd/worktree-kill-parse-ref'</title>
<updated>2017-05-16T02:51:51Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-05-16T02:51:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4b44b7b1df44d371eaf3fbed75829d1a749bc7df'/>
<id>urn:sha1:4b44b7b1df44d371eaf3fbed75829d1a749bc7df</id>
<content type='text'>
"git gc" did not interact well with "git worktree"-managed
per-worktree refs.

* nd/worktree-kill-parse-ref:
  refs: kill set_worktree_head_symref()
  worktree.c: kill parse_ref() in favor of refs_resolve_ref_unsafe()
  refs: introduce get_worktree_ref_store()
  refs: add REFS_STORE_ALL_CAPS
  refs.c: make submodule ref store hashmap generic
  environment.c: fix potential segfault by get_git_common_dir()
</content>
</entry>
<entry>
<title>submodule_uses_worktrees(): plug memory leak</title>
<updated>2017-05-08T03:18:20Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2017-05-04T13:59:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d32de66a07c600c14f70e6d435f8f9c496b0d625'/>
<id>urn:sha1:d32de66a07c600c14f70e6d435f8f9c496b0d625</id>
<content type='text'>
There is really no reason why we would need to hold onto the allocated
string longer than necessary.

Reported by Coverity.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
