Commit graph

2034 commits

Author SHA1 Message Date
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
dependabot[bot]
f1f38b2a01 cargo: bump serde from 1.0.146 to 1.0.147
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.146 to 1.0.147.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.146...v1.0.147)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 10:51:00 -07:00
dependabot[bot]
6a906da780 cargo: bump textwrap from 0.15.1 to 0.16.0
Bumps [textwrap](https://github.com/mgeisler/textwrap) from 0.15.1 to 0.16.0.
- [Release notes](https://github.com/mgeisler/textwrap/releases)
- [Changelog](https://github.com/mgeisler/textwrap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mgeisler/textwrap/compare/0.15.1...0.16.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 10:35:10 -07:00
Benjamin Saunders
c03c746f8d cli: report fetch progress continuously 2022-10-23 12:13:25 -07:00
Martin von Zweigbergk
b2e309c9e4 tests: stop libgit2 from reading configs in lib tests too
I had `init.defaultBranch = main` in my global config (just being
rolled out internally at Google, it seems), which made
`test_import_refs_reimport_head_removed()` and
`test_fetch_initial_commit()` fail. This fixes it.
2022-10-23 11:08:22 -07:00
Martin von Zweigbergk
efce1e54e6 tests: extract setup of libgit2 config to lib crate
We have some problems with non-hermetic tests in the lib crate, so
we'll want to reuse the setup code there.
2022-10-23 11:08:22 -07:00
Martin von Zweigbergk
c366795d80 tests: remove obsolete workaround for WorkingCopy reading from $HOME
Since d56ae79d3f, `WorkingCopy` no longer reads `.gitignores`
directly from `$HOME/.gitignore`, so we don't need the workaround to
prevent it in the tests.
2022-10-23 11:08:22 -07:00
Yuya Nishihara
cb2fcde560 revset: implement file(pattern[, candidates]) predicate
The name "file()" is just copied from hg. I'm not sure if it's good in
jj's context, but I couldn't find a better name.
2022-10-24 01:48:00 +09:00
Yuya Nishihara
d5cf2582dc revset: instantiate Workspace in tests where workspace_id is needed
This makes resolve_commit_ids_in_workspace() reusable for file() revset
tests.
2022-10-24 01:48:00 +09:00
Yuya Nishihara
5c52b4e819 revset: introduce wrapper struct to pass around workspace information
More workspace-derived parameters will be added, and I don't think wrapping
with Option for each makes sense because all parameters should be available
if workspace exists.
2022-10-24 01:48:00 +09:00
Yuya Nishihara
efb8c5e58a revset: make filter_by_diff() accept either borrowed or owned matcher
So filter_by_diff() can also be used to evaluate file() revset.

I've never seen Borrow<T> for this sort of abstraction, but it seems a valid
use case of Borrow<T>.

https://stackoverflow.com/a/69318514
https://github.com/rust-lang/rust/blob/1.64.0/compiler/rustc_mir_dataflow/src/framework/cursor.rs#L45
2022-10-24 01:48:00 +09:00
Yuya Nishihara
0e1f098376 cli: add WorkspaceCommandHelper::evaluate_revset(expr)
I'll add more workspace-derived parameters to RevsetExpression::evaluate().
2022-10-24 01:48:00 +09:00
Yuya Nishihara
977cfd3d4a repo_path: make FsPathParseError displayable by itself
So it can be easily embedded in other error types such as RevsetError.
2022-10-24 01:48:00 +09:00
Yuya Nishihara
b885dc75f6 cli: inline repo_paths_from_values()
Unlike matcher_from_values(), this function is trivial and isn't widely
used. Let's simply do .map() and .collect().

TODO comment is relocated to matcher_from_values(). I think glob and
fileset-like stuff will be added to the matcher parser, not to the
'Path -> RepoPath' function. And it's probably implemented in lib crate.
2022-10-22 12:40:43 +09:00
Yuya Nishihara
50f327768c cli: move repo_paths|matcher_from_values() to WorkspaceCommandHelper
args.remove resolution in cmd_sparse() is reordered to accommodate with
borrow checker.
2022-10-22 12:40:43 +09:00
Yuya Nishihara
d635d02f06 cli: add WorkspaceCommandHelper::parse_file_path() for convenience
WorkspaceCommandHelper knows the context where user file pattern should
be resolved.
2022-10-22 12:40:43 +09:00