Commit graph

65 commits

Author SHA1 Message Date
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
Martin von Zweigbergk
26a554818a git: update our record of Git branches on export
When we export branches to Git, we didn't update our own record of
Git's refs. This frequently led to spurious conflicts in these refs
(e.g. #463). This is typically what happened:

 1. Import a branch pointing to commit A from Git
 2. Modify the branch in jj to point to commit B
 3. Export the branch to Git
 4. Update the branch in Git to point to commit C
 5. Import refs from Git

In step 3, we forgot to update our record of the branch in the repo
view's `git_refs` field. That led to the import in step 5 to think
that the branch moved from A to C in Git, which conflicts with the
internal branch target of B.

This commit fixes the bug by updating the refs in the `MutableRepo`.

Closes #463.
2022-11-13 15:06:10 -08:00
Benjamin Saunders
b009019d8d cli: add git remote rename subcommand 2022-10-20 11:04:16 -07:00
Martin von Zweigbergk
6812bd9584 cleanup: rename checkout to wc_commit
`wc_commit` seems clearer than `checkout` and not too much longer. I
considered `working_copy` but it was less clear (could be the path to
the working copy, or an instance of `WorkingCopy`). I also considered
`working_copy_commit`, but that seems a bit too long.
2022-09-18 16:19:58 -07:00
Martin von Zweigbergk
b0912b3199 repo: add a function for getting workspaces by checkout 2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
8ae9540f2c cli: make move/squash/unsquash keep empty working-copy commit
If the source commit becomes empty as a result of
`move/squash/unsquash`, we abandon it. However, perhaps we shouldn't
do that if the source commit is a working-copy commit because
working-copy commits are often work-in-progress commits.

The background for this change is that @arxanas had just started a new
change and had set a description on it, and then decided to make some
changes in the working copy that should be in the parent
commit. Running `jj squash` then abandoned the working-copy commit,
resuling in the description getting lost.
2022-05-30 07:52:24 -07:00
Martin von Zweigbergk
39838a76bf view: move merging of views up to repo level (#111)
I want to make it so when we apply a repo-level change that removes a
head, we rebase descendants of that head onto the closes visible
ancestor, or onto its successor if the head has been rewritten (see
#111 for details). The view itself doesn't have enough information for
that; we need repo-level information (to figure out relationships
between commits).

The view doesn't have enough information to do the.
2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
f294df6e8e view: inline checkout() into remaining few callers 2022-02-05 15:43:37 -08:00
Martin von Zweigbergk
6d3e2017f8 view: merge checkouts for all workspaces, not just the default one (#13) 2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
766c01a6d9 view: add workspace_id argument to set_checkout() (#13) 2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
0098edd3d2 op_store: add support for tracking multiple workspaces (#13)
This patch teaches the `View` object to keep track of the checkout in
each workspace. It serializes that information into the `OpStore`. For
compatibility with existing repos, the existing field for a single
workspace's checkout is interpreted as being for the workspace called
"default".

This is just an early step towards support for multiple
workspaces. Remaining things to do:

 * Record the workspace ID somewhere in `.jj/` (maybe in
   `.jj/working_copy/`)

 * Update existing code to use the workspace ID instead of assuming
   it's always "default" as we do after this patch

 * Add a way of indicating in `.jj/` that the repo lives elsewhere and
   make it possible to load a repo from such workspaces

 * Add a command for creating additional workspaces

 * Show each workspace's checkout in log output
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
69ff505338 view: replace start_modification() by Clone impl
I'm pretty sure the `start_modification()` function is a leftover from
when there was `ReadonlyView` and `MutableView`.
2022-01-05 15:11:07 -08:00
Martin von Zweigbergk
8a2f630ac0 git: start tracking HEAD of underlying Git repo
This patch adds a place for tracking the current `HEAD` commit in the
underlying Git repo. It updates `git::import_refs()` to record it. We
don't use it anywhere yet.

This is part of #44.
2021-12-01 11:08:53 -08:00
Martin von Zweigbergk
0c441d9558 cli: don't commit no-op transaction
If nothing changed in a transaction, it's rarely useful to commit it,
so let's avoid that. For example, if you run `jj git import` without
changing the anything in the Git repo, we now just print "Nothing
changed.".
2021-12-01 09:51:20 -08:00
Martin von Zweigbergk
ce5e95fa80 store: rename Store to Backend and StoreWrapper to Store
For what's currently called `Store` in the code, I have been using
"backend" in plain text. That probably means that `Backend` is a good
name for it.
2021-09-12 12:02:10 -07:00
Martin von Zweigbergk
7dc82c1580 cli: make jj git push push given branch
Now that we have native branches, we can make `jj git push` only be
about pushing a branch to a remote branch with the same name.

We may want to add back support for the more advanced case of pushing
an arbitrary commit to an arbitrary branch later, but let's get the
common case simplified first.
2021-08-04 22:14:43 -07:00
Martin von Zweigbergk
044f23bc33 view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.

For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).

This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.

I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-08-04 11:33:57 -07:00
Martin von Zweigbergk
9fb3521bf5 view: rename insert_git_ref() to set_git_ref()
I just feel like `set_git_ref()` is a more natural name (I was looking
for it the other day before I realized I had called it
`insert_git_ref()`).
2021-08-04 08:45:37 -07:00
Martin von Zweigbergk
6b1ccd4512 view: add support for merging git ref targets
When there are two concurrent operations, we would resolve conflicting
updates of git refs quite arbitrarily before this change. This change
introduces a new `refs` module with a function for doing a 3-way merge
of ref targets. For example, if both sides moved a ref forward but by
different amounts, we pick the descendant-most target. If we can't
resolve it, we leave it as a conflict. That's fine to do for git refs
because they can be resolved by simply running `jj git refresh` to
import refs again (the underlying git repo is the source of truth).

As with the previous change, I'm doing this now because mostly because
it is a good stepping stone towards branch support (issue #21). We'll
soon use the same 3-way merging for updating the local branch
definition (once we add that) when a branch changes in the git repo or
on a remote.
2021-07-24 19:01:56 -07:00
Martin von Zweigbergk
0aa738a518 view: add support for conflicting git refs in the model
This adds support for having conflicting git refs in the view, but we
never create conflicts yet. The `git_refs()` revset includes all "add"
sides of any conflicts. Similarly `origin/main` (for example) resolves
to all "adds" if it's conflicted (meaning that `jj co origin/main` and
many other commands will error out if `origin/main` is
conflicted). The `git_refs` template renders the reference for all
"adds" and adds a "?" as suffix for conflicted refs.

The reason I'm adding this now is not because it's high priority on
its own (it's likely extremely uncommon to run two concurrent `jj git
refresh` and *also* update refs in the underlying git repo at the same
time) but because it's a building block for the branch support I've
planned (issue #21).
2021-07-24 19:01:56 -07:00
Martin von Zweigbergk
4c416dd864 cleanup: let Clippy fix a bunch of warnings 2021-06-14 00:27:31 -07:00
Martin von Zweigbergk
61ffa66fb5 view: move merge_views() onto View 2021-06-05 14:08:04 -07:00
Martin von Zweigbergk
ac2530637a view: merge ReadonlyView and MutableView into a single View
The two types have become very similar so it doesn't seem that there's
any point in having two types. We should probably do the same with
`ReadonlyEvolution` and `MutableEvolution`.
2021-06-05 14:08:04 -07:00
Martin von Zweigbergk
70b99c960e transaction: make commit() return resulting ReadonlyRepo
I've wanted the API to look like this for a while. It seems like a
good API to me. It means that the caller won't have to reload the repo
after committing. The cost seems relatively small. It involves copying
potentially a lot of data in memory (at least the View object), but it
shouldn't involve reading from disk or any other processing. To reduce
the amount of data to copy, it may be worth switching to persistent
data types. I've also wanted to do that for the copying we do when
start a transaction.

I couldn't measure any slowdown caused by this change.
2021-05-08 13:50:59 -07:00
Martin von Zweigbergk
1ebdd4ecf0 MutableRepo: use index when enforcing view invariants
We can now finally use the commit index for filtering out ancestors
from the sets of heads.

I haven't timed the change from most of the recent work on
performance, but I did a measurement after this commit. I modified a
commit in the git.git repo's "what's cooking" branch (because that's
linear). Then I ran `jj evolve` so the 100 commits after it would get
evolved. That took ~700ms. `git rebase` of the same 100 commits took
~6s.

I also compared `jj op undo` of that `jj evolve` operation. With this
patch, that was sped up from ~6.8s to ~125ms.
2021-03-15 16:35:45 -07:00
Martin von Zweigbergk
2c92fca75a MutableView: don't require whole Commit when CommitId is enough 2021-03-15 15:36:03 -07:00
Martin von Zweigbergk
b4b1de3ddc view: let MutableRepo enforce view invariants
`MutableRepo` has more information needed for taking fast-paths, and
it will have to make the same decision for doing incremental updates
of the evolution state anyway.
2021-03-15 15:17:36 -07:00
Martin von Zweigbergk
b9fe944e76 view: remove unnecessary removing of parents in add_head()
We call `enforce_invariants()` right after removing the parent
commits, and that will remove parents anyway.
2021-03-15 15:06:14 -07:00
Martin von Zweigbergk
5631e85502 view: don't enforce invariants in merge_views()
We now only call the function from `MutableRepo::merge()`. There we
pass the result to `MutableView::set_view()`, which already enforces
the invariants.
2021-03-14 11:07:34 -07:00
Martin von Zweigbergk
8048d9641e commands: rewrite jj op undo using new MutableRepo::merge() 2021-03-14 10:57:57 -07:00
Martin von Zweigbergk
4b8484e561 rustfmt: configure to group imports 2021-03-14 10:46:25 -07:00
Martin von Zweigbergk
ac9fb1832d OpHeadsStore: move logic for merging repos to MutableRepo
This adds `MutableRepo::merge()`, which applies the difference between
two `ReadonRepo`s to itself. That results in much simpler code than
the current code in `merge_op_heads()`. It also lets us write `undo`
using the new function. Finally -- and this is the actual reason I did
it now -- it prepares for using the index when enforcing view
invariants.
2021-03-14 10:43:39 -07:00
Martin von Zweigbergk
7ea0c6a868 View: move op_id/base_op_id to Repo
This is yet another step towards making the `View` types
simpler. Perhaps we eventually won't need to wrap the types returned
from the `OpStore` at all.
2021-03-14 00:25:02 -08:00
Martin von Zweigbergk
c1de8b0f3a View: move creation of Operation to Transaction
This continues the work to make the `View` types be only about the
state of the current view and not about operations in general (which
has been moved out `OpStore` and qOpHeadsStore`).
2021-03-14 00:16:21 -08:00
Martin von Zweigbergk
f79874d612 view: let repo get current operation from OpHeadsStore and pass in
This makes the View types a lot simpler.
2021-03-11 22:23:02 -08:00
Martin von Zweigbergk
82a3ff6ef8 repo: make OpHeadsStore accessible directly on ReadonlyRepo
We can now get rid of `MutableView::update_op_heads()`.
2021-03-10 23:27:36 -08:00
Martin von Zweigbergk
212dd35d01 view: let repo create OpHeadsStore and pass in to view 2021-03-10 23:14:00 -08:00
Martin von Zweigbergk
ec07104126 view: move creation of initial operation to OpHeadsStore
This is a step towards getting rid of
`MutableView::update_op_heads()`.
2021-03-10 22:57:59 -08:00
Martin von Zweigbergk
2590e127f7 view: move get_single_op_head() onto OpHeadsStore 2021-03-10 21:59:32 -08:00
Martin von Zweigbergk
b4d4cd143a view: move locking of .jj/view/op_heads/ to OpHeadsStore 2021-03-10 21:51:08 -08:00
Martin von Zweigbergk
4bd121dab5 view: split out separate type for keeping track of op heads 2021-03-10 21:34:11 -08:00
Martin von Zweigbergk
2955bc4a29 repo: let repo types directly have an OpStore
I'd like to make `ReadonlyView` and `MutableView` focused on just the
state of the view (i.e. the set of heads, git refs, etc.). The
responsibility for managing the `.jj/view/op_heads/` directory should
be moved out of it. This prepares for that.
2021-03-10 20:55:56 -08:00
Martin von Zweigbergk
48d7903925 repo: simplify and clarify name of base_op_head_id() functions 2021-03-10 15:39:15 -08:00
Martin von Zweigbergk
9ee521d9d3 transaction: fix (mostly harmless) race where index can get re-calculated 2021-03-10 15:22:03 -08:00
Martin von Zweigbergk
47a7cf7101 view: extract function for updating operation heads
This will be used to address the race in `Transaction::commit()`.
2021-03-10 15:17:54 -08:00
Martin von Zweigbergk
fc73ef8d6e view: delete an incorrect comment about a race
Unlike in `Transaction::commit()`, in the `view` module, we actually
don't update the `.jj/view/op_heads/` directory until after we've
recorded the index associated with the operation, so there's no race
there.
2021-03-10 14:30:27 -08:00
Martin von Zweigbergk
a715fd0ae7 view: drop stale comment about resolving concurrent operations
The comment was from the time when we resolved divergent operations at
write time.
2021-03-08 23:18:26 -08:00
Martin von Zweigbergk
e6aa2402a6 view: drop redundant filtering of ancestors of public heads
I added `enforce_invariants()` in 1f593a4193 and then forgot to use
it in 4db3d8d3a6.
2021-03-08 23:18:26 -08:00
Martin von Zweigbergk
f755c3f740 cleanup: access integer types' MAX constants directly on the type
Using `std::u32::MAX` is deprecated.
2021-03-08 23:18:17 -08:00
Martin von Zweigbergk
1e623bd019 index: update in memory and on disk while resolving operation conflicts
Updating the index on disk means that reader won't have to calculate
the state. Updating it in memory means that we can take advantage of
it while resolving conflicts. We will do that soon.
2021-03-06 23:30:03 -08:00