Commit graph

2418 commits

Author SHA1 Message Date
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
Yuya Nishihara
1d2642de1e repo: split commit_id and change_id indices
The goal is to replace the commit_id index with ReadonlyIndex to save the
initialization cost, but this also helps to fix root id handling.
2023-01-22 12:03:08 +09:00
Yuya Nishihara
8c0f7d7707 backend: define root change id statically
I made it a free function. Alternatively, the root id could be instantiated
by and obtained through backend, but I don't think we'll need such level of
abstraction.

I'm going to add a workaround for shortest prefix calculation of the root ids,
where this function will be used.
2023-01-22 12:03:08 +09:00
Yuya Nishihara
ef33bd76df backend: declare CHANGE_ID_HASH_LENGTH as constant 2023-01-22 12:03:08 +09:00
Benjamin Saunders
6d0a6f32aa nix: remove .envrc
The flake currently has some odd behavior, such as copying .jj and
target/, and treating the jj src as an input to the dev shell. This
avoids making life rough for direnv users while those are outstanding.
2023-01-21 14:17:57 -08:00
Samuel Tardieu
8b644846a4 refactor: use #[from] on error alternative 2023-01-21 09:46:54 +01:00
Martin von Zweigbergk
8a1b21ff73 backend: implement equality for commits and trees
It can be useful in tests to be able to compare two commits or
trees. Most other structs already implement equality.
2023-01-20 23:26:20 -08:00
Ilya Grigoriev
1bcdcea3ef Fix typo in function name 2023-01-20 22:05:33 -08:00
Samuel Tardieu
9846bf6c7f style: use bool::then() 2023-01-21 01:14:45 +01:00
dependabot[bot]
034a23f4ec cargo: bump git2 from 0.16.0 to 0.16.1
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.16.0 to 0.16.1.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.16.0...0.16.1)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-21 00:05:57 +00:00
dependabot[bot]
76e1310f36 cargo: bump libgit2-sys from 0.14.1+1.5.0 to 0.14.2+1.5.1
Bumps [libgit2-sys](https://github.com/rust-lang/git2-rs) from 0.14.1+1.5.0 to 0.14.2+1.5.1.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.14.1...libgit2-sys-0.14.2)

---
updated-dependencies:
- dependency-name: libgit2-sys
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-20 23:52:42 +00:00
Daniel Ploch
bd43580437 op_heads_store: remove LockedOpHeads
Make op resolution a closed operation, powered by a callback provided by the
caller which runs under an internal lock scope. This allows for greatly
simplifying the internal lifetime structuring.
2023-01-20 15:18:08 -08:00
Daniel Ploch
bec1051967 cli_util: add a helper for creating a Transaction without owning a Workspace 2023-01-20 15:18:08 -08:00
Daniel Ploch
19962fcded op_heads_store: move the ancestry walk into the OpHeadsStore trait 2023-01-20 15:18:08 -08:00
Philip Metzger
c252f3eb04 Docs: Fix a dangling ref.
During the initial review, we missed that I wrote `detached head` 
in the link to https://www.git-scm.com/docs/git-checkout#_detached_head 
instead of `detached`. This corrects the link.
2023-01-20 20:05:05 +01:00
Yuya Nishihara
763a8cc0f1 index: remove allocation from bisection loop of commit_id prefix search
This wouldn't actually matter since the depth of binary search is O(log(N)),
but I feel it's better to avoid allocation in comparison loop.
2023-01-21 01:44:21 +09:00
Yuya Nishihara
2b7021664d index: deduplicate binary search functions of commit_id lookup 2023-01-21 01:44:21 +09:00
Yuya Nishihara
049a9261ab index: change return type of commit_id_byte_prefix_to_pos()
I don't think the returned position here is an IndexPosition, but a local
"lookup" index of the entry.
2023-01-21 01:44:21 +09:00
Yuya Nishihara
a574987955 index: remove redundant slicing from commit_id-prefix search function
If commit_id[..prefix_len] < prefix, commit_id < prefix is obviously true.
If commit_id[..prefix_len] == prefix, commit_id < prefix returns false. So
slicing isn't needed.

This makes commit_id_byte_prefix_to_pos() basically the same as
segment_commit_id_to_pos(), and these two functions can be merged.
2023-01-21 01:44:21 +09:00
dependabot[bot]
a29b19fa9d github: bump dtolnay/rust-toolchain
Bumps [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain) from e645b0cf01249a964ec099494d38d2da0f0b349f to 22cb70465de2ebc761c76f91046abd5a6986040f.
- [Release notes](https://github.com/dtolnay/rust-toolchain/releases)
- [Commits](e645b0cf01...22cb70465d)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-20 15:18:40 +00:00
Samuel Tardieu
8a289ddef0 refactor: return ExitCode from CliRunner::run()
`CliRunner::run()` has been renamed from `CliRunner::run_and_exit()`
and returns an `ExitCode` which can be returned from `main()`.
2023-01-20 06:42:08 +01:00
Martin von Zweigbergk
f7324768a7 docs: fix some typos in github.md, and reformat it 2023-01-19 09:45:10 -08:00
dependabot[bot]
24e03e2ff5 github: bump github/codeql-action from 2.1.38 to 2.1.39
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.38 to 2.1.39.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](515828d974...a34ca99b46)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-19 08:10:30 -08:00
Yuya Nishihara
55dd3a3747 index: do not build hex string to test prefix match, use .as_bytes()
matches() is called from resolve_change_id() loop right now, so it's better to
not allocate String there. Regarding new IdIndex integration, I'll probably make
IdIndex store raw byte ids instead of hexes, and use HexPrefix to look up
range and test prefixes. I think this is basically the same as prefix lookup
in MutableIndex, but I have no idea if we can factor out a common interface.

I made HexPrefix store (Vec<u8>, bool) instead of (Vec<u8>, Option<u8>) so
both min/partial prefixes can be borrowed as slice.
2023-01-19 22:41:29 +09:00
Yuya Nishihara
7e0ba8c002 index: abstract target type of HexPrefix by leveraging ObjectId trait
Another option is HexPrefix<T: ObjectId>, but we might want to build HexPrefix
once, and test it against CommitId and ChangeId.
2023-01-19 22:41:29 +09:00
Mike Forster
c6a4b2cdfc Also update MSRV in flake.nix
This got lost in an unfortunate merge.

Apparently I need to learn better how to use `jj` properly.
2023-01-19 11:03:36 +01:00
Michael Forster
27228ce292 Update MSRV to 1.61
This is needed for compatibility with the sapling dag crate.
2023-01-19 10:29:39 +01:00
Yuya Nishihara
139fe08419 templater: fix id of brackets-prefix format to respect total length
I think the intent of '- 1' here is the separator length, which was
originally ':'. Alternatively, we can ensure that prefix + remainder is
always 12 chars.
2023-01-19 16:41:50 +09:00
Yuya Nishihara
d6c6cdb45c templater: store type-erased version of commit/change id
It's unlikely we'll need to discriminate commit/change id types while
templating, so let's unify them. Since ObjectId trait isn't object safe,
I decided to simply store bytes instead of Box<dyn ObjectId>.
2023-01-19 16:41:50 +09:00
Yuya Nishihara
0f4269a141 templater: micro-optimize short/shortest hex operation 2023-01-19 16:41:50 +09:00
Yuya Nishihara
38e6924482 templater: move CommitOrChangeIdKeyword functions to CommitOrChangeId
CommitOrChangeIdKeyword is no longer needed.
2023-01-19 16:41:50 +09:00
Yuya Nishihara
bf58051c55 templater: split tag structs for commit_id/change_id property
These structs are basically functions taking &Commit, so there's no point
to abstract them.
2023-01-19 16:41:50 +09:00
Martin von Zweigbergk
ff3edb642f github: build and test all targets
It seems that at least examples are not included in the default set of
targets, and we clearly want to check that the examples compile, as
that's an important reason we have them. We don't have any tests for
the examples yet, but let's add the flag now so we don't forget it
later.
2023-01-18 23:03:30 -08:00
Michael Forster
536ac87b11 Configure nix development shell environment
This gets used by `nix develop`, or automatically by `direnv` if you have it
installed.

The binary versions are pinned to the versions recommended by `contributing.md`.

```
>> cargo --version
cargo 1.60.0 (d1fd9fe 2022-03-01)

>> rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)

>> cargo fmt --version
rustfmt 1.5.1-nightly (3984bc5 2023-01-17)

>> cargo clippy --version
clippy 0.1.60 (7737e0b 2022-04-04)
```
2023-01-19 06:45:50 +01:00
Michael Forster
0ddf550369 Configure a formatter for Nix.
I've choosen nixpkgs-fmt because it's the one whose output is most similar to
the current style.
2023-01-19 06:45:50 +01:00
Martin von Zweigbergk
5b40eda47a cli: add a way to add custom global flags
Our internal build at Google needs a custom global flag, which lets
the user pass flags into C++ code we use for our custom backends. This
provides a way of achieving that.
2023-01-18 17:24:05 -08:00
Martin von Zweigbergk
0f8622dd5c repo: move test_id_index() into a tests module
This is the usual convention (to save on compilation time when not
running tests).
2023-01-18 16:59:16 -08:00