ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

851 commits

Author SHA1 Message Date
David Barnett
e824c491bf Add a "config" command with "get" and "list" subcommands
Partially fixes #531.
2022-12-27 16:59:20 -06:00
Martin von Zweigbergk
d86ba708a3 repo: add MutableRepo::rewrite_commit() returning CommitBuilder
Same reasoning as the previous commit.
2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
812ef97adb repo: add MutableRepo::new_commit() returning CommitBuilder
Since `CommitBuilder` now has a reference to `MutableRepo`, it's
convenient to create instances of it by calling a method on
`MutableRepo`.
2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
f3208f59c4 store: propagate error from Backend::write_commit() 2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
49b2f3b6ca commit_builder: keep MutableRepo reference
When you're done with the `CommitBuilder`, you're going to have to
call `write_to_repo()`, passing it a mutable `MutableRepo`
reference. It's a bit simpler to pass that reference when we create
the `CommitBuilder` instead, so that's what this patch does.

A drawback of passing in the mutable reference when we create the
builder is that we can't have multiple unfinished `CommitBuilder`
instance live at the same time. We don't have any such use cases yet,
and it's not hard to work around them, so I think this change is worth
it.
2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
5cb3807b26 colors: move defaults from source to file 2022-12-24 07:07:37 -08:00
Martin von Zweigbergk
6514ab2e3a cli: when config is invalid, use default config
When we fail to read the user's config, it seems obviously better to
use the default config than to not use it. It doesn't matter yet, but
it will matter when I've moved color configs out of `formatter.rs` and
into a `.toml` file. Without this change, we'd lose the default
coloring of the error message for config errors.
2022-12-24 07:07:37 -08:00
Martin von Zweigbergk
462f696e4e config: add a README to explain that the config files are not installed 2022-12-24 07:07:37 -08:00
Martin von Zweigbergk
b22a6db7e7 config: move default merge-tool config into config/ directory
I'm about to add more default configs, so it will be good to collect
them in one directory.
2022-12-24 07:07:37 -08:00
Ilya Grigoriev
5a681d31d0 cmd jj log: Move divergent label next to the change id
The divergent label is most relevant when the user is about to
refer to a commit by its change id.

It's also good to put it far from the `conflicts` label, to
reduce confusion between very different concepts that have
similar names.

Finally, I think it is a feature rather than a bug that the
`divergent` label now upsets the alignment of different lines
of `jj log`.
2022-12-22 17:25:16 -08:00
Benjamin Saunders
d99e85269f cli: fix core.excludesFile default when XDG_CONFIG_HOME is set 2022-12-22 10:03:20 -08:00
Yuya Nishihara
48cf32f559 cli: simply assign result of if expression in cmd_describe() 2022-12-23 00:47:22 +09:00
Yuya Nishihara
2550dcae4c cli: include diff summary in commit/describe editor content 2022-12-23 00:47:22 +09:00
Yuya Nishihara
d438f43224 cli: rephrase diff summary header so it can be reused for commit/describe 2022-12-23 00:47:22 +09:00
Yuya Nishihara
e7d9e1ff9c cli: inline diff_util::diff_as_bytes()
I'll add a similar function that uses show_patch() instead of show_diff(),
and I don't think it's worth duplicating _as_bytes() part for that.
2022-12-23 00:47:22 +09:00
Yuya Nishihara
300f744e41 cli: normalize line ending of edited commit description, ensure last newline
Since CR+LF vs LF things shouldn't matter in commit description, it's probably
better to normalize newline characters.

In Mercurial, ui.edit() and changelog.stripdesc() handle line normalization,
and trailing newlines are stripped. In Git, cleanup_message() handles that,
and the last newline is added after stripping trailing newlines.
2022-12-22 14:59:03 +09:00
Yuya Nishihara
6f8fb09609 cli: append "\n" to commit description specified by -m/--message
Otherwise the description set by -m would differ from the one set by editor.
This fixes test_describe() which says "make no changes", but previously "\n"
would be added by the second "jj describe".

As you can see, almost all hashes change in CLI tests. This means in-flight
PRs will need to be rebased to update insta snapshots.

Description text could be normalized by CommitBuilder, but the caller would
have to normalize it beforehand to compare with the current description, so
we would need an explicit function anyway. Another idea is to add a newtype
that represents a normalized description, and make CommitBuilder require it.
Commit::description() will return &Description in place of &str to ensure
that commit.description() == raw_str wouldn't compile.

Git CLI provides --cleanup=<mode> option to switch normalization rules, but
I don't think we'll need such feature.
2022-12-22 14:59:03 +09:00
Yuya Nishihara
986649623d commit_builder: relax type of description parameter
The next commit will introduce a newtype for -m/--message argument which
can be converted Into<String>.

Since CommitBuilder is a thin wrapper, code bloat caused by generic parameters
wouldn't matter. I have another set of commits that makes all builder methods
accept Into/IntoIterator, which will remove some of .clone() calls from tests.
2022-12-22 14:59:03 +09:00
Ilya Grigoriev
18722bbf36 cmd: Remove the -i option to jj restore.
It is superceded by the new options to the `jj diffedit` command.
2022-12-21 08:15:06 -08:00
Ilya Grigoriev
c9706fc0d4 Rename jj touchup to jj diffedit 2022-12-21 08:15:06 -08:00
Ilya Grigoriev
f71ca25ebe cmd: Add --to and --from arguments to jj touchup
This allows touching up a commit while seeing the differences between it and
another arbitrary commit.
2022-12-21 08:15:06 -08:00
Yuya Nishihara
a850c488f9 cli: use fs::read_to_string() to read edited description file
Also removes panic on io::Error. It's unlikely, but could occur if the
edited description contained non-UTF-8 character.
2022-12-21 23:48:51 +09:00
Yuya Nishihara
cc2091aad6 cli: leverage tempfile to create commit description file with random suffix
This should be more reliable as there might be a stale description file
having the exact same random suffix.

Also removes panic on io::Error.
2022-12-21 23:48:51 +09:00
Ilya Grigoriev
0285a203a2 Rearrange branches of if statement in jj git push 2022-12-21 00:52:17 -08:00
Ilya Grigoriev
2f00fcb6b4 jj git push: Make sure each branch is processed at most once 2022-12-21 00:52:17 -08:00
Ilya Grigoriev
fad686f48c Allow jj git push to push multiple branches/changes at once
Also creates short arg `-b` for `--branch`.
2022-12-21 00:52:17 -08:00
Benjamin Saunders
b222bbd10a cli: respect default value of git core.excludesFile 2022-12-21 00:18:55 -08:00
Martin von Zweigbergk
a2d2da4d48 cli: remove unnecessary (?) ArgAction::Append in $[clap]
I think "append" is the default for `Vec`-type fields.
2022-12-18 17:51:58 -08:00
Ilya Grigoriev
dac80ef88c Rename diff_edit.rs to merge_tools.rs
This is important especially since we're about to rename the `touchup` command into `diffedit`.
2022-12-17 22:26:59 -08:00
Ilya Grigoriev
f96f45125e Rename merge-tools.toml to merge_tool_config.toml
I think this fits in better with the other files in this dir
and is more descriptive.
2022-12-17 22:08:50 -08:00
Ilya Grigoriev
8f9cc3f4e8 Instructions and better config for Vim as a diff editor
After I changed `merge-tools.vimdiff.program` to `vim`, using
`vimdiff` as a diff editor wouldn't work at all. 

Out of the box, it's still not a good experience. I included a
recommendation of a plugin to install to make it better.
2022-12-17 22:08:50 -08:00
Daniel Ploch
309a3f91a1 op_heads_store: refactor into an interface and simple implemenation
The implementation has some hoops to jump through because Rust does not allow
`self: &Arc<Self>` on trait methods, and two of the OpHeadsStore functions need
to return cloned selves. This is worked around by making the implementation type
itself a wrapper around Arc<>.

This is not particularly note worthy for the current implementation type where
the only data copied is a PathBuf, but for extensions it is likely to be more
critical that the lifetime management of the OpHeadsStore is properly
maintained.
2022-12-16 10:47:48 -08:00
Yuya Nishihara
af85f552b6 cli: do not unwrap BackendError at resolve_revset() 2022-12-16 13:34:58 +09:00
Yuya Nishihara
4e8f51a983 cleanup: leverage Itertools::try_collect() instead of turbofish
It still requires return type annotation in some places, but should be easier
to type than ::<Result<...

https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.try_collect
2022-12-16 13:34:58 +09:00
Yuya Nishihara
9158c96202 cli: show hint if e.g. checkout revset resolved to multiple revisions
As suggested at
https://github.com/martinvonz/jj/issues/878#issuecomment-1345466602
2022-12-15 22:55:29 +09:00
Yuya Nishihara
6889d64ffc cli: unnest resolve_single_rev() error handling bits
I'll add more code to (Some, Some) arm, so let's extract the successful
case for readability.
2022-12-15 22:55:29 +09:00
Yuya Nishihara
62a38d3e86 cli: add kdiff3 edit-args to stock config 2022-12-15 15:16:50 +09:00
Yuya Nishihara
52e26a8d9a cli: move merge-tools name to [table] header
Even though we need to repeat "merge-tools", I feel it's a bit better to
group parameters by tool name. Tools are sorted by name.
2022-12-15 15:16:50 +09:00
Yuya Nishihara
c86f7f87e4 cli: add comment why stock config isn't add_source()-d to main config_builder 2022-12-15 15:16:50 +09:00
Yuya Nishihara
0a28b2c508 cli: extract stock merge-tools config to file, embed it in binary
I think a separate .toml file is easier to maintain as the merge-tools
table will grow.
2022-12-15 15:16:50 +09:00
Martin von Zweigbergk
7f9a0a2820 cleanup: let new Clippy move variables into format strings
I ran an upgraded Clippy on the codebase. All the changes seem to be
about using variables directly in format strings instead of passing
them as separate arguments.
2022-12-14 21:30:58 -08:00
Martin von Zweigbergk
c8a04d6f69 cli: use .display() instead of debug format in two errors 2022-12-14 21:30:58 -08:00
Yuya Nishihara
cec4d6c214 cli: allow multiple diff outputs
"jj log -p --summary" now shows summary and color-words diff, like
"hg log -p --stat".

Handling of "-p" is tricky. I first considered "-p" would turn on the default
diff output, but I found it would be confusing if "jj log -p --git" showed
both color-words and git diffs. So the default format is inserted only if
no --git nor --color-words is explicitly specified.
2022-12-15 11:41:42 +09:00
Yuya Nishihara
07cf103ac1 cli: pass from/to_tree in to show_diff() instead of TreeDiffIterator
This allows us to generate diff in different formats. There are various ways
to achieve that:

 a. build TreeDiffIterator for each format (this patch)
 b. make TreeDiffIterator clonable
 c. collect TreeDiffIterator and reuse the resulting vec

(a) and (b) are practically the same. (c) would be more efficient if building
and iterating TreeDiffIterator were expensive, but I don't think it is because
Tree is cached by Store. If we add $GIT_EXTERNAL_DIFF-like feature, we'll
probably need Tree objects to snapshot them to /tmp. So I chose (a).
2022-12-15 11:41:42 +09:00
Yuya Nishihara
69e57daa64 cli: enable diff output by 'log --color-words'
It doesn't make sense that --git implies -p, but --color-words doesn't.
2022-12-15 11:41:42 +09:00
Yuya Nishihara
b4d6c9e8da cli: extract helper that resolves diff arguments for log-like commands 2022-12-15 11:41:42 +09:00
Yuya Nishihara
cdf3bfa55f cli: extract default_diff_format() from diff_format_for()
I'll make "jj log -p --summary" show both summary and diff, where -p will
be resolved to the default diff format.
2022-12-15 11:41:42 +09:00
Yuya Nishihara
f26582d0a3 cli: leverage show_patch() helper to implement show command 2022-12-15 11:41:42 +09:00
Martin von Zweigbergk
b28ff2fbd9 cli: use committer timestamp instead of author timestamp in log output
The author timestamp is rarely useful (in my experience). The
committer timestamp, on the other hand, can be useful for
understanding when a change was most recently modified. IIRC, I
originally picked the author timestamp to match the email (which is
the author's), but it's probably not confusing to use the author email
and the committer timestamp. I suspect few users will even reflect on
it.
2022-12-14 15:48:11 -08:00
Daniel Ploch
7cbea42a24 repo: rename BackendFactories to StoreFactories 2022-12-14 14:10:30 -08:00