Commit graph

525 commits

Author SHA1 Message Date
Essien Ita Essien
08d1809dc1 Issue warning if renaming branch with a remote tracking branch. 2024-01-07 18:04:38 +00:00
Martin von Zweigbergk
0046af8d4c cli: allow non-static version strings from custom binaries
We would like to use a non-static version string at Google. We have a
workaround using Lazy, but it seems unfortunate to have to do
that. Using dynamic strings requires Clap's `string` feature, which
increases the binary size by 140 kiB (0.6%).
2024-01-06 16:24:55 -08:00
Yuya Nishihara
95d83cbfe5 object_id: make ObjectId constructors non-trait methods
I'm going to add try_from_hex(), which requires Self: Sized. Such trait bound
could be added, but I don't think we'll need abstracted ObjectId constructors
at all.
2024-01-05 23:36:57 +09:00
Yuya Nishihara
31b236a70d object_id: move HexPrefix and PrefixResolution from index module 2024-01-05 10:20:57 +09:00
Yuya Nishihara
fa5e40719c object_id: extract ObjectId trait and macros to separate module
I'm going to add a prefix resolution method to OpStore, but OpStore is
unrelated to the index. I think ObjectId, HexPrefix, and PrefixResolution can
be extracted to this module.
2024-01-05 10:20:57 +09:00
Yuya Nishihara
f169c99fb4 cli: add "op abandon root..head" command that "reparents" operations
In order to implement GC (#12), we'll need to somehow prune old operations.
Perhaps the easiest implementation is to just remove unwanted operation files
and put tombstone file instead (like git shallow.) However, the removed
operations might be referenced by another jj process running in parallel. Since
the parallel operation thinks all the historical head commits are reachable, the
removed operations would have to be resurrected (or fix up index data, etc.)
when the op heads get merged.

The idea behind this patch is to split the "op log" GC into two steps:
 1. recreate operations to be retained and make the old history unreachable,
 2. delete unreachable operations if the head was created e.g. 3 days ago.
The latter will be run by "jj util gc". I don't think GC can be implemented
100% safe against lock-less append-only storage, and we'll probably need some
timestamp-based mechanism to not remove objects that might be referenced by
uncommitted operation.

FWIW, another nice thing about this implementation is that the index is
automatically invalidated as the op id changes. The bad thing is that the
"undo" description would contain an old op id. It seems the performance is
pretty okay.
2024-01-04 11:44:36 +09:00
Matt Stark
3f0a49dafe Ensure you never drop the working commit with --skip-empty
See #2766 for discussions
2024-01-04 13:33:24 +11:00
Yuya Nishihara
c53748d732 op_walk: allow walk_ancestors() from more than one head operations 2024-01-02 10:30:08 +09:00
Yuya Nishihara
51691ea22c tests: add lib tests for op id resolution, migrate some from cli
CLI testing is slow and harder to set up crafted environment.
2024-01-02 10:30:08 +09:00
Yuya Nishihara
c9b581589c op_walk: simplify arguments passed to high-level "opset" query functions 2024-01-01 10:22:23 +09:00
Yuya Nishihara
26b5f38f45 op_walk: move "opset" query functions from jj_cli 2024-01-01 10:22:23 +09:00
Yuya Nishihara
e4460d5386 op_walk: add error types for fake "opset" expression
This removes CommandError dependency from these resolution functions. We might
want to refactor the error types again if we introduce a real "opset" evaluator.

The error message for unresolved op heads now includes "@" instead of the whole
expression.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
94fc32ab47 op_walk: extract walk_ancestors() to new module
I'm going to extract fake "opset" resolution functions there, and I think
walk_ancestors() belongs to the same category.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
6dd936f72f op_heads: let caller decide resolve_op_heads() error type
The resolver callback usually returns wider error type, which I don't think
is a variant of OpHeadResolutionError.

To help type inference, resolver's error type is E, not E1 where E: From<E1>.
2024-01-01 10:22:23 +09:00
Martin von Zweigbergk
0d02724341 cli: read files concurrently when diffing
Same reasoning as in the previous patch - this should help
high-latency backends.
2023-12-29 13:37:13 -08:00
Yuya Nishihara
60c5e86fe1 cli: add missing copyright header to cli/src/commands/*.rs 2023-12-29 22:06:50 +09:00
Yuya Nishihara
43e016a7d1 index: add explicit reindexing method that can propagate error 2023-12-29 13:05:58 +09:00
Yuya Nishihara
3abe6be384 index: propagate DefaultIndexStore::init/reinit() errors 2023-12-29 13:05:58 +09:00
Yuya Nishihara
bb73cd491f clenaup: don't use debug format to embed ObjectId in error message
Also fixed typo, s/a/an/.
2023-12-29 13:05:58 +09:00
Waleed Khan
88cc4daad3 merge_tools: upgrade to scm-record v0.2.0
To get the fix at https://github.com/arxanas/git-branchless/pull/1013 "fix(record): don't add new files with no selected contents".
2023-12-26 19:25:02 -08:00
Yuya Nishihara
dde42b9c05 index: rename resolve_prefix() to resolve_commit_id_prefix()
I'll probably add change id lookup methods to CompositeIndex. The Index trait
won't gain resolve_change_id_prefix(), but I also renamed its resolve_prefix()
for consistency.
2023-12-26 01:03:10 +09:00
Ilya Grigoriev
1fb9df252b split.rs: stop using DescendantRebaser::new
This requires creating a new public API as a substitute. I took the opportunity
to also add some comments to the
`MutRepo::record_rewritten_commit`/`record_abandoned_commit` functions.

I imade the simplest possible addition to the API; it is not a very elegant
one. Eventually, the entire `record_rewritten_commit` API should probably be
refactored again.

I also added some comments explaining what these functions do.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
c7c8960bcc test_split_command: check that new commits inherit author dates
At some point, I tried `new_commit` instead of `rewrite_commit` in the split
command. That seemed to work, but messed up the dates in a subtle way.

This commit should prevents repeats of this mistake and emphasize the
importance of the author dates being preserved.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
6bfd09009f move.rs: remove use of MutRepo::create_descenant_rebaser.
After this, the internal function is only used in tests.
2023-12-24 19:25:16 -08:00
Yuya Nishihara
6b862c6f23 cli: don't panic on empty alias substitution
This partially reverts 6c627fb30d "cli: default to log when no subcommand is
provided." We could reject an empty alias at all, but we would still need to
ensure that the expanded alias contained a subcommand name.

The help output is a bit odd as the <COMMAND> can be omitted, but I think
that's acceptable. If we do care about that, maybe we can override_usage().
2023-12-24 23:31:28 +09:00
Yuya Nishihara
55b4f69fb6 repo: propagate store error from add_heads() 2023-12-24 00:22:30 +09:00
Yuya Nishihara
1836a105bb cli: warn if -R/--repository could be involved in command alias expansion
#2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
30b5e88b04 cli: use cwd-relative workspace config to resolve default command and aliases
This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes #2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
941e53802f cli: error out early if -R path is invalid
It should be better to handle invalid -R path globally. The error message is
a bit worse, but I think it's still okay.

This helps to load temporary config from the cwd-relative path. If the command
processing continued with an invalid -R path, the temporary config would have
to be explicitly discarded.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
c82b2c78fd cli: inline init_workspace_loader()
In order to load command aliases from .jj/repo/config.toml, WorkspaceLoader
will be changed to be instantiated earlier with the cwd path.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
5bf9e4192a cli: don't look for added/removed conflicts across old/new heads
removed_heads..added_heads won't stop if new head is added on top of non-head
commit for example.

#2729
2023-12-21 23:40:52 +09:00
Gabriel Scherer
fad511a6e5 document the use of JJ_USER and JJ_EMAIL in combination with --reset-author
Suggested-by: David Barnett <dbarnett@google.com>
2023-12-21 00:20:45 +01:00
Ilya Grigoriev
c5f76d6b4d cli untrack --help: mention that files need to be already be ignored
Make it clearer what the command does, make the error message when the file is
not ignored less of a surprise.

Also, I think it's nice to mention `.git/info/exclude`, since the path is
not trivial to remember.
2023-12-17 22:16:22 -08:00
Yuya Nishihara
87a8238bee git: turn git.auto-local-branch off by default
As far as I can see in the chat, there's no objection to changing the default,
and git.auto-local-branch = false is generally preferred.

docs/branches.md isn't updated as it would otherwise conflict with #2625. I
think the "Remotes" section will need a non-trivial rewrite.

#1136, #1862
2023-12-17 08:30:24 +09:00
Yuya Nishihara
6971ec239a tests: set git_settings.auto_local_branch where it matters 2023-12-17 08:30:24 +09:00
Essien Ita Essien
35b8dad890 Implement a rename subcommand for the branch command.
This is really a simple change that does the following in a transaction:
* Set the new branch name to point to the same commit as the old branch name.
* Set the old branch name to point to no commit (hence deleting the old name).

Before it starts, it confirms that the new branch name is not already in use.
2023-12-16 18:44:46 +00:00
Yuya Nishihara
5a466cab4c cli: ensure default remote branch is imported by "git clone"
I originally thought this would be unavoidable, but I was wrong. "jj git clone"
doesn't implicitly create any local branch if git.auto-local-branch is off, and
that's fine because the detached HEAD state is normal in jj.

That being said, Git users would expect that the main/master branch exists.
Since importing the default branch is harmless, let's create and track it no
matter if git.auto-local-branch is off.
2023-12-16 16:02:10 +09:00
Yuya Nishihara
0cb6a2f178 tests: deduplicate source repo setup in test_git_clone.rs 2023-12-16 16:02:10 +09:00
Yuya Nishihara
15c3014284 cli: colorize inline "jj branch" command hints
This is a bit different from the ordinary ui hints, but I feel the colored
output is easier to follow.
2023-12-16 07:50:15 +09:00
Yuya Nishihara
40d18bb2c9 cli: remove weird line break from the "jj branch forget" hint
The message seems a bit too long, but it doesn't make sense to insert \n
in the middle of sentence.
2023-12-16 07:50:15 +09:00
Yuya Nishihara
72d9cd019b index: extract as_composite() to trait method
The revset engine will accept abstract AsCompositeIndex type, and the
evaluated revset can be 'static if the index is behind Arc<T>.
2023-12-15 16:10:28 +09:00
Yuya Nishihara
d420002ea2 cargo: bump git2 to 0.18.1 2023-12-15 14:17:02 +09:00
Martin von Zweigbergk
90e241cc95 cli: simplify definition of workspaces in cmd_workspace_forget() 2023-12-13 08:12:49 -08:00
Martin von Zweigbergk
24b1421918 cli: move a few transaction description variables later
Now that we don't need the transaction until later, let's move the
variables closer to where they're used.
2023-12-13 08:12:49 -08:00
Martin von Zweigbergk
60fae3114e transaction: take description at end instead of start
It seems better to have the caller pass the transaction description
when we finish the transaction than when we start it. That way we have
all the information we want to include more readily available.
2023-12-13 08:12:49 -08:00
Ilya Grigoriev
872a94d1c5 cli branch track, branch untrack: document remote branches in jj help
This tries to clarify the fact that the branches must be remote and the syntax
for specifying them as globs.

Cc @yuja, https://github.com/martinvonz/jj/pull/2625#discussion_r1423379351

Here is the result (excerpt):

```
$ jj branch track --help
Start tracking given remote branches

A tracking remote branch will be imported as a local branch of the same name. Changes to it
will propagate to the existing local branch on future pulls.

Usage: jj branch track [OPTIONS] <BRANCH@REMOTE>...

Arguments:
  <BRANCH@REMOTE>...
          Remote branches to track

          By default, the specified name matches exactly. Use `glob:` prefix to select
          branches by wildcard pattern. For details, see
          https://github.com/martinvonz/jj/blob/main/docs/revsets.md#string-patterns.

          Examples: branch@remote, glob:main@*, glob:jjfan-*@upstream
```
2023-12-12 13:11:21 -08:00
Yuya Nishihara
cdcd465c79 index: move default_index_store.rs to sub directory named default_index
default_index_store.rs is relatively big, and it contains types and impls in
arbitrary order. Let's split them into sub modules. After everything moved,
mod.rs will only contain tests.
2023-12-12 08:07:52 +09:00
Martin von Zweigbergk
a88b3dd2f5 cli: print a hint about how to resolve conflicts
This prints a hint about using `jj new <first conflicted commit>` and
`jj squash` to resolve conflicts. The hint is printed whenever there
are new or resolved conflicts.

I hope this hint will be useful especially for new users so they know
which commit to resolve conflicts in first. It may not be obvious that
they should start with the bottommost one. I hope the hint will also
be useful for more more experienced user by letting them just copy the
printed command without first running `jj log` to find the right
commit..
2023-12-10 12:44:57 -08:00
Martin von Zweigbergk
2dae5f58dd cli: print a message about new and resolved conflicts
When e.g. `jj rebase` results in new conflicts, it's useful for the
user to learn about that without having to run `jj log` right
after. This patch adds reporting of new conflicts created by an
operation. It also add reporting of conflicts that were resolved or
abandoned by the operation.

There was no measurable performance impact when rebasing a single
commit in the Linux kernel repo.
2023-12-10 12:44:57 -08:00
Yuya Nishihara
a110ec6d95 cli: print failed git export reason for each ref
Not all reasons are actionable, but we print hint in common cryptic cases.
2023-12-09 23:37:00 +09:00