Commit graph

5182 commits

Author SHA1 Message Date
Yuya Nishihara
0f2f566188 index: remove "segment_" prefix from IndexSegment methods
Since Readonly/MutableIndexSegment no longer implement Index trait, there's
no ambiguity between segment-local and index-global operations. Let's shorten
the method names.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
c9b9e2864e index: introduce newtype that represents segment-local position
I'm thinking of changing some IndexSegment methods to return LocalPosition
instead of global IndexPosition, and using u32 there would be a source of bugs.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
ee8d5e279a index: make segment-level lookup return neighbor commit ids instead of positions
Both readonly and mutable segments know the commit ids to return, and the
caller only needs the ids. Since segment_commit_id(local_pos) scans the graph
entries, doing that would increase the chance of cache miss.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
0e7834feb9 index: inline segment_entry_by_pos()
There's no reasonable way to abstract the IndexEntry construction.
2023-12-26 01:03:10 +09:00
Ilya Grigoriev
1fb9df252b split.rs: stop using DescendantRebaser::new
This requires creating a new public API as a substitute. I took the opportunity
to also add some comments to the
`MutRepo::record_rewritten_commit`/`record_abandoned_commit` functions.

I imade the simplest possible addition to the API; it is not a very elegant
one. Eventually, the entire `record_rewritten_commit` API should probably be
refactored again.

I also added some comments explaining what these functions do.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
c7c8960bcc test_split_command: check that new commits inherit author dates
At some point, I tried `new_commit` instead of `rewrite_commit` in the split
command. That seemed to work, but messed up the dates in a subtle way.

This commit should prevents repeats of this mistake and emphasize the
importance of the author dates being preserved.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
6bfd09009f move.rs: remove use of MutRepo::create_descenant_rebaser.
After this, the internal function is only used in tests.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
cde8ea8985 Make CommitBuilder constructors private to the library crate
The implementation of `CommitBuilder::write` is tightly bound to the MutRepo,
so only MutRepo should construct CommitBuilder-s.
2023-12-24 19:25:16 -08:00
Yuya Nishihara
6b862c6f23 cli: don't panic on empty alias substitution
This partially reverts 6c627fb30d "cli: default to log when no subcommand is
provided." We could reject an empty alias at all, but we would still need to
ensure that the expanded alias contained a subcommand name.

The help output is a bit odd as the <COMMAND> can be omitted, but I think
that's acceptable. If we do care about that, maybe we can override_usage().
2023-12-24 23:31:28 +09:00
Yuya Nishihara
b954bab0ca index: fix partial reindexing to not lose commits only reachable from one side
Spotted while adding error propagation there. This wouldn't likely be a real
problem because "jj debug reindex" removes all of the operation links.

The "} else {" condition is removed because it doesn't make sense to exclude
only the exact parent_op_id operation. This can be optimized to not walk
ancestors of the parent_op_id operation, but I don't see a motivation to add
tests covering such scenarios. It's pretty rare that an intermediate operation
link is missing.
2023-12-24 23:31:16 +09:00
Yuya Nishihara
320d15412b index: let caller of segment-level save-in() squash segments explicitly
There are many unit tests that call mutable_segment.save_in(), but I don't
think these callers expect that the segment file could be squashed depending
on the size. Let's make it caller's responsibility.

maybe_squash_with_ancestors() should be cheap if segment_num_commits() == 0,
so it's okay to call it before checking the emptiness.
2023-12-24 00:22:47 +09:00
Yuya Nishihara
1d80bbb70a index: leverage ancestor iterator to collect segments to be squashed
I think "for" loop is easier to follow. Maybe it could be rewritten further to
.find_map() loop, but that would be too clever.

I also made ancestor_index_segments() pub(super) since it doesn't make sense
to only provide ancestor_files_without_local().
2023-12-24 00:22:47 +09:00
Yuya Nishihara
55b4f69fb6 repo: propagate store error from add_heads() 2023-12-24 00:22:30 +09:00
Yuya Nishihara
0f6a7418f2 index: propagate store error from reindexing function
If the error is permanent (because the repo predates the no-gc-ref fix for
example), there's no easy way to recover. Still, panicking in this function
seems wrong.
2023-12-24 00:22:30 +09:00
Yuya Nishihara
1836a105bb cli: warn if -R/--repository could be involved in command alias expansion
#2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
30b5e88b04 cli: use cwd-relative workspace config to resolve default command and aliases
This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes #2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
941e53802f cli: error out early if -R path is invalid
It should be better to handle invalid -R path globally. The error message is
a bit worse, but I think it's still okay.

This helps to load temporary config from the cwd-relative path. If the command
processing continued with an invalid -R path, the temporary config would have
to be explicitly discarded.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
c82b2c78fd cli: inline init_workspace_loader()
In order to load command aliases from .jj/repo/config.toml, WorkspaceLoader
will be changed to be instantiated earlier with the cwd path.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
7a44e590dc lock: remove byteorder dependency from tests, use fs helper functions
This is the last use of Read/WriteBytesExt. The byteorder crate is great, but
we don't need an abstraction of endianness. Let's simply use the std functions.
2023-12-23 00:14:17 +09:00
Yuya Nishihara
9de6273e10 index, stacked_table: inline read_u32::<LittleEndian>()
There aren't many callers of ReadBytesExt::read_u32().
2023-12-23 00:14:17 +09:00
Yuya Nishihara
21c22be96e stacked_table: use u32::from_le_bytes() to reinterpret bytes as integer
Apparently, I forgot to update this in fb06e89649.
2023-12-23 00:14:17 +09:00
Yuya Nishihara
6f5096e266 index, stacked_table: use u32::try_from() instead of numeric cast
These .unwrap()s wouldn't be compiled out, but I don't think they would
have measurable impact. Let's use the safer method.
2023-12-22 09:03:50 +09:00
Yuya Nishihara
9ec89bcf86 index, stacked_table: use u32::to_le_bytes() to reinterpret as bytes 2023-12-22 09:03:50 +09:00
Yuya Nishihara
392539fa29 index, stacked_table: simply extend Vec<u8> to not use .write_all()
I'm going to remove use of .write_u32() there. It's not super important, but
fewer .unwrap()s, the code looks slightly better.
2023-12-22 09:03:50 +09:00
Yuya Nishihara
fb06e89649 index: use u32::from_le_bytes() to reinterpret bytes as integer
It's less abstract than going through io::Read, so is probably easier for
compiler to optimize out. I also feel it's a bit more readable.
2023-12-22 09:03:50 +09:00
Austin Seipp
889f052dfa readme: do some cleanup
As noted by Martin and Waleed on Discord.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I9cba734774a7e89dfd65c8202e76c2f4
2023-12-21 16:26:17 -06:00
dependabot[bot]
04f9440872 cargo: bump the cargo-dependencies group with 2 updates
Bumps the cargo-dependencies group with 2 updates: [anyhow](https://github.com/dtolnay/anyhow) and [async-trait](https://github.com/dtolnay/async-trait).


Updates `anyhow` from 1.0.75 to 1.0.76
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](https://github.com/dtolnay/anyhow/compare/1.0.75...1.0.76)

Updates `async-trait` from 0.1.74 to 0.1.75
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](https://github.com/dtolnay/async-trait/compare/0.1.74...0.1.75)

---
updated-dependencies:
- dependency-name: anyhow
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: async-trait
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-21 08:07:54 -08:00
Yuya Nishihara
5bf9e4192a cli: don't look for added/removed conflicts across old/new heads
removed_heads..added_heads won't stop if new head is added on top of non-head
commit for example.

#2729
2023-12-21 23:40:52 +09:00
Gabriel Scherer
dafc900cca git comparison: include a 'git grep' equivalent 2023-12-21 00:20:45 +01:00
Gabriel Scherer
fad511a6e5 document the use of JJ_USER and JJ_EMAIL in combination with --reset-author
Suggested-by: David Barnett <dbarnett@google.com>
2023-12-21 00:20:45 +01:00
dependabot[bot]
cf3db53ea7 cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [tokio](https://github.com/tokio-rs/tokio).


Updates `tokio` from 1.35.0 to 1.35.1
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.35.0...tokio-1.35.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-21 08:06:02 +09:00
Yuya Nishihara
38ce914321 index: reindex on content-related I/O errors
If read_exact() or read_u32() reached to EOF, the index file should be
considered corrupted. File not found error is also treated as data corruption
because an invalid file name could be read from the child segment file. It
can't handle special file names like "..", though.
2023-12-21 08:05:30 +09:00
Yuya Nishihara
e98104d6f0 index: add file name to both io/corrupt errors, combine these variants
Index file name also applies to io::Error. New error type reuses io::Error to
represent data corruption. We could add an inner Corrupt|Io enum instead, but
we'll need to remap some io::Error variants (e.g. UnexpectedEof) to Corrupt
anyway.
2023-12-21 08:05:30 +09:00
Yuya Nishihara
88f3085bb1 index: extract function that opens file and loads index segments 2023-12-21 08:05:30 +09:00
Yuya Nishihara
eccb9b7a44 index: propagate index load errors from DefaultIndexStore 2023-12-19 07:41:57 +09:00
Yuya Nishihara
dd8e686127 index: don't reload parent files after saving new segment file
This should be cheaper, and more importantly, we no longer need to propagate
ReadonlyIndexLoadError to the caller.
2023-12-19 07:41:57 +09:00
Yuya Nishihara
fb07749291 index: split load function into header and local parts as well 2023-12-19 07:41:57 +09:00
Yuya Nishihara
616a8c7f54 index: split serialization function into header and local parts
The idea is that we don't have to reload parent files as we already have the
chain of the parent segments. The resulting readonly index will be constructed
from the loaded parent segments + local entries blob.
2023-12-19 07:41:57 +09:00
Yuya Nishihara
31b6e93c6e index: move IndexLoadError to "readonly" module, rename accordingly
I thought IndexLoadError and DefaultIndexStoreError would represent "load" and
"store" failures respectively, but they aren't. Actually, DefaultIndexStoreError
is the store-level error, and IndexLoadError should be wrapped in it.
2023-12-19 07:41:57 +09:00
Yuya Nishihara
b5de16007e index: add stub IndexReadError type
This is needed to remove .unwrap()s from DefaultIndexStore.
2023-12-19 07:41:57 +09:00
Yuya Nishihara
d49b079494 index: update file format comment about ReadonlyIndexSegment
Also made it a doc comment. I think 4-byte alignment is a nice property,
so added note about that.
2023-12-19 07:41:34 +09:00
Ilya Grigoriev
c5f76d6b4d cli untrack --help: mention that files need to be already be ignored
Make it clearer what the command does, make the error message when the file is
not ignored less of a surprise.

Also, I think it's nice to mention `.git/info/exclude`, since the path is
not trivial to remember.
2023-12-17 22:16:22 -08:00
Ilya Grigoriev
9a990ad92f docs config.md Vim instructions: link to the Wiki instead of a gist 2023-12-17 22:16:02 -08:00
Yuya Nishihara
8909647d86 index: pass base directory path by reference 2023-12-18 08:49:21 +09:00
Yuya Nishihara
b733d52557 index: split DefaultIndexStoreError::Io variant, extract save helper
Since OpStoreError can also include io::Error, it doesn't make much sense to
have Io variant at this level. Let's split it to context-specific errors, and
extract helper method that maps io::Error.
2023-12-18 08:49:21 +09:00
Yuya Nishihara
bf4a4e70b1 index: use DefaultMutableIndex wrapper when reconstructing missing index
This allows us to extract helper method that writes index file and associates
it with the operation.
2023-12-18 08:49:21 +09:00
Yuya Nishihara
50164bb36f index: have IndexWriteError carry opaque error type instead of string
I'm going to remove some .unwrap()s from DefaultIndexStore, and the inner
error type will be consolidated to DefaultIndexStoreError.
2023-12-18 08:49:21 +09:00
Yuya Nishihara
87a8238bee git: turn git.auto-local-branch off by default
As far as I can see in the chat, there's no objection to changing the default,
and git.auto-local-branch = false is generally preferred.

docs/branches.md isn't updated as it would otherwise conflict with #2625. I
think the "Remotes" section will need a non-trivial rewrite.

#1136, #1862
2023-12-17 08:30:24 +09:00
Yuya Nishihara
6971ec239a tests: set git_settings.auto_local_branch where it matters 2023-12-17 08:30:24 +09:00
Yuya Nishihara
ac99145a28 working_copy: drop open file instance from PersistError
For the same reason as the file_util change.
2023-12-17 08:20:07 +09:00