Commit graph

2723 commits

Author SHA1 Message Date
Yuya Nishihara
d771c12637 index: make HexPrefix accessor simply return "min" prefix as bytes slice
This is low-level function, so I think using &[u8] should be good here.
2023-01-27 03:37:44 +09:00
Yuya Nishihara
770ca72a1f index: use iterator to simplify segment_resolve_prefix() a bit further 2023-01-27 03:37:44 +09:00
Yuya Nishihara
956a2d5f83 index: remove redundant prefix tests from resolve_prefix functions
The "min" prefix guarantees that the first entry matches the hex prefix
if any. Spotted by @ilyagr.
2023-01-27 03:37:44 +09:00
Yuya Nishihara
b4c837fd4a index: simplify segment_resolve_prefix() loop to make both impls look close 2023-01-27 03:37:44 +09:00
dependabot[bot]
5d675f13a2 cargo: bump timeago from 0.4.0 to 0.4.1
Bumps [timeago](https://github.com/vi/timeago) from 0.4.0 to 0.4.1.
- [Release notes](https://github.com/vi/timeago/releases)
- [Commits](https://github.com/vi/timeago/compare/v0.4.0...v0.4.1)

---
updated-dependencies:
- dependency-name: timeago
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-26 09:16:03 -08:00
Yuya Nishihara
bfb56614d4 templater: rename TemplateFunction::new() parameter for consistency 2023-01-26 23:42:13 +09:00
Yuya Nishihara
2c4856c47b templater: remove Box<dyn> from generic wrappers, parameterize type
This basically removes 'a lifetime from these wrappers, and add trait bounds
instead. I have no idea which version would look less scary, but let's see.

I also added trait bounds to constructor functions. They aren't strictly
required, but help type inference of closure (and will probably improve
an error message.)
2023-01-26 23:42:13 +09:00
Aleksandr Mikhailov
e7077909c1 cli: fix jj squash on empty commit
Fixes #787
If `jj squash` is run on an empty commit, it fails with "Error: No changes selected"

With this change such squash command will behave like `jj abandon`.
2023-01-26 11:37:20 +01:00
Ilya Grigoriev
5421f5e92d test_obslog_command.rs: stop removing change ids
The regex no longer works and the change ids are no longer random since a few
weeks ago.
2023-01-25 22:07:07 -08:00
Martin von Zweigbergk
d6622e5d42 tests: make fake editor scripts initially empty
I would expect `set_up_fake_[diff_]editor()` to create an empty script
but it turns out they didn't even create the files. That means that
the caller needs to write an empty script to them if they want the
fake editors to not do anything. Let's instead write the empty
scripts, for a less surprising behavior.
2023-01-25 21:58:38 -08:00
Yuya Nishihara
b9fc6d4203 templater: rewrite divergent property by leveraging IdIndex 2023-01-26 14:10:26 +09:00
Yuya Nishihara
824f2106fd repo: migrate revset::resolve_change_id() to use IdIndex for ReadonlyRepo
The MutableRepo implementation is the same as before.
2023-01-26 14:10:26 +09:00
Yuya Nishihara
4f15d1f779 repo: implement method to look up change_id prefix by using IdIndex
revset::resolve_change_id() for ReadonlyRepo will be replaced with this
implementation. This doesn't mean revset query will speed up. A trivial
query will become slower due to the initialization cost of the change id
index. "jj log -r hex" will get faster since we have to pay the cost anyway.

Benchmark numbers (against my "linux" repo):

Command:
    hyperfine --warmup 3 --runs 20 \
      "jj log -r $hex -T '' --no-commit-working-copy --no-graph"

Linear search (e874570947):
    Time (mean ± σ):     223.9 ms ±  16.2 ms    [User: 181.2 ms, System: 42.7 ms]
    Range (min … max):   207.7 ms … 247.6 ms    50 runs

Building IdIndex:
    Time (mean ± σ):     855.0 ms ±  21.7 ms    [User: 788.4 ms, System: 66.6 ms]
    Range (min … max):   822.6 ms … 927.5 ms    50 runs

Building IdIndex, but hacked to store SmallVec<[u8; 20]>:
    Time (mean ± σ):     406.1 ms ±  15.9 ms    [User: 354.1 ms, System: 52.0 ms]
    Range (min … max):   382.2 ms … 428.6 ms    50 runs

For my "jj" work repo, changes are < ~1ms.
2023-01-26 14:10:26 +09:00
Yuya Nishihara
38a9180bb7 repo: generalize IdIndex over key and value types
Though we'll only need IdIndex<ChangeId, IndexPosition>, this allows us to
write unit tests without setting up MutableIndex.
2023-01-26 14:10:26 +09:00
Ilya Grigoriev
8c5a14d28a contributing.md: Add a link to the "Comprehensive Rust" course
This is something I wish I had when I first contributed to `jj`.
2023-01-25 21:10:10 -08:00
Martin von Zweigbergk
10725c095f cleanup: update more "checkout" to "working-copy commit" and similar
I've preferred "working-copy commit" over "checkout" for a while
because I think it's clearer, but there were lots of places still
using "checkout". I've left "checkout" in places where it refers to
the action of updating the working copy or the working-copy commit.
2023-01-25 11:02:59 -08:00
Martin von Zweigbergk
37ba17589d simple_op_heads_store: rename storage directory
`SimpleOpHeadsStore` currently stores its files in
`.jj/repo/op_heads/simple_op_heads/`. The `.jj/repo/op_heads/type`
file indicates the type of op-heads backend. If that contains
"simple_op_head_store", we use the `SimpleOpHeadsStore`
backend. There's no need for the `simple_op_heads` directory to also
indicate the type of backend in its name. I kept just the `heads` in
the name to make it less redundant with the parent directory (which is
`op_heads)`. We could alternatively call the directory `values` or
similar.
2023-01-25 09:22:38 -08:00
Martin von Zweigbergk
0d1ec835c1 repo: rename .jj/repo/store/backend to .jj/repo/store/type
We decided to call the files identifying the backend type `type`. We
already use that name for `OpStore` and `OpHeadsStore`.
2023-01-25 09:22:38 -08:00
dependabot[bot]
7f4e714ffe cargo: bump pest_derive from 2.5.3 to 2.5.4
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.3 to 2.5.4.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.3...v2.5.4)

---
updated-dependencies:
- dependency-name: pest_derive
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-25 07:49:05 -08:00
Yuya Nishihara
e874570947 cli: proxy format_commit_summary() through transaction wrapper
At this point, tx.base_repo() is identical to tx.repo(), so the caller doesn't
need to explicitly select the "base" one.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
18e9679613 cli: move run_mergetool/edit_diff/select_diff to transaction wrapper
These functions should use MutableRepo if base_repo.store() != repo.store().
See also #50.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
330adf380f cli: start transaction before starting edit/select_diff()
Other callers do that, so let's make the transaction cover tree merging
and diff editing.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
1b8ecef968 cli: have WorkspaceCommandHelper return &WorkspaceId, clone it by caller
I didn't make this change before because there are many immutable/mutable
borrow conflicts. Now most of the problems are consolidated to the transaction
wrapper, we can simply make it return a reference.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
3d5eb970da cli: wrap transaction started by WorkspaceCommandHelper, borrow helper mutably
This ensures that helper methods that depend on repo aren't used by mistake
while transaction is in progress. Still it provides an escape hatch to invoke
e.g. select_diff() with the base repo, but such invocations are more explicit.

Some MutableRepo methods are proxied through the wrapper to get around
borrowing errors.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
44e7c0632e cli: evaluate rebase set before starting transaction
This should eliminate lifetime issue I would have to deal with in the
next commit. evaluate_revset() only borrows RepoRef, but such precise
dependency can't be expressed as of now.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
c018ef229b repo: proxy shortest unique prefix function through RepoRef
Since this function depends on both index and view, it can't be moved to
one of the storage objects. If we go forward with this approach, some
revset::resolve_*() functions will also be migrated to RepoRef.

This patch slightly changes the function name since a "prefix" might have
various meanings.
2023-01-25 10:47:39 +09:00
Yuya Nishihara
c0c5e8f041 repo: rewrite "all()" query to clarify data dependency 2023-01-25 10:47:39 +09:00
Martin von Zweigbergk
b079897a56 cli: propagate failure to record new working-copy id
This code cannot currently fail because we we never pass in the root
commit, but it's more future-proof to propagate the error.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
ce094c618b repo: propagate error when current working-copy commit is not found
This should fix the panic in the case reported in #1107. It's a bit
hard to reproduce because we normally notice the missing commit when
we snapshot the working copy, but it's possible to reproduce it using
`--no-commit-working-copy`.

I suspect the added test is too brittle because it checks the exact
error message. On the other hand, it might be useful to have one test
case like this so we catch accidental changes in the format.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
63aa484046 repo: add a specific error type for MutableRepo::check_out() 2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
eb7de6dd3c repo: inline leave_commit() into single caller 2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
4777508df0 repo: make check_out() call edit()
This reduces duplication a little, and it makes logical sense.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
dd3472924b repo: add a specific error type for MutableRepo::edit()
The new type is just an enum version of `RewriteRootCommit`.  I'll add
another variant soon.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
ff592e522f edit: explicitly check that target commit is rewritable
I think the CLI should check if the target of `jj edit` is rewritable
before calling the library to update the repo. The other commands
already do that. Then, if calling `MutableRepo::edit()` fails, it's
always an internal error, which makes error handling simpler in coming
commits.
2023-01-24 12:20:28 -08:00
Samuel Tardieu
e4f6dadfad workspace: add a root subcommand to print the workspace root path 2023-01-24 16:53:54 +01:00
dependabot[bot]
9dd5fe108a cargo: bump pest from 2.5.3 to 2.5.4
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.3 to 2.5.4.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.3...v2.5.4)

---
updated-dependencies:
- dependency-name: pest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-24 16:50:17 +01:00
Samuel Tardieu
31d7bf02ce style: make normalize_output() take a &str instead of a String 2023-01-24 15:33:49 +01:00
Yuya Nishihara
797189b106 cli: error out if colors section isn't of map type 2023-01-24 15:06:12 +09:00
Yuya Nishihara
7b24df25e4 cli: remove redundant check for undefined "merge-tools" section
The section should be defined by default.
2023-01-24 15:06:12 +09:00
Yuya Nishihara
337246ea51 cli: error out if alias/revset-aliases section isn't of map type
I considered adding .optional() helper to lift Result to Result<Option<_>>,
but it's much simpler to expect all config sections (and maybe all keys?)
are defined by default.

The error message is a bit cryptic, but it should be improved by the following
PR if accepted.

https://github.com/mehcode/config-rs/pull/413
2023-01-24 15:06:12 +09:00
Yuya Nishihara
3b09635f46 cli: rename config/git.toml to misc.toml to add some more random stuff
I could add a file per section, but each file would just contain one or two
lines.
2023-01-24 15:06:12 +09:00
Martin von Zweigbergk
7c9c2735ae readme: link to Git Merge 2022 talk for info about Google's plans 2023-01-23 11:10:48 -08:00
Yuya Nishihara
8163b87a54 templater: store repo in CommitOrChangeId struct
This one was the outlier, and I think propagating 'repo' by context variable
is more correct.
2023-01-24 01:46:41 +09:00
Yuya Nishihara
e15b35ba56 templater: remove unused repo from CommitOrChangeIdShort 2023-01-24 01:46:41 +09:00
Yuya Nishihara
f47552b744 templater: turn output parameter of TemplateProperty into associated type
When implementing FormattablePropertyTemplate, I tried a generic 'property: P'
first, and I couldn't figure out how to constrain the output type.

    impl<C, O, P> Template<C> for FormattablePropertyTemplate<P>
    where
        P: TemplateProperty<C, O>, // 'O' isn't constrained by type
        O: Template<()>,

According to the book, the problem is that we can add multiple implementations
of 'TemplateProperty<C, *>'. Since TemplateProperty is basically a function
to extract data from 'C', I think the output parameter shouldn't be freely
chosen.

https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

With this change, I can express the type constraint as follows:

    impl<C, P> Template<C> for FormattablePropertyTemplate<P>
    where
        P: TemplateProperty<C>,
        P::Output: Template<()>,
2023-01-24 01:46:41 +09:00
dependabot[bot]
efe72f714a github: bump dtolnay/rust-toolchain
Bumps [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain) from 22cb70465de2ebc761c76f91046abd5a6986040f to ce8f65846d7180d2ce63b1e74483d981800b9e22.
- [Release notes](https://github.com/dtolnay/rust-toolchain/releases)
- [Commits](22cb70465d...ce8f65846d)

---
updated-dependencies:
- dependency-name: dtolnay/rust-toolchain
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-23 08:32:50 -08:00
Yuya Nishihara
df085a4bd5 templater: label author/committer name in default formatting
Just for consistency with .name() method call.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
47e6ceb5fa templater: display both name and email by author/committer keywords
This is an example of labeled output of structured value types. I think
"{name} <{email}>" is a good default formatting, but I should note that
the signature also contains timestamp field.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
4e661ecd40 templater: format context-less property value instead of coercing to string
This unblocks labeled outputs for these value types.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
431395a7ee templater: generalize Literal/Constant wrapper for any context-less template
Now we have 'impl Template<()> for String', 'LiteralTemplate(String)' is
a bit redundant. Let's generalize it for any 'Template<()>'. I noticed
'ConstantTemplateProperty' serves as a similar role, so unified these.
2023-01-23 15:23:26 +09:00