<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.c, branch v2.32.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.32.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.32.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-05-12T23:45:03Z</updated>
<entry>
<title>dir: introduce readdir_skip_dot_and_dotdot() helper</title>
<updated>2021-05-12T23:45:03Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2021-05-12T17:28:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b548f0f1568f6b01e55ca69c24d3cb19489f92aa'/>
<id>urn:sha1:b548f0f1568f6b01e55ca69c24d3cb19489f92aa</id>
<content type='text'>
Many places in the code were doing
    while ((d = readdir(dir)) != NULL) {
        if (is_dot_or_dotdot(d-&gt;d_name))
            continue;
        ...process d...
    }
Introduce a readdir_skip_dot_and_dotdot() helper to make that a one-liner:
    while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
        ...process d...
    }

This helper particularly simplifies checks for empty directories.

Also use this helper in read_cached_dir() so that our statistics are
consistent across platforms.  (In other words, read_cached_dir() should
have been using is_dot_or_dotdot() and skipping such entries, but did
not and left it to treat_path() to detect and mark such entries as
path_none.)

Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>use CALLOC_ARRAY</title>
<updated>2021-03-14T00:00:09Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2021-03-13T16:17:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ca56dadb4b65ccaeab809d80db80a312dc00941a'/>
<id>urn:sha1:ca56dadb4b65ccaeab809d80db80a312dc00941a</id>
<content type='text'>
Add and apply a semantic patch for converting code that open-codes
CALLOC_ARRAY to use it instead.  It shortens the code and infers the
element size automatically.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: teach worktree_lock_reason() to gently handle main worktree</title>
<updated>2021-01-30T17:57:20Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-19T21:27:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=eb36135af7b03fbaab2d3091fa7f5c62a164ff43'/>
<id>urn:sha1:eb36135af7b03fbaab2d3091fa7f5c62a164ff43</id>
<content type='text'>
worktree_lock_reason() aborts with an assertion failure when called on
the main worktree since locking the main worktree is nonsensical. Not
only is this behavior undocumented, thus callers might not even be aware
that the call could potentially crash the program, but it also forces
clients to be extra careful:

    if (!is_main_worktree(wt) &amp;&amp; worktree_locked_reason(...))
        ...

Since we know that locking makes no sense in the context of the main
worktree, we can simply return false for the main worktree, thus making
client code less complex by eliminating the need for the callers to have
inside knowledge about the implementation:

    if (worktree_lock_reason(...))
        ...

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-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 worktree to lazy-load "prunable" reason</title>
<updated>2021-01-30T17:57:16Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-19T21:27:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=fc0c7d5e9e9e396afdd669019e7635773b1d1423'/>
<id>urn:sha1:fc0c7d5e9e9e396afdd669019e7635773b1d1423</id>
<content type='text'>
Add worktree_prune_reason() to allow a caller to discover whether a
worktree is prunable and the reason that it is, much like
worktree_lock_reason() indicates whether a worktree is locked and the
reason for the lock. As with worktree_lock_reason(), retrieve the
prunable reason lazily and cache it in the `worktree` structure.

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: libify should_prune_worktree()</title>
<updated>2021-01-30T17:57:08Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-19T21:27:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a29a8b7574ab34026252691933f462eddc59146a'/>
<id>urn:sha1:a29a8b7574ab34026252691933f462eddc59146a</id>
<content type='text'>
As part of teaching "git worktree list" to annotate worktree that is a
candidate for pruning, let's move should_prune_worktree() from
builtin/worktree.c to worktree.c in order to make part of the worktree
public API.

should_prune_worktree() knows how to select the given worktree for
pruning based on an expiration date, however the expiration value is
stored in a static file-scope variable and it is not local to the
function. In order to move the function, teach should_prune_worktree()
to take the expiration date as an argument and document the new
parameter that is not immediately obvious.

Also, change the function comment to clearly state that the worktree's
path is returned in `wtpath` argument.

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-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 multi-directional breakage</title>
<updated>2020-12-21T21:44:28Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-12-21T08:16:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cf76baea41bb7f6431dbfa5744c861fdb844d20b'/>
<id>urn:sha1:cf76baea41bb7f6431dbfa5744c861fdb844d20b</id>
<content type='text'>
`git worktree repair` knows how to repair the two-way links between the
repository and a worktree as long as a link in one or the other
direction is sound. For instance, if a linked worktree is moved (without
using `git worktree move`), repair is possible because the worktree
still knows the location of the repository even though the repository no
longer knows where the worktree is. Similarly, if the repository is
moved, repair is possible since the repository still knows the locations
of the worktrees even though the worktrees no longer know where the
repository is.

However, if both the repository and the worktrees are moved, then links
are severed in both directions, and no repair is possible. This is the
case even when the new worktree locations are specified as arguments to
`git worktree repair`. The reason for this limitation is twofold. First,
when `repair` consults the worktree's gitfile (/path/to/worktree/.git)
to determine the corresponding &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file to fix,
&lt;repo&gt; is the old path to the repository, thus it is unable to fix the
`gitdir` file at its new location since it doesn't know where it is.
Second, when `repair` consults &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir to find the
location of the worktree's gitfile (/path/to/worktree/.git), the path
recorded in `gitdir` is the old location of the worktree's gitfile, thus
it is unable to repair the gitfile since it doesn't know where it is.

Fix these shortcomings by teaching `repair` to attempt to infer the new
location of the &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file when the location
recorded in the worktree's gitfile has become stale but the file is
otherwise well-formed. The inference is intentionally simple-minded.
For each worktree path specified as an argument, `git worktree repair`
manually reads the ".git" gitfile at that location and, if it is
well-formed, extracts the &lt;id&gt;. It then searches for a corresponding
&lt;id&gt; in &lt;repo&gt;/worktrees/ and, if found, concludes that there is a
reasonable match and updates &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir to point at
the specified worktree path. In order for &lt;repo&gt; to be known, `git
worktree repair` must be run in the main worktree or bare repository.

`git worktree repair` first attempts to repair each incoming
/path/to/worktree/.git gitfile to point at the repository, and then
attempts to repair outgoing &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir files to point
at the worktrees. This sequence was chosen arbitrarily when originally
implemented since the order of fixes is immaterial as long as one side
of the two-way link between the repository and a worktree is sound.
However, for this new repair technique to work, the order must be
reversed. This is because the new inference mechanism, when it is
successful, allows the outgoing &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file to be
repaired, thus fixing one side of the two-way link. Once that side is
fixed, the other side can be fixed by the existing repair mechanism,
hence the order of repairs is now significant.

Two safeguards are employed to avoid hijacking a worktree from a
different repository if the user accidentally specifies a foreign
worktree as an argument. The first, as described above, is that it
requires an &lt;id&gt; match between the repository and the worktree. That
itself is not foolproof for preventing hijack, so the second safeguard
is that the inference will only kick in if the worktree's
/path/to/worktree/.git gitfile does not point at a repository.

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>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>
</feed>
