Commit graph

2383 commits

Author SHA1 Message Date
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
Samuel Tardieu
d3789cb28d refactor: extract operation commands into commands/operation module 2023-01-18 19:54:59 +01:00
Samuel Tardieu
3d09f675bd refactor: extract branch commands into commands/branch module 2023-01-18 19:54:59 +01:00
Samuel Tardieu
8f8fd7c89a refactor: extract git commands into commands/git module 2023-01-18 19:54:59 +01:00
Samuel Tardieu
f5e3db74bf refactor: move commands mod into its own directory 2023-01-18 19:54:59 +01:00
Martin von Zweigbergk
40f94b0d4b cli: rename print to cat
`jj cat` better matches `hg cat` and, of course, `cat`. I apparently
called it `jj print` when I added it in 7a013a59ae because I haven't
found `hg cat` useful for actually concatenating files. That's still
true, and I don't know if we will ever bother to teach `jj cat` to
actually concatenate files, but I think the familiarity of `cat` is
more important.

For reference, Git calls it `git show <rev>:<file>`.

I kept `print` as an alias and added a test for it. I also documented
the test better.

By the way, I've considered adding a command for writing from stdin
directly to a specific commit. If we ever do, it might make sense to
call that command `write` (e.g. `echo foo | jj write -r @-
README.md`). Then it would make sense to add `read` as an alias to
`cat`. I'm not sure that's a good idea, but let's leave that for later
anyway.
2023-01-18 10:10:02 -08:00
Yuya Nishihara
2de3034ebe cli: obtain repo from transaction, not from WorkspaceCommandHelper
I'll make WorkspaceCommandHelper inaccessible while transaction is in
progress. This will probably clarify which repo the caller expects to
operate on.
2023-01-18 09:00:21 -08:00
Yuya Nishihara
7a83305e71 cli: reorder code to slightly narrow scope of transaction
This helps to make start_transaction() borrow &mut self, and I think it's
better to check command arguments earlier.
2023-01-18 09:00:21 -08:00
Yuya Nishihara
3fb561fd44 cli: simply pass repo in to check_rebase_destination() 2023-01-18 09:00:21 -08:00
Yuya Nishihara
11c6903786 transaction: remove useless Option wrapping MutableRepo 2023-01-18 09:00:21 -08:00
Martin von Zweigbergk
985555f393 git_backend: avoid redoing some steps when retrying in write_commit()
By inlining `wite_commit_internal()` into `write_commit()`, we can
avoid redoing some steps when we retry. This includes taking the mutex
lock, and reading the tree object and parent commits. It also means
that we avoid cloning the input commit object, which we otherwise
would even in the non-retrying case. I haven't measured if any of this
makes a significant difference, but I think it also slightly
simplifies the code, so it doesn't have to.
2023-01-17 23:12:50 -08:00
Ilya Grigoriev
606eefa8c4 A BTree-based index of commit & change ids to optimize unique_prefix
This is fast enough to be used on medium-sized repositories such as git/git.
It is a bit slow, but bearable, on huge repositories such as torvalds/linux.

There is 0 performance penalty if the display of unique prefixes is disabled

A trie-based implementation will be submitted for consideration in a
follow-up PR. It is faster, but more complicated.

**Update:** I also just discovered https://sapling-scm.com/docs/internals/indexedlog/

There are three important aspects of performance that seemed relevant:

1. Speed of computing the shortest unique prefix per id. It is worlds faster
  than the naive implementation before this commit. It can be optimized
  furher by using a trie or maybe the `fst` crate.

2. Speed of inital loading of the index that happens before the first commit is
  shown. This is the part that's noticeable but bearable on torvalds/linux. 
  
  This could be optimized by storing a sorted list of commit and change ids on
  disk.  This would likely involve reworking the `Index`.

  Failing that, the speed of inital loading doesn't change if a trie is used
  and would likely be worse with the `fst` crate

3. Memory use is unremarkable here. I don't have good tools to measure it
  precisely, but it does not balloon to gigabytes even on the linux repo.
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
e7c434d492 Make ui.unique-prefixes default to brackets 2023-01-17 22:01:09 -08:00
Ilya Grigoriev
67b81a77b8 Config: ui.unique-prefixes to show id shortest unique prefixes
Currently, the possible values are `underscore` and `none`. For now, `none`
is the default, since the `underscore` value messes up copy and pasting of
ids. In the future, an `underline` value should be implemented and will
likely become the default.

Screenshot of `underscore`: https://user-images.githubusercontent.com/4123047/212502483-4119fb17-0601-4335-9770-196e36a6bc31.png
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
19d341d32a Templater: naive implementation of shortest prefix highlight for ids
This creates a templater function `short_underscore_prefix` for commit and
change ids. It is similar to `short` function, but shows one fewer hexadecimal
digit and inserts an underscore after the shortest unique prefix.

Highlighting with an underline and perhaps color/bold will be in a follow-up
PR.

The implementation is quadratic, a simple comparison of each id with every
other id. It is replaced in a subsequent commit. The problem with it is that,
while it works fine for a `jj`-sized repo, it becomes is painfully slow with a
repo the size of git/git. 

Still, this naive implemenation is included here since it's simple, and could
be used as a reference implementation. 

The `shortest_unique_prefix_length` function goes into `repo.rs` since that's
convenient for follow-up commits in this PR to have nicer diffs.
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
c34b2328c0 Index: Expose an iterator over all entries
Importantly, this includes the commits that are not visible and
thus not in the `all()` revset.
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
10794461b9 Templater: Pass Repo to CommitOrChageIdShortest template objects
It will be necessary to compute the shorter unique prefix.
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
dae42ea34a Templater: change some names from "shortest" to "short"
This matches the templater function name
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
68ad712e12 Templater: Combine Change and Commit id templates
They will both need the unique prefix functionality.

Change ids previously were just strings.
2023-01-17 22:01:09 -08:00
Ilya Grigoriev
1f6c085c4e Move the definition of Property to before its use 2023-01-17 22:01:09 -08:00
Ilya Grigoriev
3e7791bbc1 Make jj abandon print each abandoned commit once 2023-01-17 21:17:27 -08:00
Ilya Grigoriev
7057ce2183 Test that jj abandon root, specifying same revision twice 2023-01-17 21:17:27 -08:00
Ilya Grigoriev
f2114f63ee jj duplicate: Allow duplicating several commits at once
The `indexmap` crate is used to make `duplicate`'s output have a sane order,
making it easier to test.

It's also used later to remove duplicate revisions in the `abandon` command.
2023-01-17 21:17:27 -08:00
Ilya Grigoriev
12ee2b18cd Git backend: Allow simultaneous rebasing of duplicate commits
Fixes https://github.com/martinvonz/jj/issues/27
Fixes https://github.com/martinvonz/jj/issues/694
2023-01-17 21:17:27 -08:00
Ilya Grigoriev
cb299ac836 Test crash when rebasing duplicate commits at the same time 2023-01-17 21:17:27 -08:00
Ilya Grigoriev
4da6428f1a Make jj duplicate root fail gracefully 2023-01-17 21:17:27 -08:00
Ilya Grigoriev
2af732c828 Tests for jj duplicate 2023-01-17 21:17:27 -08:00
Ilya Grigoriev
a9e7c9bffc Make jj undo work after jj duplicate
Fixes https://github.com/martinvonz/jj/issues/1050

Thanks to Martin for suggesting the exact fix.

The tests go into the new tests/test_duplicate_command.rs, which will be
expanded shortly with other tests depending on this bugfix.
2023-01-17 21:17:27 -08:00
Yuya Nishihara
57c554b75c cli: fix panic on invalid git.fetch/push config value
The default could be overridden by invalid value.
2023-01-18 13:53:45 +09:00
Samuel Tardieu
5d0535276c style: use #[error(transparent)] instead of #[error("{0}")]
This is the canonical way of forwarding an error message with
the "thiserror" crate.
2023-01-17 20:39:39 +01:00
Samuel Tardieu
2832d7c739 config: allow configuration of git remotes for fetch and push operations
The `git.fetch` and `git.push` keys can be used in the configuration file
for the default to use in `jj git fetch` and `jj git push` operations.

By defaut, "origin" is used in both cases.
2023-01-17 19:04:11 +01:00
Benjamin Saunders
e63818998d cargo: specify explicit rev for git dep on dag 2023-01-16 21:37:19 -08:00
Michael Forster
6324d0a644 Disable RUSTSEC-2021-012 advisory for cargo deny 2023-01-16 22:15:55 +01:00
Michael Forster
073505fc8e Add sapling graph formatters as an option. 2023-01-16 22:15:55 +01:00
Michael Forster
cf809aefc4 Change the AsciiGraphDrawer interface form &[u8] to &str 2023-01-16 22:15:55 +01:00
Samuel Tardieu
84fc66fe50 gitignore: any character can be backslash-escaped
You may use "abc\\" in .gitignore to ignore a file named "abc\". In this
case, removing training spaces on "abc\\ " must result in "abc\\" as the
trailing space is not escaped, the preceeding backslash being part of
the previous "\\" escaping sequence.
2023-01-16 21:35:54 +01:00