<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.c, branch v2.30.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.30.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.30.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2020-10-05T21:01:52Z</updated>
<entry>
<title>Merge branch 'ma/worktree-cleanups'</title>
<updated>2020-10-05T21:01:52Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-10-05T21:01:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=07601b5b360264a74f94d74640999ea19cf61517'/>
<id>urn:sha1:07601b5b360264a74f94d74640999ea19cf61517</id>
<content type='text'>
Code clean-up.

* ma/worktree-cleanups:
  worktree: use skip_prefix to parse target
  worktree: rename copy-pasted variable
  worktree: update renamed variable in comment
  worktree: inline `worktree_ref()` into its only caller
  wt-status: introduce wt_status_state_free_buffers()
  wt-status: print to s-&gt;fp, not stdout
  wt-status: replace sha1 mentions with oid
</content>
</entry>
<entry>
<title>worktree: use skip_prefix to parse target</title>
<updated>2020-09-27T21:21:47Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2020-09-27T13:15:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a46d1f732192a8621ead7ea5c4a3ca391ad881cb'/>
<id>urn:sha1:a46d1f732192a8621ead7ea5c4a3ca391ad881cb</id>
<content type='text'>
Instead of checking for "refs/heads/" using `starts_with()`, then
skipping past "refs/heads/" using `strlen()`, just use `skip_prefix()`.

In `is_worktree_being_rebased()`, we can adjust the indentation while
we're here and lose a pair of parentheses which isn't needed and which
might even make the reader wonder what they're missing and why that
grouping is there.

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>worktree: rename copy-pasted variable</title>
<updated>2020-09-27T21:21:47Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2020-09-27T13:15:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=fb07bd42975bcbfbc29d4a3ef1bff1039a469336'/>
<id>urn:sha1:fb07bd42975bcbfbc29d4a3ef1bff1039a469336</id>
<content type='text'>
As the commit message of 04a3dfb8b5 ("worktree.c: check whether branch
is bisected in another worktree", 2016-04-22) indicates, the function
`is_worktree_being_bisected()` is based on the older function
`is_worktree_being_rebased()`. This heritage can also be seen in the
name of the variable where we store our return value: It was never
adapted while copy-editing and remains as `found_rebase`.

Rename the variable to make clear that we're looking for a bisect(ion),
nothing else.

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>worktree: update renamed variable in comment</title>
<updated>2020-09-27T21:21:47Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2020-09-27T13:15:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cfaf9f05c6174b520082036c0f1439adf9c4fbf7'/>
<id>urn:sha1:cfaf9f05c6174b520082036c0f1439adf9c4fbf7</id>
<content type='text'>
The comment above `add_head_info()` mentions "head_sha1", but it was
renamed to "head_oid" in 0f05154c70 ("worktree: convert struct worktree
to object_id", 2017-10-15). Update the comment.

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>worktree: inline `worktree_ref()` into its only caller</title>
<updated>2020-09-27T21:21:47Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2020-09-27T13:15:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ef2d5547fa342197befd4be599438d7a7fa41e04'/>
<id>urn:sha1:ef2d5547fa342197befd4be599438d7a7fa41e04</id>
<content type='text'>
We have `strbuf_worktree_ref()`, which works on a strbuf, and a wrapper
for it, `worktree_ref()` which returns a string. We even make this
wrapper available through worktree.h. But it only has a single caller,
sitting right next to it in worktree.c.

Just inline the wrapper into its only caller. This means the caller can
quite naturally reuse a single strbuf. We currently achieve something
similar by having a static strbuf in the wrapper.

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>wt-status: introduce wt_status_state_free_buffers()</title>
<updated>2020-09-27T21:21:47Z</updated>
<author>
<name>Martin Ågren</name>
<email>martin.agren@gmail.com</email>
</author>
<published>2020-09-27T13:15:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=962dd7ebc3e76afc2c896d377c319f8140966303'/>
<id>urn:sha1:962dd7ebc3e76afc2c896d377c319f8140966303</id>
<content type='text'>
When we have a `struct wt_status_state`, we manually free its `branch`,
`onto` and `detached_from`, or sometimes just one or two of them.
Provide a function `wt_status_state_free_buffers()` which does the
freeing.

The callers are still aware of these fields, e.g., they check whether
`branch` was populated or not. But this way, they don't need to know
about *all* of them, and if `struct wt_status_state` gets more fields,
they will not need to learn to free them.

Users of `struct wt_status` (which contains a `wt_status_state`) already
have `wt_status_collect_free_buffers()` (corresponding to
`wt_status_collect()`) which we can also teach to use this new helper.

Finally, note that we're currently leaving dangling pointers behind.
Some callers work on a stack-allocated struct, where this is obviously
ok. But for the users of `run_status()` in builtin/commit.c, there are
ample opportunities for someone to mistakenly use those dangling
pointers. We seem to be ok for now, but it's a use-after-free waiting to
happen. Let's leave NULL-pointers behind instead.

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>worktree: teach "repair" to fix outgoing links to worktrees</title>
<updated>2020-08-31T18:47:45Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-08-31T06:57:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b214ab5aa597e748c228e657d4eb7c18960e6a67'/>
<id>urn:sha1:b214ab5aa597e748c228e657d4eb7c18960e6a67</id>
<content type='text'>
The .git/worktrees/&lt;id&gt;/gitdir file points at the location of a linked
worktree's .git file. Its content must be of the form
/path/to/worktree/.git (from which the location of the worktree itself
can be derived by stripping the "/.git" suffix). If the gitdir file is
deleted or becomes corrupted or outdated, then Git will be unable to
find the linked worktree. An easy way for the gitdir file to become
outdated is for the user to move the worktree manually (without using
"git worktree move"). Although it is possible to manually update the
gitdir file to reflect the new linked worktree location, doing so
requires a level of knowledge about worktree internals beyond what a
user should be expected to know offhand.

Therefore, teach "git worktree repair" how to repair broken or outdated
.git/worktrees/&lt;id&gt;/gitdir files automatically. (For this to work, the
command must either be invoked from within the worktree whose gitdir
file requires repair, or from within the main or any linked worktree by
providing the path of the broken worktree as an argument to "git
worktree repair".)

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: teach "repair" to fix worktree back-links to main worktree</title>
<updated>2020-08-31T18:47:45Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-08-31T06:57:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bdd1f3e4da716012a52194cdfbc9c80dfdce87d4'/>
<id>urn:sha1:bdd1f3e4da716012a52194cdfbc9c80dfdce87d4</id>
<content type='text'>
The .git file in a linked worktree is a "gitfile" which points back to
the .git/worktrees/&lt;id&gt; entry in the main worktree or bare repository.
If a worktree's .git file is deleted or becomes corrupted or outdated,
then the linked worktree won't know how to find the repository or any of
its own administrative files (such as 'index', 'HEAD', etc.). An easy
way for the .git file to become outdated is for the user to move the
main worktree or bare repository. Although it is possible to manually
update each linked worktree's .git file to reflect the new repository
location, doing so requires a level of knowledge about worktree
internals beyond what a user should be expected to know offhand.

Therefore, teach "git worktree repair" how to repair broken or outdated
worktree .git files automatically. (For this to work, the command must
be invoked from within the main worktree or bare repository, or from
within a worktree which has not become disconnected from the repository
-- such as one which was created after the repository was moved.)

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: retire special-case normalization of main worktree path</title>
<updated>2020-08-01T02:56:11Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-07-31T23:32:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=918d8ff78099004c561e0da90fa04cd629bb3b0e'/>
<id>urn:sha1:918d8ff78099004c561e0da90fa04cd629bb3b0e</id>
<content type='text'>
In order for "git-worktree list" to present consistent results,
get_main_worktree() performs manual normalization on the repository
path (returned by get_common_dir()) after passing it through
strbuf_add_absolute_path(). In particular, it cleans up the path for
three distinct cases when the current working directory is (1) the main
worktree, (2) the .git/ subdirectory, or (3) a bare repository.

The need for such special-cases is a direct consequence of employing
strbuf_add_absolute_path() which, for the sake of efficiency, doesn't
bother normalizing the path (such as folding out redundant path
components) after making it absolute. Lack of normalization is not
typically a problem since redundant path elements make no difference
when working with paths at the filesystem level. However, when preparing
paths for presentation, possible redundant path components make it
difficult to ensure consistency.

Eliminate the need for these special cases by instead making the path
absolute via strbuf_add_real_path() which normalizes the path for us.
Once normalized, the only case we need to handle manually is converting
it to the path of the main worktree by stripping the "/.git" suffix.
This stripping of the "/.git" suffix is a regular idiom in
worktree-related code; for instance, it is employed by
get_linked_worktree(), as well.

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: drop bogus and unnecessary path munging</title>
<updated>2020-08-01T02:56:11Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-07-31T23:32:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1c4854ec7333f412cd60a5b673bb4f4e43319391'/>
<id>urn:sha1:1c4854ec7333f412cd60a5b673bb4f4e43319391</id>
<content type='text'>
The content of .git/worktrees/&lt;id&gt;/gitdir must be a path of the form
"/path/to/worktree/.git". Any other content would be indicative of a
corrupt "gitdir" file. To determine the path of the worktree itself one
merely strips the "/.git" suffix, and this is indeed how the worktree
path was determined from inception.

However, 5193490442 (worktree: add a function to get worktree details,
2015-10-08) extended the path manipulation in a mysterious way. If it is
unable to strip "/.git" from the path, then it instead reports the
current working directory as the linked worktree's path:

    if (!strbuf_strip_suffix(&amp;worktree_path, "/.git")) {
        strbuf_reset(&amp;worktree_path);
        strbuf_add_absolute_path(&amp;worktree_path, ".");
        strbuf_strip_suffix(&amp;worktree_path, "/.");
    }

This logic is clearly bogus; it can never be generally correct behavior.
It materialized out of thin air in 5193490442 with neither explanation
nor tests to illustrate a case in which it would be desirable.

It's possible that this logic was introduced to somehow deal with a
corrupt "gitdir" file, so that it returns _some_ sort of meaningful
value, but returning the current working directory is not helpful. In
fact, it is quite misleading (except in the one specific case when the
current directory is the worktree whose "gitdir" entry is corrupt).
Moreover, reporting the corrupt value to the user, rather than fibbing
about it and hiding it outright, is more helpful since it may aid in
diagnosing the problem.

Therefore, drop this bogus path munging and restore the logic to the
original behavior of merely stripping "/.git".

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
