Commit graph

5496 commits

Author SHA1 Message Date
Yuya Nishihara
81837897dc index: extract dir.join("operations") to private method 2024-02-12 19:38:36 +09:00
Martin von Zweigbergk
48a9f9ef56 repo: use Transaction for creating repo-init operation
Since the operation log has a root operation, we don't need to create
the repo-initialization operation in order to create a valid
`ReadonlyRepo` instance. I think it's conceptually simpler to create
the instance at the root operation id and then add the initial
operation using the usual `Transaction` API. That's what this patch
does.

Doing that also brought two issues to light:

 1. The empty view object doesn't have the root commit as head.
 2. The initialized `OpHeadsStore` doesn't have the root operation as
     head.

Both of those seem somewhat reasonable, but maybe we should change
them. For now, I just made the initial repo (before the initial
operation) have a single op head (to compensate for (2)). It might be
worth addressing both issues so the repo is in a better state before
we create the initial operation. Until we do, we probably shouldn't
drop the initial operation.
2024-02-11 21:19:30 -08:00
Martin von Zweigbergk
305a507ae3 repo: move creation of repo-init operation to end of init()
Since we now have a root operation, we don't need the
repo-initialization operation to create the repo. Let's move it later
to clarify that.
2024-02-11 21:19:30 -08:00
Aleksey Kuznetsov
dce99cf1f8 cli: add short -b option for --branch in jj git fetch 2024-02-11 09:20:02 +05:00
Benjamin Brittain
416bde236a cli: inform the user of the command which disables the hint 2024-02-10 19:07:38 -05:00
Ilya Grigoriev
a9c3af8153 test_local_working_copy: use std::fs:write instead of OpenOptions 2024-02-10 16:06:28 -08:00
Ilya Grigoriev
b2e37d448b clippy: add truncate option as suggested by clippy
In the next commit, I replace the whole thing with
std::fs::write, but I'll leave this here in case
the next commit is somhow incorrect
2024-02-10 16:06:28 -08:00
Ilya Grigoriev
a88c06068e clippy: new nightly fixes
For some reason, clippy also suggested surrounding
`self.value` with parentheses. Not sure whether
that's a clippy bug.

Cc: https://github.com/rust-lang/rust-clippy/issues/12268
2024-02-10 16:06:28 -08:00
Aleksey Kuznetsov
afebea6e73 cli: make jj show accept a template to render its output 2024-02-10 21:54:52 +05:00
jyn
bca905a26e document the jj equivalent of git reset --soft
i did the following things:

1. make some changes to the working copy
2. run `jj commit`
3. before i added a description, i decided i didn't want to commit yet. in git, the way to do this is to delete the contents of the editor; git sees that it is blank and aborts the commit. in jj, this doesn't work, because descriptions are allowed to be empty.

now i have the following jj state:
```
; jj log --stat
@  pokrsyvs github@jyn.dev 2024-02-06 21:48:17.000 -05:00 ddd6217f
│  (empty) (no description set)
│  0 files changed, 0 insertions(+), 0 deletions(-)
◉  lqqmzmku github@jyn.dev 2024-02-06 21:48:02.000 -05:00 HEAD@git b03bf3de
│  (no description set)
│  config/jj.toml | 2 +-
│  1 file changed, 1 insertion(+), 1 deletion(-)
◉  xqkmwvwp github@jyn.dev 2024-02-06 21:47:08.000 -05:00 master b673f97b
```
i want to undo the most recent commit, `lqqmzmku`. i'm used to doing this with `git reset --soft HEAD~`, which makes the parent `xqkmwvwp` and leaves the change to `config/jj.toml` on disk while removing it from the git history; basically `lqqmzmku` would go back to being the working copy.

i found that `jj move` does what i want, but it took a lot of trawling the options, it wasn't obvious, and i couldn't find `git reset` mentioned in the docs.
2024-02-10 08:49:03 -08:00
dependabot[bot]
785f2f5776 cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [either](https://github.com/rayon-rs/either).


Updates `either` from 1.9.0 to 1.10.0
- [Commits](https://github.com/rayon-rs/either/compare/1.9.0...1.10.0)

---
updated-dependencies:
- dependency-name: either
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-10 17:42:41 +09:00
dependabot[bot]
6d1faf9b03 Update strsim (changes tests), clap, clap_complete
This is #3002 with tests rerun to account for changes
to `strsim`, as @thoughtpolice noticed in
https://github.com/martinvonz/jj/pull/3002#issuecomment-1936763101

The string similarity changes include an example that
seems better and one that seems worse. Decreasing
the threshold definitely makes things worse.
2024-02-10 00:01:47 -08:00
Yuya Nishihara
917109745f cargo: bump itertools to 0.12.1 2024-02-10 09:15:30 +09:00
Yuya Nishihara
e908bd9a17 simple_op_store: use TryFrom<i32> instead of deprecated from_i32() 2024-02-10 09:15:30 +09:00
Yuya Nishihara
7aa7cbe5ff cargo: bump prost to 0.12.3 2024-02-10 09:15:30 +09:00
Yuya Nishihara
421ab592be cargo: bump gix to 0.58.0, migrate to ObjectId::try_from()
The panicking conversion function appears to be renamed, and try_from() is
added instead.
2024-02-10 09:15:30 +09:00
Yuya Nishihara
e943a5b092 templater: parse negative integer as unary operator and literal
Follows up 9702a425e5 "Allow negative numbers in the template grammar."
Since we've added parsing rules for operator expressions, it makes sense to
parse unary '-' as operator.
2024-02-10 09:15:21 +09:00
Austin Seipp
5b517b542e rust: bump MSRV to 1.76.0
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-09 15:48:01 -06:00
Austin Seipp
b18201eff9 chore: nix flake update
This is to get the latest version of `rustc`, which was released this week.
Needed for follow up MSRV bump.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I9153ea8f184f9b46a073671f623ef9f63a3f5036
2024-02-09 15:48:01 -06:00
Austin Seipp
c8f703f14b docs: fix some automerge fallout
I enabled automerge for #2994, but forgot to actually *push* my changes
before resolving all the conversations, so GitHub insta-merged it.

This just addresses Ilya and Philip's final comments on #2994.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-09 12:36:28 -06:00
Austin Seipp
015c52bcdc docs: document git.fetch and git.push config options
Someone on Discord asked this exact question, but these options apparently
weren't documented when they were added in the `0.7.0` release.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-09 12:03:42 -06:00
Martin von Zweigbergk
6c1aeff7a9 working copy: materialize symlinks on Windows as regular files
I was a bit surprised to learn (or be reminded?) that checking out
symlinks on Windows leads to a panic. This patch fixes the crash by
materializing symlinks from the repo as regular files. It also updates
the snapshotting code so we preserve the symlink-ness of a path. The
user can update the symlink in the repo by updating the regular file
in the working copy. This seems to match Git's behavior on Windows
when symlinks are disabled.
2024-02-09 09:20:24 -08:00
Martin von Zweigbergk
b253a28788 merge: add as_normal(), taken from RefTarget
The `RefTarget::as_normal()` function is not specific to `RefTarget`,
and I plan to use it from `local_working_copy`.
2024-02-09 09:20:24 -08:00
Martin von Zweigbergk
5a898b16a8 working_copy: handle symlink outside write_path_to_store()
The `write_path_to_store()` has almost no overlapping code between the
handling of symlinks and regular files, which suggests that we should
move out the handling of symlinks to the caller (there's only one).
2024-02-09 09:20:24 -08:00
Jonathan Tan
ec4bb4ffa3 workspace: create transaction using workspace_command
Using workspace_command means that we record the command arguments into
the ops log.

This also allows us to avoid a clone of an Arc.
2024-02-09 01:24:09 -08:00
Jonathan Tan
33f3a420a1 workspace: recover from missing operation
If the operation corresponding to a workspace is missing for some reason
(the specific situation in the test in this commit is that an operation
was abandoned and garbage-collected from another workspace), currently,
jj fails with a 255 error code. Teach jj a way to recover from this
situation.

When jj detects such a situation, it prints a message and stops
operation, similar to when a workspace is stale. The message tells the
user what command to run.

When that command is run, jj loads the repo at the @ operation (instead
of the operation of the workspace), creates a new commit on the @
commit with an empty tree, and then proceeds as usual - in particular,
including the auto-snapshotting of the working tree, which creates
another commit that obsoletes the newly created commit.

There are several design points I considered.

1) Whether the recovery should be automatic, or (as in this commit)
manual in that the user should be prompted to run a command. The user
might prefer to recover in another way (e.g. by simply deleting the
workspace) and this situation is (hopefully) rare enough that I think
it's better to prompt the user.

2) Which command the user should be prompted to run (and thus, which
command should be taught to perform the recovery). I chose "workspace
update-stale" because the circumstances are very similar to it: it's
symptom is that the regular jj operation is blocked somewhere at the
beginning, and "workspace update-stale" already does some special work
before the blockage (this commit adds more of such special work). But it
might be better for something more explicitly named, or even a sequence
of commands (e.g. "create a new operation that becomes @ that no
workspace points to", "low-level command that makes a workspace point to
the operation @") but I can see how this can be unnecessarily confusing
for the user.

3) How we recover. I can think of several ways:
a) Always create a commit, and allow the automatic snapshotting to
create another commit that obsoletes this commit.
b) Create a commit but somehow teach the automatic snapshotting to
replace the created commit in-place (so it has no predecessor, as viewed
in "obslog").
c) Do either a) or b), with the added improvement that if there is no
diff between the newly created commit and the former @, to behave as if
no new commit was created (@ remains as the former @).
I chose a) since it was the simplest and most easily reasoned about,
which I think is the best way to go when recovering from a rare
situation.
2024-02-09 00:38:47 -08:00
Jonathan Tan
61a026ff7b workspace: inline is_stale()
A subsequent commit will need to handle the return value of
check_stale_working_copy() in 3 different ways, so a boolean will soon
not be sufficient. In preparation for that, inline is_stale() into its
caller, converting it into a "match".
2024-02-09 00:38:47 -08:00
Jonathan Tan
4d0f1b9746 workspace: refactor for_stale_working_copy
Move this function from cli_util.rs, since workspace.rs is the only
caller. This function will be enlarged in a subsequent commit.
2024-02-09 00:38:47 -08:00
Austin Seipp
91d1205d55 readme: fix [!WARNING] section
Apparently this previously-beta markdown syntax from GitHub "graduated" to a
full feature in such a way that it it actually regressed in features, so doing
this `[!WARNING]` inline inside of a list is no longer valid. Sigh. Scoot it
up a level in the document, and just make it part of the section and not inside
the list.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-08 16:59:55 -06:00
Yuya Nishihara
406f2b6147 templater: retain "++" in parsed tree to provide better error indication 2024-02-09 07:42:54 +09:00
Yuya Nishihara
fd4c5a601c templater: translate symbol rules in error message
This is simplified version of the revset change c4769e0b7c.
2024-02-09 07:42:54 +09:00
Yuya Nishihara
948129e88f templater: evaluate logical operator expressions (||, &&, and !)
#2924
2024-02-09 07:42:54 +09:00
Yuya Nishihara
88a1729f8b templater: parse logical operators (||, &&, and !)
These operator symbols are different from the ones in the revset language. I
have no idea if we need bitwise operators, but we'll probably add comparison
operators. It would look weird if 'x == y & z' were parsed as '(x == y) & z'.
2024-02-09 07:42:54 +09:00
Yuya Nishihara
3c4d90483d templater: sort catch-all arms of ExpressionKind in declaration order
Perhaps this was copy-paste error.
2024-02-09 07:42:54 +09:00
Ilya Grigoriev
12c3be70f4 lib refs.rs: rename TrackingRefPair to LocalAndRemoteRef
As discussed in
https://github.com/martinvonz/jj/pull/2962#discussion_r1479384841, the
previous name is confusing since the struct is used for pairs where the
remote branch is not tracked by the local branch.
2024-02-07 17:06:28 -08:00
Evan Mesterhazy
4c4db67f85 Add comments to cmd_split() and rename some variables
This commit is intended to improve readability and makes no functional changes.
2024-02-07 19:53:05 -05:00
Martin von Zweigbergk
8e4d1af98e release: release version 0.14.0
Thanks to everyone who's contributed!
2024-02-07 15:43:04 -08:00
Yuya Nishihara
1296d20126 templates: use surround() function in default "show" template
This isn't a great example of surround(), but works.
2024-02-08 02:16:47 +09:00
Yuya Nishihara
4f0db3607a cli: fix doc about colocated repo created by "jj git init --git-repo=."
Ref changes are imported and exported automatically so long as jj and git
share the same workspace directory.
2024-02-07 09:12:24 -08:00
Yuya Nishihara
b13cfef095 cli: rename --colocated flag of "jj git init" to --colocate (verb)
"jj git clone" has --colocate flag, so let's stick to it.

#2747
2024-02-07 09:12:24 -08:00
dependabot[bot]
3b196d274c cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [git2](https://github.com/rust-lang/git2-rs).


Updates `git2` from 0.18.1 to 0.18.2
- [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/git2-rs/compare/git2-0.18.1...git2-0.18.2)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-07 10:34:02 -06:00
Yuya Nishihara
3e72c43970 cli: suggest "jj git init" if workspace looks like a plain git repo 2024-02-08 00:34:55 +09:00
Martin von Zweigbergk
1be8225046 docs: explain that approving your coworker's PRs should be avoided
We want to avoid conflicts of interest (both real and
apparent). Better to document this before it happens.

By the way, Ilya and I both work for Google and we have approved lots
of each others' PRs, but we work in very different parts of the
company and I don't think any of the PRs have been specific to
Google's interests.
2024-02-06 21:34:58 -08:00
jyn
d66fcf2ca0 compile integration tests as a single binary
this greatly speeds up the time to run all tests, at the cost of slightly larger recompile times for individual tests.

this unfortunately adds the requirement that all tests are listed in `runner.rs` for the crate.
to avoid forgetting, i've added a new test that ensures the directory is in sync with the file.

 ## benchmarks

before this change, recompiling all tests took 32-50 seconds and running a single test took 3.5 seconds:

```
; hyperfine 'touch lib/src/lib.rs && cargo t --test test_working_copy'
  Time (mean ± σ):      3.543 s ±  0.168 s    [User: 2.597 s, System: 1.262 s]
  Range (min … max):    3.400 s …  3.847 s    10 runs
```

after this change, recompiling all tests take 4 seconds:
```
;  hyperfine 'touch lib/src/lib.rs ; cargo t --test runner --no-run'
  Time (mean ± σ):      4.055 s ±  0.123 s    [User: 3.591 s, System: 1.593 s]
  Range (min … max):    3.804 s …  4.159 s    10 runs
```
and running a single test takes about the same:
```
; hyperfine 'touch lib/src/lib.rs && cargo t --test runner -- test_working_copy'
  Time (mean ± σ):      4.129 s ±  0.120 s    [User: 3.636 s, System: 1.593 s]
  Range (min … max):    3.933 s …  4.346 s    10 runs
```

about 1.4 seconds of that is the time for the runner, of which .4 is the time for the linker. so
there may be room for further improving the times.
2024-02-06 18:19:41 -08:00
Ilya Grigoriev
1741ab22e4 view.rs: clarify some internal function docstrings
Mostly, I was a bit confused that some of these functions return a
`TrackingRefPair` but don't seem to take into account whether the remote
branch is being tracked or not.
2024-02-06 17:52:01 -08:00
Ilya Grigoriev
291ce0c379 docs: minor updates to jj git push --help 2024-02-06 15:51:39 -08:00
Ilya Grigoriev
b20e7ee095 docs: document that git push --deleted only pushes tracked branches
It tries to push all deleted branches, but can only succeed for tracked
branches.

Closes #2946, as there's probably no need to have `--deleted --tracked`
that would only be different in that the warnings wouldn't be printed.
Thanks to @yuja for pointing this out.
2024-02-06 15:51:39 -08:00
Ilya Grigoriev
8fb790118f cli branch rename: change warning when renaming a branch with remotes 2024-02-06 15:41:01 -08:00
Chris Krycho
fc3283817d docs: Add FAQ item for git log
New users often want to know how to just see what `git log` would show.
Putting it in the FAQ isn’t perfect but might help a bit.
2024-02-06 15:03:51 -07:00
Martin von Zweigbergk
b343289238 working_copy: make reset() take a commit instead of a tree
Our virtual file system at Google (CitC) would like to know the commit
so it can scan backwards and find the closest mainline tree based on
it. Since we always record an operation id (which resolves to a
working-copy commit) when we write the working-copy state, it doesn't
seem like a restriction to require a commit.
2024-02-06 12:41:09 -08:00