<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.c, branch v2.48.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.48.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.48.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-12-23T17:32:11Z</updated>
<entry>
<title>Merge branch 'ps/build-sign-compare'</title>
<updated>2024-12-23T17:32:11Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-12-23T17:32:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4156b6a741c7fb15a4eccb320612fb6e453f439c'/>
<id>urn:sha1:4156b6a741c7fb15a4eccb320612fb6e453f439c</id>
<content type='text'>
Start working to make the codebase buildable with -Wsign-compare.

* ps/build-sign-compare:
  t/helper: don't depend on implicit wraparound
  scalar: address -Wsign-compare warnings
  builtin/patch-id: fix type of `get_one_patchid()`
  builtin/blame: fix type of `length` variable when emitting object ID
  gpg-interface: address -Wsign-comparison warnings
  daemon: fix type of `max_connections`
  daemon: fix loops that have mismatching integer types
  global: trivial conversions to fix `-Wsign-compare` warnings
  pkt-line: fix -Wsign-compare warning on 32 bit platform
  csum-file: fix -Wsign-compare warning on 32-bit platform
  diff.h: fix index used to loop through unsigned integer
  config.mak.dev: drop `-Wno-sign-compare`
  global: mark code units that generate warnings with `-Wsign-compare`
  compat/win32: fix -Wsign-compare warning in "wWinMain()"
  compat/regex: explicitly ignore "-Wsign-compare" warnings
  git-compat-util: introduce macros to disable "-Wsign-compare" warnings
</content>
</entry>
<entry>
<title>global: mark code units that generate warnings with `-Wsign-compare`</title>
<updated>2024-12-06T11:20:02Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-06T10:27:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=41f43b8243f42b9df2e98be8460646d4c0100ad3'/>
<id>urn:sha1:41f43b8243f42b9df2e98be8460646d4c0100ad3</id>
<content type='text'>
Mark code units that generate warnings with `-Wsign-compare`. This
allows for a structured approach to get rid of all such warnings over
time in a way that can be easily measured.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: refactor `repair_worktree_after_gitdir_move()`</title>
<updated>2024-12-02T00:36:18Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:23:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2037ca85ad93ec905b46543df6df4080f6ca258b'/>
<id>urn:sha1:2037ca85ad93ec905b46543df6df4080f6ca258b</id>
<content type='text'>
This refactors `repair_worktree_after_gitdir_move()` to use the new
`write_worktree_linking_files` function. It also preserves the
relativity of the linking files; e.g., if an existing worktree used
absolute paths then the repaired paths will be absolute (and visa-versa).
`repair_worktree_after_gitdir_move()` is used to repair both sets of
worktree linking files if the `.git` directory is moved during a
re-initialization using `git init`.

This also adds a test case for reinitializing a repository that has
relative worktrees.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: add relative cli/config options to `repair` command</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:23:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e6df1ee2c13405ef7077256fef49424f69d61125'/>
<id>urn:sha1:e6df1ee2c13405ef7077256fef49424f69d61125</id>
<content type='text'>
This teaches the `worktree repair` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree with an absolute path is repaired
with `--relative-paths`, the links will be replaced with relative paths,
even if the original path was correct. This allows a user to covert
existing worktrees between absolute/relative as desired.

To simplify things, both linking files are written when one of the files
needs to be repaired. In some cases, this fixes the other file before it
is checked, in other cases this results in a correct file being written
with the same contents.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: add relative cli/config options to `move` command</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:23:03Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=298d2917e26520791b47ba5d38c1866e21894cc7'/>
<id>urn:sha1:298d2917e26520791b47ba5d38c1866e21894cc7</id>
<content type='text'>
This teaches the `worktree move` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree is moved with `--relative-paths`
the new path will be relative (and visa-versa).

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: add `write_worktree_linking_files()` function</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:22:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4dac9e3c01cf056edd315e0ed26e6df1c4d94571'/>
<id>urn:sha1:4dac9e3c01cf056edd315e0ed26e6df1c4d94571</id>
<content type='text'>
A new helper function, `write_worktree_linking_files()`, centralizes
the logic for computing and writing either relative or absolute
paths, based on the provided configuration. This function accepts
`strbuf` pointers to both the worktree’s `.git` link and the
repository’s `gitdir`, and then writes the appropriate path to each.
The `relativeWorktrees` extension is automatically set when a worktree
is linked with relative paths.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: refactor infer_backlink return</title>
<updated>2024-12-02T00:36:16Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:22:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5976310916458868b5cbd9d8c7cc7de5af418230'/>
<id>urn:sha1:5976310916458868b5cbd9d8c7cc7de5af418230</id>
<content type='text'>
The previous round[1] was merged a bit early before reviewer feedback
could be applied. This correctly indents a code block and updates the
`infer_backlink` function to return `-1` on failure and strbuf.len on
success.

[1]: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: link worktrees with relative paths</title>
<updated>2024-10-08T18:49:22Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-10-08T03:12:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=717af916cd69d2565aa2a7b7d73d895aa92ff392'/>
<id>urn:sha1:717af916cd69d2565aa2a7b7d73d895aa92ff392</id>
<content type='text'>
Git currently stores absolute paths to both the main repository and
linked worktrees. However, this causes problems when moving repositories
or working in containerized environments where absolute paths differ
between systems. The worktree links break, and users are required to
manually execute `worktree repair` to repair them, leading to workflow
disruptions. Additionally, mapping repositories inside of containerized
environments renders the repository unusable inside the containers, and
this is not repairable as repairing the worktrees inside the containers
will result in them being broken outside the containers.

To address this, this patch makes Git always write relative paths when
linking worktrees. Relative paths increase the resilience of the
worktree links across various systems and environments, particularly
when the worktrees are self-contained inside the main repository (such
as when using a bare repository with worktrees). This improves
portability, workflow efficiency, and reduces overall breakages.

Although Git now writes relative paths, existing repositories with
absolute paths are still supported. There are no breaking changes
to workflows based on absolute paths, ensuring backward compatibility.

At a low level, the changes involve modifying functions in `worktree.c`
and `builtin/worktree.c` to use `relative_path()` when writing the
worktree’s `.git` file and the main repository’s `gitdir` reference.
Instead of hardcoding absolute paths, Git now computes the relative path
between the worktree and the repository, ensuring that these links are
portable. Locations where these respective file are read have also been
updated to properly handle both absolute and relative paths. Generally,
relative paths are always resolved into absolute paths before any
operations or comparisons are performed.

Additionally, `repair_worktrees_after_gitdir_move()` has been introduced
to address the case where both the `&lt;worktree&gt;/.git` and
`&lt;repo&gt;/worktrees/&lt;id&gt;/gitdir` links are broken after the gitdir is
moved (such as during a re-initialization). This function repairs both
sides of the worktree link using the old gitdir path to reestablish the
correct paths after a move.

The `worktree.path` struct member has also been updated to always store
the absolute path of a worktree. This ensures that worktree consumers
never have to worry about trying to resolve the absolute path themselves.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: refactor infer_backlink() to use *strbuf</title>
<updated>2024-10-08T18:49:21Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-10-08T03:12:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bb4a883584ab13500921325617e022142633e53a'/>
<id>urn:sha1:bb4a883584ab13500921325617e022142633e53a</id>
<content type='text'>
This lays the groundwork for the next patch, which needs the backlink
returned from infer_backlink() as a `strbuf`. It seemed inefficient to
convert from `strbuf` to `char*` and back to `strbuf` again.

This refactors infer_backlink() to return an integer result and use a
pre-allocated `strbuf` for the inferred backlink path, replacing the
previous `char*` return type and improving efficiency.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative</title>
<updated>2024-10-08T18:49:13Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-10-08T18:49:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=58d8805de246352b41ca7bfd6cd70078b94ff1f1'/>
<id>urn:sha1:58d8805de246352b41ca7bfd6cd70078b94ff1f1</id>
<content type='text'>
* es/worktree-repair-copied:
  worktree: repair copied repository and linked worktrees
</content>
</entry>
</feed>
