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

1590 commits

Author SHA1 Message Date
Martin von Zweigbergk
3acb89e7cc merged_tree: remove TreeDiffEntry::source 2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
721aa1238c copies: add a separate diff stream item type with copy info
The goal is to have the new item type know if it represent a copy, a
rename, a deleted rename source, or a regular copy-unrelated item.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
70598498b0 merged_tree: provide separate version of diff_stream() with copy info
I plan to provide a richer version of `TreeDiffEntry` with copy info
(and to make `TreeDiffEntry` itself "poorer"). Most callers want to
know about copies/renames, but at least working copy implementations
probably don't. This patch adds separate `diff_stream()` and
`diff_stream_with_copies()` so we can provide the simpler interface
for callers that don't need copy info.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
fd9a236be5 copies: move CopyRecords to new copies module
Copy/rename handling is complicated. It seems worth having a module
for it. I'm going to add more content to it next.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
aa0fbd9f3f drop "support" for legacy tree config
The tree-level conflicts have worked well in practice and we don't
want to allow users to use legacy trees for new commits. We don't
really support legacy trees very well since 0590f8bece anyway.
2024-08-18 07:19:50 -07:00
Essien Ita Essien
e2a5c83e5c Follow ups on post-submission comments for #4282.
* Derive a bunch of standard and useful traits for `movement_util::Direction`
  as it is a simple type. Importantly `Copy`.
* Return `&'static str` from Direction.cmd()
* Refactor out `MovementArgs` to reduce the number of arguments
  to `movement_util::move_to_commit`.
* Implement `From<&NextArgs/&PrevArgs>` for MovementArgs

Part of #3947
2024-08-18 10:43:08 +01:00
Yuya Nishihara
1be955ea4e diff: simplify conditions whether to emit color-words context lines
This appears to fix redundant "    ..." line for empty diffs.
2024-08-18 12:40:07 +09:00
Yuya Nishihara
9beb57018a diff: split color-words diffing to line-based and refinement stages
This allows us to select rendering function hunk by hunk. For example, a hunk
with lots of small changes could be rendered without interleaving left/right
words. Another good thing is that context line handling can be simplified as
the whole context hunk is available.
2024-08-18 12:40:07 +09:00
Yuya Nishihara
59745fb67f files: allow DiffLineIterator users to specify and retrieve line numbers
The added functions will be used in order to iterate middle hunks which don't
start from line_number = 1.
2024-08-18 12:40:07 +09:00
Yuya Nishihara
2be8e596e2 diff: extract Diff::by_word() function
I'm going to split color-words diffs to by_line() and by_word() stages.

Perhaps, Diff::default_refinement() can be removed once all non-test callers
are migrated.
2024-08-18 12:40:07 +09:00
Benjamin Tan
f258664a2f rewrite: move_commits: do not remove parents of target commits which are outside the target set
This ensures consistency between the commands `jj rebase -r a::` and `jj
rebase -s a`.
2024-08-17 23:27:47 +08:00
Benjamin Tan
e5493e0fc0 rebase: modify tests to include commit's parent branch in log output 2024-08-17 23:27:47 +08:00
Martin von Zweigbergk
749a284354 working_copy: delete path() method from trait
We don't currently use the `path()` method. Not all working copies
even have a relevant path. For example, working copies on Google's
server don't.
2024-08-16 16:55:14 -07:00
Essien Ita Essien
237b41e738 next/prev: refactor movement utilities into cli/src/movement_utils.rs
The code in both cli/src/commands/{next,prev}.rs is identical except
for the direction of movement. This commit pull the parts that make
sense out into cli/src/movement_util.rs so it's easier to see the
differences.

Part of #3947
2024-08-16 23:21:00 +01:00
Essien Ita Essien
c6335ca655 next/prev: Add jj log output to more prev_next tests.
Add gratuitous `jj log` output to more points in the tests.
This makes it easier to understand the intended changes
by literally visualizing the commit tree we are after each movement.

This is at least useful for me since I find the new+squash workflow
confusing.

Test behaviour is not changed.

Part of #3947
2024-08-16 21:28:48 +01:00
Yuya Nishihara
be35ab164c tests: restore snapshots of line/word-oriented diff hunks
test_diff_basic() is now testing file-level changes such as renames.
2024-08-16 22:16:36 +09:00
Matt Kulukundis
2f2e5fb72a copy-tracking: implement copy tracking for external tools 2024-08-16 07:48:43 -04:00
Yuya Nishihara
a973c7b0ea files: replace precomputed has_left/right_content flags with functions
I don't think the iteration cost would matter here, and it doesn't make sense
that has_left/right_content are cached whereas is_unmodified() isn't.
2024-08-16 09:30:30 +09:00
Yuya Nishihara
cca5277184 diff: clarify that DiffLine hunk doesn't have [left, right] diff pair
This will simplify users of line.hunks[] which I'm going to add.
2024-08-16 09:30:30 +09:00
Matt Kulukundis
95e8dd51eb copy-tracking: add support for diff --git 2024-08-15 11:03:39 -04:00
Yuya Nishihara
78c0128ec3 files: make DiffLineIterator accept generic DiffLine iterator
I'm thinking of adding some heuristics to render hunks containing lots of
small word changes differently, in a similar manner to the unified diffs. This
patch might help add some pre/post-processing at consumer.

files::diff() is inlined to caller to get around 'self borrowing.
2024-08-15 20:06:12 +09:00
Yuya Nishihara
8b222e4038 cli: propagate BackendError from tree diffs 2024-08-15 20:02:56 +09:00
Benjamin Tan
ab604b4ecd rewrite::move_commits(): preserve order of parent commits
When rebasing a new child commit on top of the moved commit(s), the
order of the new child commit's parent commits is now correctly
preserved if the original parent commit is now a parent of the moved
commit(s).

Closes #3969.
2024-08-15 17:51:03 +08:00
Benjamin Tan
4a17b9fbe4 rebase: modify tests to avoid printing commit and change IDs
I think they were adding too much noise to commit diffs. Only the tests
focused on skipping rebasing will include the commit and change IDs,
other tests will omit them.
2024-08-15 17:51:03 +08:00
Matt Kulukundis
0b179dcbde copy-tracking: implement copy-tracking for --types 2024-08-14 20:48:43 -04:00
Matt Kulukundis
eccc3e235d copy-tracking: diff --name-only is a no-op 2024-08-14 19:52:19 -04:00
Benjamin Tan
41e99ccdbf diff_util: add copy records tracking to DiffRenderer::show_patch
This allow `jj show --summary` and other commands to include copy
tracking information.
2024-08-14 23:16:17 +08:00
Benjamin Tan
f983021814 cli: add basic tests for show command 2024-08-14 23:16:17 +08:00
Essien Ita Essien
a6d8009097 Define builtin_immutable_heads() as a default revset alias.
* Add `builtin_immutable_heads()` in the `revsets.toml`.
* Redefine `immutable_heads()` in terms of `builtin_immutable_heads()`
* Warn if user redefines `builtin_immutable_heads()`, `mutable()` or
  `immutable()`.
* Update module constant in revset_util.rs from BUILTIN_IMMUTABLE_HEADS
  to USER_IMMUTABLE_HEADS to avoid confusion since it points at
  `immutable_heads()` **and** we now have a revset-alias
  literally named `builtin_immutable_heads()`.
* Add unittest
* Update CHANGELOG
* Update documentation.

Fixes: #4162
2024-08-14 11:32:16 +01:00
Matt Kulukundis
ec99a17ae8 copy-tracking: improve --summary and add --stat
- add support for copy tracking to `diff --stat`
- switch `--summary` to match git's output more closely
- rework `show_diff_summary` signature to be more consistent
2024-08-13 21:37:45 -04:00
Aaron Bull Schaefer
e803bed845 config: expand tilde in ssh key filepaths
Add home directory expansion for SSH key filepaths. This allows the
`signing.key` configuration value to work more universally across both
Linux and macOS without requiring an absolute path.

This moved and renamed the previous `expand_git_path` function to a more
generic location, and the prior use was updated accordingly.
2024-08-13 08:06:43 -07:00
Benjamin Tan
38f6ee8918 cargo: bump git2 to 0.19.0
This includes a bump of `libgit2` to v1.8.1.
2024-08-13 11:47:21 +08:00
Benjamin Tan
e2ab6d4f42 rewrite: migrate move_commits function from rebase command 2024-08-12 21:48:17 +08:00
Matt Kulukundis
5911e5c9b2 copy-tracking: Add copy tracking as a post iteration step
- force each diff command to explicitly enable copy tracking
- enable copy tracking in diff_summary
- post-process for diff iterator
- post-process for diff stream
- update changelog
2024-08-11 17:01:45 -04:00
Matt Kulukundis
34b0f87584 copy-tracking: plumb CopyRecordMap through diff method 2024-08-11 17:01:45 -04:00
Matt Kulukundis
6bae5eaf9d copy-tracking: create a MaterializedTreeDiffEntry type 2024-08-11 17:01:45 -04:00
Matt Kulukundis
e123eb21b9 copy-tracking: add source field to TreeDiffEntry
- add the field and make it compile, but don't use it yet
2024-08-11 17:01:45 -04:00
Matt Kulukundis
8e84c60157 copy-tracking: create an explicit TreeDiffEntry struct 2024-08-11 17:01:45 -04:00
Matt Kulukundis
ee6b922144 copy-tracking: create CopyRecordMap and add it to diff summaries 2024-08-11 17:01:45 -04:00
Matt Kulukundis
e667a2b403 copy-tracking: adjust backend signature
- use a single commit instead of an array of them.  This simplifies the
  implementation.  A higher level api can wrap this when an array of
  commits is desired and those semantics are figured out.
- since this API is directly 1-1 on parents, there are no conflicts
- if we introduce a higher level API that handles lists of commits, we
  may need to restore the conflict/resolved distinction, but for now
  simplify
2024-08-11 17:01:45 -04:00
tinger
6c28ca6436 cli: op show: remove visible alias for positional arg 2024-08-09 15:50:19 +02:00
Yuya Nishihara
9a4cb9e6e8 config: do not parse TOML value expression by write_config_value_to_file()
It's a bit weird that a write() function parses user input, and some callers
doesn't want such flakiness.
2024-08-09 22:39:16 +09:00
Yuya Nishihara
9fb9e732c1 git: resolve relative core.excludesFile path at workspace root
The "git" command appears to chdir() to the --work-tree directory first, then
read() the core.excludesFile file. There's no manual relative path resolution
in "git".

Fixes #4222
2024-08-08 23:05:46 +09:00
Yuya Nishihara
b3ede64472 cargo: bump gix to 0.64.0
config.<type>_by_key() is merged with config.<type>().
2024-08-07 20:32:58 +09:00
Yuya Nishihara
7bdb28f1fe cli: make "op abandon" not fail with multiple op heads
Since "op abandon" just rewrites DAG, it works no matter if the heads are
merged or not. This change will help crash recovery. "op abandon
--at-op=<one-of-the-heads>" can't be used because ancestor operations would be
preserved by the other head.
2024-08-07 10:51:44 +09:00
Yuya Nishihara
399110b1fc op_walk: allow to resolve operation expression from multiple heads
I'll make "op abandon" work without merging op heads.
2024-08-07 10:51:44 +09:00
Yuya Nishihara
8cac8fba5a cli: op diff: consolidate match arms of forward diffs
These two are equivalent. It's still restricted to zero or one removed commits
because I'm not sure how diverged changes should be rendered.
2024-08-07 10:51:23 +09:00
Yuya Nishihara
f7836aa687 cli: obslog: show diffs from all predecessors, not first predecessor
Suppose a squash node in obslog is analogous to a merge in revisions log, it
makes sense to show diffs from auto-merge (or auto-squash) parents. This
basically means a non-partial squash node no longer shows diffs.

This also fixes missing diffs at the root predecessors if there were.
2024-08-07 10:51:23 +09:00
Yuya Nishihara
83ee6489d9 tests: add partial/multi-source squashes to obslog test 2024-08-07 10:51:23 +09:00
Yuya Nishihara
c99f502c31 tests: leverage "squash -m" in obslog test 2024-08-07 10:51:23 +09:00
Yuya Nishihara
92ba6d336d cli: op diff: be more strict about multiple diff sources/destinations
As the doc comment states, this function only supports change of "a single
added and removed commit", "only a single added", or "single removed commit."
It doesn't make sense to show diffs from the parent commit ignoring multiple
removed commits for example.
2024-08-07 10:51:23 +09:00
Ilya Grigoriev
b42e94906d jj run: describe it as a stub in the help text 2024-08-06 17:51:01 -07:00
Ilya Grigoriev
132dfd30e2 describe: warn user of limitations when describing multiple commits
I think it might be nice to have this in the upcoming release, but I'd
like to warn people that their changes will be lost if they aren't
careful, and to not rely on the syntax being fixed just yet.
2024-08-06 11:28:21 -07:00
Ilya Grigoriev
6d1cc7f803 describe multiple commits: instruct user where to put commit descriptions
This seems especially helpful if the descriptions start out empty.
2024-08-06 11:28:21 -07:00
Yuya Nishihara
0b1a6cd9e0 cli: allow any number of trailing dashes in "JJ: describe" line
Because a line without " -------" is allowed, it makes sense to strip other
variants like " --".
2024-08-06 10:15:32 +09:00
Yuya Nishihara
fb3e120092 cli: minor style cleanup in parse_bulk_edit_message() 2024-08-06 10:15:32 +09:00
Yuya Nishihara
f7b8a22c66 cli: remove redundant string concatenation from parse_bulk_edit_message() 2024-08-06 10:15:32 +09:00
Yuya Nishihara
f4dd856f9f ui: do not write() to channel if builtin pager has terminated 2024-08-05 10:34:33 +09:00
Yuya Nishihara
ce2bc8d6b6 ui: include error sources in pager warning
An error in builtin pager can be nested.
2024-08-05 10:21:23 +09:00
Benjamin Tan
35b04f45dc describe: allow updating the description of multiple commits
If multiple commits are provided, the description of each commit
will be combined into a single file for editing.
2024-08-05 02:06:40 +08:00
Ilya Grigoriev
37ccfd5acc built-in pager: write a message to the user if pager failed to start
The message is printed at the end, any text sent to the pager before
then is lost. See
https://github.com/martinvonz/jj/pull/4197#discussion_r1701799135
for a discussion about why that seems OK.
2024-08-03 17:45:18 -07:00
Yuya Nishihara
9ec617534c cli: merge op heads and snapshot working copy by "op log" by default
This partially reverts 543036c753 "cli: run 'op log' without loading repo or
merging concurrent ops." User can now get around the issue by --at-op=@
--ignore-working-copy.
2024-08-03 09:22:26 +09:00
Yuya Nishihara
5bfb3742e8 cli: migrate trivial uses of op_walk::resolve_op_for_load()
Now heads merging can be turned off by --at-op=@.
2024-08-03 09:22:26 +09:00
Yuya Nishihara
2008991749 cli: do not attempt to merge op heads if --at-op=@ is specified
The idea is that --at-op specifies a certain operation, so --at-op=@ can be
interpreted as the option to select _the_ known head operation. This helps
eliminate special cases from "op log" which doesn't snapshot nor merge
concurrent ops.
2024-08-03 09:22:26 +09:00
Yuya Nishihara
b290af8e29 op_walk: include operation ids in multiple match error 2024-08-03 09:22:26 +09:00
Yuya Nishihara
e9d744db32 tests: add crash recovery test from bad GC
The current "op abandon" and "op log" have workarounds to recover from this
situation. Let's make sure they work as expected.
2024-08-03 09:22:26 +09:00
Yuya Nishihara
cf053b7e09 ui: print :builtin pager suggestion as a hint 2024-08-03 09:14:29 +09:00
Yuya Nishihara
b503ecb071 ui: rewrite request_pager() to return early and use stdout instance 2024-08-03 09:14:29 +09:00
Yuya Nishihara
47a4406f4d ui: extract finalize_pager() as UiOutput method 2024-08-03 09:14:29 +09:00
Stephen Jennings
6c41b1bef8 revset: add author_date and committer_date revset functions
Author dates and committer dates can be filtered like so:

    committer_date(before:"1 hour ago") # more than 1 hour ago
    committer_date(after:"1 hour ago")  # 1 hour ago or less

A date range can be created by combining revsets. For example, to see any
revisions committed yesterday:

    committer_date(after:"yesterday") & committer_date(before:"today")
2024-08-01 09:04:07 -07:00
Essien Ita Essien
7c4185cd41 Change conflict hint depending on state of working commit.
To avoid always printing the rebase instructions to fix a conflict
even when a child commit to fix the conflict already exists, implement
the following:

* If working commit has conflicts:
  * Continue printing the same message we print today.

* If working commit has no conflicts:
  * If any parent has conflicts, we print: "Conflict in parent is resolved in working copy".
    Also explicitly not printing the "conflicting parent" here, since a merge commit
    could have conflict in multiple parents.
  * If no parent has any conflicts: exit quietly.
* Update unittests for conflict hinting update.
* Update CHANGELOG
2024-08-01 16:21:24 +01:00
Yuya Nishihara
d0f6f429e1 diff: add "diff" label globally by outer show_diff/patch() functions
It's not so important, but this removes duplicated "diff" labels from template
output. Perhaps, this also fixes "diff access-denied" label in file-by-file
external diffs.

The inner show_*() functions no longer add "diff" labels, but that's okay
because all CLI callers (except for the templater) use DiffRenderer.
2024-08-01 22:56:36 +09:00
Yuya Nishihara
07b0b0676d tests: rerun commit.diff() template test with --color=debug
The added test shows the "diff" label is repeated because of auto-labeling of
templater. The original "--color=always" test is also kept to ensure that color
sequences are unchanged even if we remove one of the "diff" labels.
2024-08-01 22:56:36 +09:00
Yuya Nishihara
052f022479 formatter: make error type of with_label() callback generic
This will help eliminate push/pop_label() calls from show_diff_*().
2024-08-01 22:56:36 +09:00
Yuya Nishihara
f57a7e5eba cli: move cmd_config_list() entry point next to Args struct 2024-08-01 09:54:12 +09:00
Yuya Nishihara
9168500341 cli: split commands/config.rs into sub modules 2024-08-01 09:54:12 +09:00
Yuya Nishihara
dc2b5500ff diff: specify available terminal width by caller, subtract graph width
The width parameter is mandatory so it wouldn't fall back to ui.term_width() by
mistake. The API is getting messy and we might want to extract some parameters
to separate struct.

Fixes #4158
2024-08-01 02:03:03 +09:00
Yuya Nishihara
1977748642 ui: fill in default term width globally and return as usize
I'm going to add more ui.term_width() callers, and it's unlikely we'll have to
set different defaults or error out.
2024-08-01 02:03:03 +09:00
Yuya Nishihara
b2b86825cb cli: move cmd_workspace_update_stale() entry point next to Args struct 2024-07-31 10:21:34 +09:00
Yuya Nishihara
21e1ce4f50 cli: split commands/workspace.rs into sub modules 2024-07-31 10:21:34 +09:00
Yuya Nishihara
a39dd0f176 cli: duplicate cmd_workspace_root() to cmd_root()
Suppose cmd_root() will gain options to print other kind of root paths, it's
probably simpler to inline path handling there instead of turning cmd_root()
into a dispatcher function. If cmd_root() remains with the current form, maybe
we can add aliases.root = ["workspace", "root"] instead.
2024-07-31 10:21:34 +09:00
Danny Hooper
51e11ff7e3 cli: fix: replace obsolete todo with a new one 2024-07-29 14:23:26 -05:00
Scott Taylor
304f6dfc3f workspace: warn if destination doesn't contain path separator
Users may try to run `jj workspace add <name>` without specifying a
path, which results in the workspace being created in the current
directory. This can be confusing, since the workspace contents will also
be snapshotted in the original workspace if it is not sparse. Adding a
warning should reduce confusion in this case.
2024-07-26 18:37:11 -05:00
Scott Taylor
4d8eee3416 test: update workspace path in test case
This test case was creating "workspace1" as a sub-directory of the
default workspace, which seems like a mistake.
2024-07-26 18:37:11 -05:00
Danny Hooper
89f5d16dc0 cli jj fix: add ability to configure multiple tools for different filesets
The high level changes include:
 - Reworking `fix_file_ids()` to loop over multiple candidate tools per file,
   piping file content between them. Only the final file content is written to
   the store, and content is no longer read for changed files that don't match
   any of the configured patterns.
 - New struct `ToolsConfig` to represent the parsed/validated configuration.
 - New function `get_tools_config()` to create a `ToolsConfig` from a `Config`.
 - New tests; the only old behavior that has changed is that we don't require
   `fix.tool-command` if `fix.tools` defines one or more tools. The general
   approach to validating the config is to fail early if anything is weird.

Co-Authored-By: Josh Steadmon <steadmon@google.com>
2024-07-25 13:40:18 -05:00
Danny Hooper
8fe2274584 fake-formatter: add --uppercase and --append formatting behaviors
This allows tests to easily distinguish the effects of multiple formatters that
could be applied during a single `jj fix` command, which is helpful for testing
the feature for configuring multiple formatters on potentially overlapping
filesets.

Uppercase is a counterpart to lowercase. Append exposes the number of changes
and their order of execution in the file content, which provides a terse way of
writing test expectations.
2024-07-25 13:40:18 -05:00
Yuya Nishihara
d6e97883df cli: port description template to templater
This implements a building block of "signed-off-by line" #1399 and "commit
--verbose" #1946. We'll probably need an easy way to customize the diff part,
but I'm not sure if it can be as simple as a template alias function. User
might want to embed diffs without "JJ: " prefixes?

Perhaps, we can deprecate "ui.default-description", but it's not addressed in
this patch. It could be replaced with "default_description" template alias,
but we might want to configure default per command. Suppose we add a default
"backout_description" template, it would have to be rendered against the
source commit, not the newly-created backout commit.

The template key is named as "draft_commit_description" because it is the
template to generate an editor template. "templates.commit_description_template"
sounds a bit odd.

There's one minor behavior change: the default description is now terminated
by "\n".

Closes #1354
2024-07-25 22:39:00 +09:00
Yuya Nishihara
5a19eb6331 cli: merge description_template_for_*() functions 2024-07-25 22:39:00 +09:00
Yuya Nishihara
45d16f4b34 cli: commit, split: set default description to intermediate commit object
description_template_for_*() functions will be merged soon.

We don't need to set the default description to the second commit of the split
because its description should be kept empty if it was.
2024-07-25 22:39:00 +09:00
Yuya Nishihara
6395d32358 cli: commit, split: pass temporary commit object to description helper 2024-07-25 22:39:00 +09:00
Yuya Nishihara
b9cc61b535 cli: describe: set default description to temporary commit object
This could be handled by description_template_for_describe(), but I think it's
better to do mutation by caller. I also think commands like "backout" or "new"
can do a similar thing to generate a default commit description from the source
or merge parent commits.
2024-07-25 22:39:00 +09:00
Philip Metzger
fa7f4e68c5 run: Treat jj run -j0 <command> as use all available cores
Waleed noticed this in #4021.
2024-07-24 22:13:28 +02:00
Yuya Nishihara
7d50ebc23e cli: commit: set up rewritten commit early
For the same reason as the previous commit.
2024-07-25 00:09:39 +09:00
Yuya Nishihara
453e4f3fcc cli: split: set up rewritten commits early
For the same reason as the cmd_describe() change. A temporary commit object
will be constructed in order to render it as a description template.
2024-07-25 00:09:39 +09:00
Yuya Nishihara
0208e60358 cli: split: make local variable names shorter 2024-07-25 00:09:39 +09:00
Yuya Nishihara
4e234c1a18 cli: split: narrow scope of temporary variables of first/second commits 2024-07-25 00:09:39 +09:00
Yuya Nishihara
d637216c16 cli: describe: start transaction and set up rewritten commit early
This will help consolidate description_template_for_*() functions and port them
to templater. This change also means the committer (and operation start)
timestamp is set earlier. I think that's good.
2024-07-25 00:09:39 +09:00
Yuya Nishihara
69bb57d1d1 cli: describe: don't unwrap read error of stdin 2024-07-25 00:09:39 +09:00
Yuya Nishihara
d328adca7b tests: use insta::assert_snapshot!() to capture description templates 2024-07-25 00:09:39 +09:00
Martin von Zweigbergk
d740f1801b conflicts: use non-legacy MergedTreeId for root commit
This is part of migrating away from legacy trees (with path-level
conflicts). I can't think of any practical impact (we already compare
the tree ids equal).
2024-07-24 14:33:05 +02:00
Yuya Nishihara
bafb357209 git: on abandoning unreachable commits, don't count HEAD ref
This basically reverts 20eb9ecec1 "git: don't abandon HEAD commit when it
loses a branch." I think the new behavior is more consistent because the Git
HEAD is equivalent to @- in jj, so it shouldn't be considered a named ref.

Note that we've made old HEAD branch not considered at 92cfffd843 "git: on
external HEAD move, do not abandon old branch."

#4108
2024-07-24 21:22:26 +09:00
Yuya Nishihara
eb332b1d08 cli: make for_loaded_repo() callers specify whether repo/workspace are synced
It's wrong to deduce loaded_at_head from command-line arguments if the repo was
loaded at an arbitrary operation. Instead, the caller should specify whether
the working copy state is synchronized with the repo view.

I think .for_loaded_repo(ui, workspace, repo, true) would be bad for
readability, so I added separate functions. I'm not happy with the name
.for_temporary_repo(), but it seems okay for the current call sites.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
d7c1b97418 cli: fix "workspace add --at-op" to set up new working copy properly
Because new workspace is created for the new operation forked from the --at-op
operation, the new working copy should be writable.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
b76947c1d6 cli: error out on "init --at-op/--ignore-working-copy" or "clone --at-op"
--at-op should be invalid on repo initialization. "init --ignore-working-copy"
could be supported by using working_copy.reset(), but I don't think it's
worth the effort. If the working directory is empty, --ignore-working-copy
is meaningless, and if the directory is not empty, the user would probably
want to do snapshot at some point.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
c705afa299 cli: exit with CLI error status on "op abandon --at-op"
The command option --at-op isn't supported by "op abandon", so it's rather a
CLI error.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
b9e82f6e06 tests: run workspace-creation commands with --at-op or --ignore-working-copy
I'm going to fix misuse of CommandHelper::for_loaded_repo(), which expects
that the given repo respects the --at-operation option.

I don't think all of the added tests are useful, but "clone
--ignore-working-copy" might be legit as a replacement for bare repos.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
3f05d065b5 cli: uncapitalize op description of "workspace add" and custom command example
That's our convention.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
8fec7500c3 cli: enable fileset by default
I've tested it for months and found no problems.
2024-07-24 10:49:46 +09:00
Stephen Jennings
2a9fdbac52 git: add --allow-private option to push command 2024-07-23 08:45:51 -07:00
Stephen Jennings
03b6d380f5 git: add git.private-commits setting for preventing commits from being pushed
The user can define the setting `git.private-commits` as they desire. For
example:

    git.private-commits = 'description(glob:"wip:*")'

If any commits are in this revset, then the push is aborted.

If a commit would be private but already exists on the remote, then it does
not block pushes, nor do its descendents block pushes unless they are also
contained in `git.private-commits`.

Closes #3376
2024-07-23 08:45:51 -07:00
Benjamin Tan
dade156859 cli: add jj operation show command 2024-07-22 19:16:42 +08:00
Benjamin Tan
a6d82cc344 cli: add jj operation diff command 2024-07-22 19:16:42 +08:00
Yuya Nishihara
ddc601fbf9 str_util: add regex pattern
This patch adds minimal support for the regex pattern. We might have to add
"regex-i:" for completeness, but it can be achieved by "regex:'(?i)..'".
2024-07-22 12:00:52 +09:00
Scott Taylor
14d3bb85bc workspace: use cwd for printing relative path
The user probably would expect the path to be relative to their current
directory rather than the workspace root. For instance, if the user is
in a child directory and runs `jj workspace add ../../name`, then they
might be surprised if we printed "../name" instead of "../../name".
2024-07-21 14:26:18 -05:00
Yuya Nishihara
8df7857706 cli_util: add tx.commit_summary_template() and related helper functions
These functions mirror the ones in WorkspaceCommandHelper. I'm not sure if all
of them will have to be public, but parse_commit_template() might be useful in
order to implement description template.
2024-07-20 09:08:59 +09:00
Yuya Nishihara
b762dd55cd cli_util: cache IdPrefixContext by transaction wrapper
This addresses lifetime issue in the next patch, in which the context has to
be borrowed from a known location.
2024-07-20 09:08:59 +09:00
Scott Taylor
d5c526f496 branch: ignore git tracking branches for rename warning
Prevents a warning from being printed when renaming branches in a
colocated repo, since git tracking branches were being considered as
remote tracking branches.
2024-07-18 17:27:19 -05:00
Yuya Nishihara
5649ee4f45 fileset: parse glob characters as identifier
It's inconvenient that we have to quote glob patterns as 'glob:"*.rs"'. Suppose
filesets are usually specified in shell, it's better to allow unquoted strings
if possible. This change also means we'll probably abandon #2101 "make the
parsing of string arguments stricter."

Note that we can no longer introduce ? operator or [] subscript syntax in
filesets.

Closes #4053
2024-07-18 13:49:10 +09:00
Ilya Grigoriev
ff0188d63a cli branch create/set: add --to aliases for -r
Now that `jj move` does not accept `-r` (since it has `--from` and `--to`), `jj set --to` seems more useful
than `jj set -r`. `create --to` is also added for ease of switching
between `branch create` and `branch move`.
2024-07-17 21:21:40 -07:00
Yuya Nishihara
1a387489d9 files: relax requirement of merge() inputs
Most callers have Merge<ContentHunk> or Merge<Vec<u8>>.
2024-07-18 11:34:43 +09:00
Yuya Nishihara
a9af8d21f8 diff: move materialized_diff_stream() to jj_lib::conflicts module
New diff_contains() revset function will use this helper.
2024-07-18 01:01:16 +09:00
Martin von Zweigbergk
f2bfb90c8c cli: remove unused dependency on gix-filter
This dependency was added in 067d37aa but it seems it ended up being
used only from the jj-lib crate.
2024-07-17 11:53:51 +02:00
Yuya Nishihara
d1912bf016 templater: add commit.diff().<format>() methods
This patch adds TreeDiff template type to host formatting options. The main
reason of this API design is that diff formats have various incompatible
parameters, so a single .diff(files, format[, options..]) method would become
messy pretty quickly. Another reason is that we can probably add custom
summary templating support as diff.files().map(|file| file.path()..).

RepoPathUiConverter is passed to templater explicitly because the one stored
in RevsetParseContext is behind Option<_>.
2024-07-17 18:52:49 +09:00
Yuya Nishihara
4a63a1f660 diff: pass repo.store() to inner show_*_diff() functions, reorder arguments
This will help remove lifetimed &dyn Repo from diff object in templater.

Function arguments are reordered in a way that all show_*() functions have
common parameters in the same order.
2024-07-17 18:52:49 +09:00
Yuya Nishihara
18d60ad0d3 cli: use lossy string conversion to accept non-UTF-8 template outputs
I'm going to add diff() method which provides no guarantee about content
encoding.
2024-07-17 18:52:49 +09:00
Vincent Ging Ho Yim
79b326d56b cli_util: add missing word in conflict resolution instructions 2024-07-17 08:10:25 +02:00
Anton Älgmyr
c7eac90200 Enable the new graph nodes by default.
It's been tested in various places now, so this is probably mature
enough to be the default.
2024-07-16 12:54:24 +02:00
Yuya Nishihara
a757fddcf1 revset: parse file() argument as fileset expression
Since fileset and revset languages are syntactically close, we can reparse
revset expression as a fileset. This might sound a bit scary, but helps
eliminate nested quoting like file("~glob:'*.rs'"). One oddity exists in alias
substitution, though. Another possible problem is that we'll need to add fake
operator parsing rules if we introduce incompatibility in fileset, or want to
embed revset expressions in a fileset.

Since "file(x, y)" is equivalent to "file(x|y)", the former will be deprecated.
I'll probably add a mechanism to collect warnings during parsing.
2024-07-16 10:18:57 +09:00
Scott Taylor
91504cae02 obslog: reverse order of predecessors in topo traversal
Currently, when there is a commit with two predecessors, the graph
splits into two branches, and all of the predecessors on the first
branch are printed before all of the predecessors on the second branch.
This causes the graph to grow wider with each squashed commit, since the
second branch must always get indented one level farther each time a
commit is squashed. I have some commits where the graph is indented more
than 10 levels due to squashing more than 10 times, making it very
difficult to read.

Reversing the order and printing the second branch before the first
branch prevents this unnecessary indentation and makes the graph easier
to read. This does not change the order of the edges in the graph (i.e.
the first predecessor is still the first edge and the second predecessor
is still the second edge in the graph).
2024-07-15 20:10:31 -05:00
Scott Taylor
fcf1ca95f2 obslog: update test to show multiple squashes 2024-07-15 20:10:31 -05:00
Yuya Nishihara
ea3a574e36 cli: include untracked remote branches in default immutable_heads()
I used to use "remote_branches() & ~mine()" to exclude "their" branches from
the default log, and I don't think that's uncommon requirement. Suppose
untracked branches are usually read-only, it's probably okay to make them
immutable by default.
2024-07-15 23:41:07 +09:00
Yuya Nishihara
692c9960c0 diff: do not emit unified diff for binary files 2024-07-15 14:45:59 +09:00
Yuya Nishihara
e3055e5aaf diff: do not emit unified diff header on absent/empty transitions
---/+++ lines are part of unified diff hunks, not Git diff header.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
53f7acbc42 diff: refactor show_git_diff() to construct GitDiffPart for absent side
This will simplify binary content handling.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
7bdc4a9681 diff: clarify that mode flag of GitDiffPart is hard-coded
We can also change it to enum, but let's keep it str for now.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
07a6a8016c diff: fix typo in Git diff "index old..new" header
Spotted while consolidating "index" line generation. Git appears to use ".." to
separate hashes.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
0912c74ecf diff: add tests for mode changes and absent/empty transitions
This captures a bug of "diff --git" which emits unified diff header without
hunks.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
59daef2351 diff: accept diff inputs by generic iterator
This helps migrate internal [u8] variables to BStr.

b"" literals in tests are changed to &str to get around potential type
incompatibility between &[u8; N].
2024-07-14 23:26:29 +09:00
Scott Taylor
2dd75b5c53 revset: add tracked/untracked_remote_branches()
Adds support for revset functions `tracked_remote_branches()` and
`untracked_remote_branches()`. I think this would be especially useful
for configuring `immutable_heads()` because rewriting untracked remote
branches usually wouldn't be desirable (since it wouldn't update the
remote branch). It also makes it easy to hide branches that you don't
care about from the log, since you could hide untracked branches and
then only track branches that you care about.
2024-07-13 10:43:21 -05:00
Yuya Nishihara
8ee5b783b3 formatter: minor cleanup in --color=debug handling 2024-07-13 11:08:01 +09:00
Jonathan Tan
de2940f9b7 --color=debug: combine segments with same labels
This not only makes the output easier to read, but also protects against
implementation detail changes in `write!` when used with a format
string (especially, how many times and with what strings it calls the
underlying writer).
2024-07-11 10:39:05 -07:00
Jonathan Tan
579ba8031b --color=debug: print unlabeled text without markup
This makes the debug output cleaner and makes the subsequent commit
easier to write.
2024-07-11 10:39:05 -07:00
Emily
93d76e5d8f str_util: support case‐insensitive string patterns
Partially resolve a 1.5‐year‐old TODO comment.

Add opt‐in syntax for case‐insensitive matching, suffixing the
pattern kind with `-i`. Not every context supports case‐insensitive
patterns (e.g. Git branch fetch settings). It may make sense to make
this the default in at least some contexts (e.g. the commit signature
and description revsets), but it would require some thought to avoid
more confusing context‐sensitivity.

Make `mine()` match case‐insensitively unconditionally, since email
addresses are conventionally case‐insensitive and it doesn’t take
a pattern anyway.

This currently only handles ASCII case folding, due to the complexities
of case‐insensitive Unicode comparison and the `glob` crate’s lack
of support for it. This is unlikely to matter for email addresses,
which very rarely contain non‐ASCII characters, but is unfortunate
for names and descriptions. However, the current matching behaviour is
already seriously deficient for non‐ASCII text due to the lack of any
normalization, so this hopefully shouldn’t be a blocker to adding the
interface. An expository comment has been left in the code for anyone
who wants to try and address this (perhaps a future version of myself).
2024-07-10 05:58:34 +01:00
Scott Taylor
b27ff28956 cli: skip formatting instructions if not required
`tx.format_commit_summary()` can be expensive because it needs to build
an IdPrefixContext now, so it's best to avoid formatting instruction
messages unless they are actually required.
2024-07-09 20:24:14 -05:00
Yuya Nishihara
8856e6d328 diff: fix typo in get_diff_stat() comment 2024-07-10 10:05:31 +09:00
Yuya Nishihara
6a1d9262a0 diff: add short for Diff::for_tokenizer(_, find_line_ranges)
Line-by-line diff is common. Let's add a helper method for convenience.
2024-07-10 10:05:31 +09:00
Martin von Zweigbergk
fefe07b3c3 diff: consider uncommon words to match only if they have the same count
Patience diff starts by lining up unique elements (e.g. lines) to find
matching segments of the inputs. After that, it refines the
non-matching segments by repeating the process. Histogram expands on
that by not just considering unique elements but by continuing with
elements of count 2, then 3, etc.

Before this commit, when diffing "a b a b b" against "a b a b a b", we
would match the two "a"s in the first input against the first two "a"s
in the second input. After this patch, we ignore the "a"s because
their counts differ, so we try to align the "b"s instead.

I have had this commit lying around since I wrote the histogram diff
implementation in 1e657c5331. I vaguely remember thinking that the
way I had implemented it (without this commit) was a bit weird, but I
wasn't sure if this commit would be an improvement or not. The bug
report from @chooglen today of a case where we behave differently from
Git is enough to make me think that we make this change after all.

#761
2024-07-09 20:35:36 +09:00
Scott Taylor
a983abb594 cli_util: short-prefixes for commit summary in transaction
I've run into change ID prefixes being 4-5 characters instead of the
usual 1-2 characters in commands like `jj duplicate` and `jj split`
fairly often, and it seems like this should resolve that.
2024-07-08 08:23:39 -05:00
Scott Taylor
ddfce6d2c9 cli_util: extract new_id_prefix_context method 2024-07-08 08:23:39 -05:00
Vladimir Petrzhikovskii
802d2f5327 cli: recursively create clone destination path 2024-07-07 23:02:41 +02:00