Commit graph

1749 commits

Author SHA1 Message Date
Martin von Zweigbergk
0870c47559 cli: on init, don't crash when Git repo doesn't exist 2022-11-03 19:27:17 -07:00
Martin von Zweigbergk
650853401d tests: replace test env path in output by $TEST_ENV
Mercurial's test runner does something like this.

I considered replacing `\` by `/` everywhere, but we use `\` in
graph-log output quite frequently, so it doesn't seem worth it.
2022-11-03 19:27:17 -07:00
Yuya Nishihara
1c4888f769 revset: report bad number of arguments with span 2022-11-03 09:41:04 +09:00
Yuya Nishihara
b938b5e907 revset: report invalid string argument with span
Also dropped "found: {}" from the error summary as it's obvious.
2022-11-03 09:41:04 +09:00
Yuya Nishihara
aeee0acd08 revset: report unknown function with span 2022-11-03 09:41:04 +09:00
Yuya Nishihara
fdbd44571d revset: report unparsable file path with span 2022-11-03 09:41:04 +09:00
Yuya Nishihara
65c903869c revset: wrap RevsetParseError to optionally have code span
The idea is to (ab)use pest::error::Error type to pretty-print error
message with code span. pest::error::Error will be constructed upfront
to erase lifetime from Span<'i>/Position<'i>.
2022-11-03 09:41:04 +09:00
Yuya Nishihara
f4cb91c7dd revset: remove pre-calculation of arguments count 2022-11-03 09:41:04 +09:00
Yuya Nishihara
1d4b5fd8a7 revset: add helper functions that extracts function arguments
These functions doesn't return inner Pairs but Pair so that the Span of
the matching tokens can be easily obtained.
2022-11-03 09:41:04 +09:00
dependabot[bot]
e4e4fe4461 github: bump github/codeql-action from 2.1.29 to 2.1.30
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.29 to 2.1.30.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](ec3cf9c605...18fe527fa8)

---
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>
2022-11-02 09:33:52 -07:00
Martin von Zweigbergk
66838cd532 cli_util: avoid exit() in handle_command_result()
We try to keep the calls to `exit()` in one place. I seem to just have
missed this case in an earlier cleanup.
2022-11-01 17:46:00 -07:00
Benjamin Saunders
de1dc4ca13 tesutils: replace lazy_static with std::sync::Once 2022-11-01 12:23:07 -07:00
Yuya Nishihara
62511f7cad revset: extend file() predicate to accept more than one paths
'file(a, b)' could be expressed as 'file(a) | file(b)', but the former is
easier to type and can be evaluated efficiently without optimization step.
2022-11-02 01:02:37 +09:00
Yuya Nishihara
fba6741c23 revset: resolve file path at parse() stage
Baby step towards embedding matcher in RevsetExpression. If we had a fileset
language or regex pattern, we would probably want to parse it at this stage
so the syntax error can be reported without evaluation.
2022-11-02 01:02:37 +09:00
Yuya Nishihara
78c0cf81bf revset: pass workspace context around parse() functions
The next commit will move file path resolution to parse().
2022-11-02 01:02:37 +09:00
Yuya Nishihara
2193d7768d cli: add stub function to parse revset with workspace context
parse() will take a workspace context to resolve file paths.
2022-11-02 01:02:37 +09:00
Glen Choo
4ebeb95203 cli: print clap errors through Ui
Use clap::Command::try_get_matches_from() to parse args, and handle the
resulting error as a CommandError. The exit code 2 matches the exit code that
clap would output (this is tested by test_alias).

With this new abstraction, teach the clap output to respect "ui.color"
(--color doesn't seem to be understood). We'll also make use of it when
we route output through the pager.

The "errors" returned by try_get_matches_from() can be found at
https://docs.rs/clap/latest/clap/error/enum.ErrorKind.html. I've tested:

- no args
- --help
- help subcommand
- --version
- subcommand with --help
- subcommand with bad args
2022-11-01 07:35:25 +08:00
Glen Choo
470c9f3a5f ui: add write_stderr()
This lets us write to stderr, but unlike write_error(), this won't write
with formatting. This will be used for preformatted strings, e.g. those
coming from clap.
2022-11-01 07:35:25 +08:00
Glen Choo
a52c32adef ui: add color field
This gives us a convenient way to read the color setting when handling
errors from clap.
2022-11-01 07:35:25 +08:00
dependabot[bot]
38ee349cc2 cargo: bump once_cell from 1.15.0 to 1.16.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.15.0...v1.16.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-31 09:13:00 -07:00
dependabot[bot]
43cfe5488c cargo: bump clap_mangen from 0.2.3 to 0.2.4
Bumps [clap_mangen](https://github.com/clap-rs/clap) from 0.2.3 to 0.2.4.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_mangen-v0.2.3...clap_mangen-v0.2.4)

---
updated-dependencies:
- dependency-name: clap_mangen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-31 09:10:42 -07:00
Yuya Nishihara
55184237e1 cli: suggest 'jj init --git-repo' if .git directory already exists
I made new empty repository by mistake, and didn't notice it until I ran
'jj status'.
2022-10-31 01:00:40 +09:00
Martin von Zweigbergk
7947ba16f1 cleanup: use imported UserError variant instead of qualifying
We already have the variant imported and we use it so much that it
seems reasonable to use it instead of qualifying it by the
`CommandError` type.
2022-10-29 17:56:14 -07:00
Martin von Zweigbergk
416a36a59c git: don't abandon root commit when all refs are gone
If you remove all refs from the backing Git repo and then run `jj git
import`, we would see that all commits disappeared from the Git repo,
so we would remove them from the jj repo too. However, we do that by
doing a history walk from old heads to the new heads, which includes
the root commit when the new heads is an empty set. That means that we
mark the root commit as abandoned, which led to a crash in
`rewrite.rs` (when we try pick the root commit's first parent to use
as parent for rebased commits).
2022-10-29 03:02:26 -07:00
Martin von Zweigbergk
20eb9ecec1 git: don't abandon HEAD commit when it loses a branch
I was trying to create a reproduction script for #412, but the script
ran into another bug first. The script removed all the local and
remote branches from the backing Git repo. I noticed that we would
then try to abandon all commits. We should still count Git HEAD's
target as visible and not try to abandon it. This patch fixes that.
2022-10-29 03:02:26 -07:00
Benjamin Saunders
cf5b86b9b7 cli: style tweak 2022-10-28 11:51:53 -07:00
Benjamin Saunders
01bb1e67da workspace: fail gracefully on non-Unicode paths 2022-10-28 11:51:53 -07:00
Benjamin Saunders
3d1ac8b933 repo: propagate I/O errors gracefully from ReadonlyRepo::init 2022-10-28 11:51:53 -07:00
Benjamin Saunders
cfa46c50e2 workspace: propagate I/O errors gracefully 2022-10-28 11:51:53 -07:00
Martin von Zweigbergk
8e2dd4b406 cli: include tags as upstream commits to exclude in default log revset
Sometimes a tagged commit is not in any branch on the remote, but we
should still consider them upstream and not include them in the
default log template.

This was reported by @colemickens but now that I think about it, I
remember seeing such commits in the Git core repo (v1.4.4.5 and a few
commits before it were never merged into main).

We don't have a good way of testing this because we don't have a
command for creating tags.

Closes #681
2022-10-27 20:56:41 -07:00
Martin von Zweigbergk
95638d453c progress: use clamp() for readability
This was actually what I meant in my code-review comment but I used
the wrong word ("clip") :) I wasn't going to bother changing it, but
Clippy nightly just started warning about it.
2022-10-27 17:47:12 -07:00
Martin von Zweigbergk
597e10103f repo: remove unused error type 2022-10-27 17:46:46 -07:00
Martin von Zweigbergk
2b64e52b4d repo: inline single-user init_repo_dir()
The function has only one caller since 25b922cd0b and it's pretty
small. Inlining also means we can reuse the joined paths created in
it, so I did that by extracting variables for them.
2022-10-27 17:46:13 -07:00
Martin von Zweigbergk
3cdcf6cf3d docs: explain that we don't support shallow clones (#675) 2022-10-27 06:56:34 -07:00
Yuya Nishihara
59717aa187 revset: remove redundant candidates argument from merges()
Since 'merges()' just filters the candidates set per item, it doesn't need
a candidates argument. Perhaps, 'merges(x)' could be a predicate to select
merge commits within a subgraph 'x', but I don't know if that would be
useful.
2022-10-27 21:33:35 +09:00
Yuya Nishihara
373c63b414 revset: remove redundant candidates argument from filter predicates 2022-10-27 21:33:35 +09:00
Yuya Nishihara
f48675ad90 revset: evaluate optimized expression 2022-10-27 21:33:35 +09:00
Yuya Nishihara
4d5936983a revset: optimize filter expression to minimize candidates set
Since 'filter(expr)' is identical to 'expr & filter()', it can be rewritten
in order to minimize the candidates set to be scanned.

The implementation is somewhat similar to revsetlang.optimize() of Mercurial,
but I've split the tree rewriting logic to several steps. I think that's good
for maintainability and should help us conclude that a recursion will
eventually terminate.
2022-10-27 21:33:35 +09:00
Yuya Nishihara
cfae28575b revset: add explicit RevsetExpression::All variant
This isn't strictly necessary, but is useful while getting rid of
redundant 'all() &' expression.
2022-10-27 21:33:35 +09:00
Yuya Nishihara
4337a997cf revset: unify FilterRevset variants at RevsetExpression level
This helps to match '(filter, _) | (_, filter)' to rewrite the expression
tree. Only one predicate is allowed for now, but I think it can be extended
to internalize 'f(c) & g(c)' as '(g*f)(c)' to eliminate redundant lookup
of commit object.
2022-10-27 21:33:35 +09:00
Yuya Nishihara
030e0069f6 revset: reorder match arms in evaluate_expression() to group filter stuff 2022-10-27 21:33:35 +09:00
dependabot[bot]
9548b6ad49 github: bump github/codeql-action from 2.1.28 to 2.1.29
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.28 to 2.1.29.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](cc7986c02b...ec3cf9c605)

---
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>
2022-10-26 20:44:10 -07:00
Benjamin Saunders
78f2de20f0 cli: erase progress feedback on completion 2022-10-24 12:52:41 -07:00
Benjamin Saunders
e773709e31 cli: draw bar in progress report 2022-10-24 12:52:41 -07:00
Benjamin Saunders
3dd2cbf799 cli: limit progress report update rate 2022-10-24 12:52:41 -07:00
Benjamin Saunders
f11b3d2476 cli: factor progress reporting out into its own module 2022-10-24 12:52:41 -07:00
Benjamin Saunders
9381765739 cli: fix cursor flicker during progress reports 2022-10-24 12:52:41 -07:00
dependabot[bot]
27937e6787 github: bump actions/upload-artifact from 3.1.0 to 3.1.1
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.0 to 3.1.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](3cea537223...83fd05a356)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 10:55:50 -07:00
Martin von Zweigbergk
c1a008a0fe readme: avoid using "I" since we're now several people contributing 2022-10-24 10:52:38 -07:00
Martin von Zweigbergk
06b99b2a92 readme: PR workflows no longer require many manual steps
Our readme says that pull request require too many manual steps. I
think that refers to the manual abandoning of merged commits that was
necessary before 57ba9a940976; I think the workflow works reasonably
well these days. So let's avoid scaring away potential new users by
mentioning that old problem.
2022-10-24 10:52:38 -07:00