ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

2654 commits

Author SHA1 Message Date
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
Yuya Nishihara
23ab89d200 templater: implement context-less Template::format() on value types
This is a slightly better version of the one I described in:
https://github.com/martinvonz/jj/pull/1098#issuecomment-1399476487

These impls will replace coerce_to_string() to support labeled outputs.
We could allow arbitrary context type 'C', but I feel uncomfortable with
that. So let's start with () until we find it doesn't work out.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
c1f0ca9b5a templater: rewrite Property match arms with generic function
We might want to go further by rewriting the Property enum with trait, but
let's start small.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
d2b8240648 templater: inline TemplateFormatter into write_commit_summary()
It's not used extensively, and I don't think this abstraction is useful
for the moment.
2023-01-23 15:23:26 +09:00
Martin von Zweigbergk
e716168368 cli: also sanitize non-colored output printed to a terminal
This makes us sanitize ANSI escape bytes in the output if it goes to
the terminal, even when it's not colored (by us), such as when using
`--color=never`. That means that e.g. `jj cat
tests/test_commit_template.rs` will not be colored, but `jj cat
tests/test_commit_template.rs | cat` will be. Sanitizing output sent
to the terminal might help reduce some security threats based on
hiding content by using ANSI escapes.

We could add a config option for sanitizing the output, but I'm not
sure it'll be useful.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
13a177f211 cli: sanitize ANSI escapes when writing colored output is enabled
Since `ColorFormatter` itself outputs ANSI escape codes, we should not
let the caller also include ANSI escape codes. This commit makes
`ColorFormatter` replace them by a unicode "␛".
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
7527656d9b formatter: expose raw output and use for graphlog
For graphlog output, we use a separate formatter for each commit. The
output from the formatter is written to a buffer in memory. Then we
write it to graphlog renderer. Since the buffer already has any color
codes, we should not pass it through the top-level formatter (the one
bound to stdout). It hasn't mattered much so far, but it will when we
start sanitizing output written to formatters. This commit adds a
method to the `Formatter` trait for getting access to the raw
underlying output. It also starts passing that output to the graphlog
renderer.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
522025e091 log: remove unused and inconsistent log label
We add a top-level `log` label to the output from `jj log`, but we
never define any colors based on it. More importantly, it was
inconsistent between the graph and non-graph cases. When showing the
graph, any colors set based on it would only apply to the graph itself
[1] because we use a separate formatter for each commit in the
graphlog and that formatter didn't inherit the `log` label. So let's
just remove the label for now. We can consider adding it back for each
commit later. That's what we do for `jj op log`, but it's simpler in
that case because it doens't have a `--no-graph` version.

 [1] Well, mostly; it would also apply to any uncolored element
     immediately right of the graph.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
842b3e5591 formatter: remove write_bytes() method
The caller can just as easily use `write_all()`.

Maybe we should also remove the `write_str()` method.
2023-01-22 17:45:12 -08:00
Yuya Nishihara
c82a62cf99 repo: turn IdIndex into sorted Vec, use binary search
Since IdIndex is immutable, we don't need fast insertion provided by BTreeMap.
Let's simply use Vec for some speed up. More importantly, this allows us to
store multiple (ChangeId, CommitId) pairs for the same change id, and will
unblock the use of IdIndex in revset::resolve_symbol().

Some benchmark numbers (against my "linux" repo) follow.

Command:
    hyperfine --warmup 3 "jj log -r master \
      -T 'commit_id.short_prefix_and_brackets()' \
      --no-commit-working-copy --no-graph"

Original:
    Time (mean ± σ):      1.892 s ±  0.031 s    [User: 1.800 s, System: 0.092 s]
    Range (min … max):    1.833 s …  1.935 s    10 runs

This commit:
    Time (mean ± σ):     867.5 ms ±   2.7 ms    [User: 809.9 ms, System: 57.7 ms]
    Range (min … max):   862.3 ms … 871.0 ms    10 runs
2023-01-23 07:38:04 +09:00
Yuya Nishihara
1a6e71170e templater: remove string.short() method
I think this is a remainder of 68ad712e12 "Templater: Combine Change and
Commit id templates." It doesn't make sense that description.short() prints
the first 12 characters.
2023-01-23 00:29:55 +09:00
Samuel Tardieu
b53f004372 Fix output of jj debug completion --help
The help strings for fish and zsh were inverted.
2023-01-22 12:28:03 +01:00
Yuya Nishihara
879f585b21 repo: leverage stored index to calculate shortest prefix in commit id space
With my "jj" work repo, this saves ~4ms to show the log with default revset.

Command:
    JJ_CONFIG=/dev/null hyperfine --warmup 3 --runs 100 \
      "jj log -T 'commit_id.short_prefix_and_brackets() \
                  change_id.short_prefix_and_brackets()' \
              --no-commit-working-copy"

Baseline (a7541e1ba4):
    Time (mean ± σ):      54.1 ms ±  16.4 ms    [User: 46.4 ms, System: 7.8 ms]
    Range (min … max):    36.5 ms …  78.1 ms    100 runs

This commit:
    Time (mean ± σ):      49.5 ms ±  16.4 ms    [User: 42.4 ms, System: 7.2 ms]
    Range (min … max):    31.4 ms …  70.9 ms    100 runs
2023-01-22 17:24:03 +09:00
Yuya Nishihara
2e9468772b index: add method to calculate shortest commit_id prefix
For simplicity, I made public API that returns the shortest length.
2023-01-22 17:24:03 +09:00
Yuya Nishihara
5a0931885d index: add ancestor iterators to CompositeIndex and rewrite loop/recursion
This iterator will be used to merge neighbor commit ids across segments.

resolve_prefix() is simplified to non-short-circuiting loop. I think that's
fine because visiting parents is cheap, and the costly operation here is
segment_resolve_prefix().

entry_by_pos() could also be migrated to iterator, but I leave the unsafe
bits there.
2023-01-22 17:24:03 +09:00
Yuya Nishihara
e71e9c99b2 index: add neighbor commit_id lookup to IndexSegment
ReadonlyIndex implementation leverages the existing binary search
function. MutableIndex one is basically the same as repo::IdIndex.

Shortest prefix length could be calculated for each segment, but I think
returning neighbors is better for testing.
2023-01-22 17:24:03 +09:00
Martin von Zweigbergk
e46cbfc9d0 cargo: replace dependency on Sapling's dag by renderdag
The rendering is now its own crate, so we don't need to depend on the
other `dag` code.

Fixes #1056.
2023-01-22 00:03:48 -08:00
Yuya Nishihara
a7541e1ba4 repo: add workaround for shortest prefix calculation of root ids
This is ugly, but we need a special case because root_change_id and
root_commit_id aren't equal but share the same prefix bytes. In practice,
no one would care for the shortest root id prefix, but we'll need to deal
with a similar problem when migrating prefix id resolution to repo layer.
2023-01-22 12:03:08 +09:00
Yuya Nishihara
1a4b5c5ee6 index: make IdIndex store raw bytes, not hex bytes
This helps us to migrate commit_id index to ReadonlyIndex. For large
repositories, this also reduces initialization cost, but that's not the main
intent of this change.

https://github.com/martinvonz/jj/pull/1041#issuecomment-1399225876

common_hex_len() and iter_half_bytes() are added to backend.rs since more
call sites will be added to index.rs, and I feel index.rs isn't a good place
to host this kind of utility functions.
2023-01-22 12:03:08 +09:00
Yuya Nishihara
65a659347e tests: pad odd-length hex bytes passed in to repo::IdIndex
This allows us to migrate IdIndex to raw bytes. In practice, these ids are
full hashes which should never be odd length.
2023-01-22 12:03:08 +09:00