Commit graph

2363 commits

Author SHA1 Message Date
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
Vamsi Avula
60d1537731 let branches and remote_branches revset functions take needles as arguments
- branches has the signature branches([needle]), meaning the needle is optional (branches() is equivalent to branches("")) and it matches all branches whose name contains needle as a substring
- remote_branches has the signature remote_branches([branch_needle[, remote_needle]]), meaning it can be called with no arguments, or one argument (in which case, it's similar to branches), or two arguments where the first argument matches branch names and the second argument matches remote names (similar to branches, remote_branches(), remote_branches("") and remote_branches("", "") are all equivalent)
2023-01-16 12:15:30 +05:30
Ilya Grigoriev
24ccd80a5c Fix issues with bright color themes
Fixes https://github.com/martinvonz/jj/issues/528 by changing bright yellow
to yellow.

Also, stop using `white` or `bright white` which are hardly visible on bright
themes.

Before (actually before the parent commit):

https://user-images.githubusercontent.com/4123047/212564102-f6e98635-9bde-4392-8b69-5571fdb1303a.png

After:

https://user-images.githubusercontent.com/4123047/212562387-b89a412e-8689-4bdd-9b25-3f5df1a7d31f.png
2023-01-15 22:00:53 -08:00
Ilya Grigoriev
e9e2853ad5 Change (empty) marker from yellow to green
Follows up on  2ccee5456. Not a major change, looks a little more orthogonal
and clear.
2023-01-15 22:00:53 -08:00
Yuya Nishihara
d4ab33951a cli: replace short_commit_description() with commit summary template
resolve_single_rev() would have to parse the template for each revision,
but it's just 5 times at most. Let's start with a simple API. If the template
doesn't capture RepoRef, maybe we can cache it.
2023-01-16 11:53:35 +09:00
Yuya Nishihara
15e51315ec cli: make short_commit_description() compatible with default summary template 2023-01-16 11:53:35 +09:00
Yuya Nishihara
3e50844afa cli: proxy write_commit_summary() of immutable context through workspace helper
I'm going to add 'format_commit_summary(commit) -> String' to replace
short_commit_description(), and it's fundamentally the same as
'write_commit_summary()' except where the output will go. The problem of
adding such method to WorkspaceCommandHelper is that it's super easy to
use wrong repo ref while transaction is in progress. This problem could
be avoided by passing repo ref explicitly, but other methods like
resolve_revset() have the same problem.

One idea to prevent such API misuse is to exclusively borrow the helper:
'start_transaction(&'a mut self) -> Wrapper<'a>'. That's doable, but I'm
not certain that it is the right way to go. Anyway, this isn't the problem
only applies to write_commit_summary(), so I decided to add a convenient
wrapper to WorkspaceCommandHelper.
2023-01-16 11:53:35 +09:00
Yuya Nishihara
8d27bb0f27 cli: fix "workspace list" to use current workspace to format commit summary
It doesn't matter for the default commit-summary template, but it should be
the workspace the user operates on, not the one currently listing.
2023-01-16 11:53:35 +09:00
Yuya Nishihara
4a17bc0302 cli: fix abandon to not reload WorkspaceCommandHelper to get workspace id 2023-01-16 11:53:35 +09:00
Ilya Grigoriev
aef0801917 Fix random seed in all tests that use testutils::user_settings
This doesn't change any tests, but could prevent change ids
randomly matching commit id prefixes from causing tests
to fail in the future.

Follows up on bbd49cdf29, https://github.com/martinvonz/jj/issues/1024
and https://github.com/martinvonz/jj/pull/1033.
2023-01-15 10:15:44 -08:00
Ilya Grigoriev
d5bbf65da1 Update Cargo.lock to make cargo-deny happy
See https://github.com/martinvonz/jj/actions/runs/3920774270/jobs/6702590941
2023-01-14 18:57:48 -08:00
Ilya Grigoriev
50321f851f revsets.md: Add a sentence to clarify connected 2023-01-14 15:52:51 -08:00
Samuel Tardieu
bdaebf33c4 style: do not dereference self to perform pattern-matching
Dereferencing `self` as `*self` in order to perform patten-matching
using `ref` is unnecessary and will be done automatically by the
compiler (match ergonomics, introduced in Rust 1.26).
2023-01-14 19:28:24 +01:00
Samuel Tardieu
c6d9024ef3 revset: ignore valid commit ids unknown to jj 2023-01-14 18:29:35 +01:00
Samuel Tardieu
efceccb17d refactor: separate timestamp related utilities in time_util module 2023-01-14 16:07:09 +01:00
Samuel Tardieu
3d870068c2 log: add (empty) in front of an empty commit description 2023-01-14 16:00:42 +01:00
Samuel Tardieu
f563e550c4 template: add "empty" template item 2023-01-14 16:00:42 +01:00
Samuel Tardieu
665f7c5917 style: description template extractor
This also prevents the creating of an extra empty String when
the description is empty.
2023-01-14 15:52:31 +01:00
Yuya Nishihara
bbd49cdf29 tests: stabilize change id in test_resolve_symbol_commit_id()
Hopefully fixes #1024.
2023-01-14 23:49:16 +09:00
Yuya Nishihara
a3a495a140 cargo: drop dependency on "uuid" 2023-01-14 23:48:02 +09:00
Yuya Nishihara
ca2e9fe6d1 git: simply use rand::random() to generate ref preventing gc
We don't care the ref content as long as it is unique, so using threaded
RNG should be fine.

This change means refs/jj/keep will now contain refs of the following
forms:

 - new create_no_gc_ref(): 0f8d6cd9721823906cfb55dac99d7bf5
 - old create_no_gc_ref(): 0f6d93fe-0507-4db8-ad0a-6317f02e27b9
 - prevent_gc(commit_id):  0f9c15100b6f1373f38186357e274a829fb6c4e2
2023-01-14 23:48:02 +09:00