The changes in this commit optimize the sorting of virtual branch files
by pre-computing the index positions of the ownership claims for each
file path. This improves the performance of the sorting operation by
avoiding the need to repeatedly search for the index positions during
the comparison step.
With 1900 hunks in a vbranch, I've found that this helps reduce the run time from 9 seconds down to just 5.
I considered not sorting at all if we didn't have any branches, but this didn't provide any substantial change in performance.
this is a cli convinience tool for listing and restoring gitbutler snapshots even if the app can't start or if it's hung. of course this can be done with plain git, but this is more convinient
In the future we could add more functionality to it
- drop "double lock across branches" test because it can't happen
- save correct tree when updating branch states
- use correct integration commit when updating base branch
this adds backend functions in Rust to do the following:
* move file hunks between commits (basic)
* undo any commit in a stack
* insert a blank commit
* move a commit within the stack
* update a commit message in place
Until `perist()` is truly atomic also on Windows, and modelled
[after Git](https://github.com/git/git/blob/master/compat/mingw.c#L2159-L2209),
sans the retries, it seems to work to just perform ordinary writes.
Before going there though, we try to call `sync_all()` on Windows to truly
finish the operation. On Unix, a rename is already supposed to be atomic.
GB writes files atomically and in the end it boils down to allocating bytes
and writing them all at once.
Now this capability lives in the `fs` module.
Instead, respect the existing bit if set in Git, but do not try
to derive it from the filesystem which is something Git doesn't
seem to be doing on Windows either.
This also makes me think that `gitoxide` should make it easy
to build a tree from a file and deal with this.
This will prevent half-written content on disk in case the write is interrupted.
Lock files are *not* used as the assumption is that a lock is held centrally.
We still need to fix the off-by-one bug affecting hunk end lines. When we add start_line + line_count we end up with an extra line. For example, with start_line 1, and line_count 1, the range is 1:1, not 1:2.
- replaces commit walking with a git blame
- limited to specific hunk lines
- earliest_commit set to default target
- lock if any blame other than boundary commit
- intersection uses context lines
Sometimes, symbolic refs are used as tracking branches, like
`refs/remotes/origin/HEAD`, and after some changes are dangling,
pointing to a ref which doesn't exist anymore (maybe it was renamed
from `master` to `main`).
Now, this isn't fatal anymore, but will be logged instead.
In the previous commit it was stated that the 'unfolding' of errors might
have been intentional to surface root causes of error messages.
However, this might have been wrong, and this commit brings back root-causes explicitly,
while erroring on the side of caution. That is, "Something went wrong" probably won't
be shown anymore, instead, possibly too much will be displayed and we'd rather tune
that down once it becomes clear which messages are needed, or should be improved.
Overall, I think it's best to show more, and then tune errors with custom context
where needed.
Previously, errors would be 'unfolded' so there was no error chain,
but the lowest error would become the top-most one that way.
I thought this was accidental, but it turns out that it wasn't.
To fix this generally, make sure that we always use the message
of the lowest-possible error if no context is provided.
This also rewrites some other checks in preference of opening the git directory
in isolation. Doing so is very fast, and the only way to know for certain if a
repository is bare.
In future, once the repository is more separated from the worktree (in terms of mindset)
it should be possible to handle bare repos with worktrees as well.
The issue initially was that the wrapping of anyhow around a `thiserror`
type, which is when manually added context gets lost as there is no way
to downcast such an `anyhow` error back to a concrete type without
wanting to know it.
The solution was to remove the intermediate `thiserror` type which didn't
serve an actual purpose.
- assure that `repository` can't be misused in `hunks_by_filepath()`.
- Use more obvious enumeration to describe and match on lines
- make clear that diff_lines can be a hash
- avoid multiple hashmasps if one would do
- `Hunk::hash_diff` now uses lines with terminator to be close to being a true content hash. This was probably intended by the code originally.
The input is variable and maybe empty, maybe a diff header followed
by diff-lines, and it could be an SHA1 of a binary file, which now is
hashed like any other content.
Note that the comment above 'deltas' merely removed, as it wasn't actionable
without changing the frontend, which can probably already deal with
multiple of these.
Now that types are better understood though, it was straightforward to
change the type of `file_path` to not be a string, which now is even
clearer of a necessity thanks to the `tauri`-independent `watcher` crate.
Also, remove a comment related to the lack of worktree support.
It now fails gracefully, and that will come up again if support should be added.