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

829 commits

Author SHA1 Message Date
Martin von Zweigbergk
bedf96475d cleanup: format commands.rs, missed in previous commit 2022-01-27 20:46:33 -08:00
Martin von Zweigbergk
d588a309da cli: prevent rebasing to a descendant
We allow rebasing to a descendant, but that causes divergence because
the old commit remains visible. You could imagine making it work so
`jj rebase -r B -d D` on a linear chain "A-B-C-D" reorders it to
"A-C-D-B", but we don't do that yet, so let's just prevent the
divergence for now.
2022-01-27 16:17:13 -08:00
Martin von Zweigbergk
ed265afc68 cli: prepare rebase code for checking that destination is not descendant 2022-01-27 16:14:36 -08:00
Martin von Zweigbergk
10ebf35c27 repo: add a convenience function for rebasing all descendants
All non-test users of `create_descendant_rebaser()` just want to
rebase all commits, so let's make that easy.
2022-01-27 08:28:44 -08:00
Martin von Zweigbergk
9f8c6fe07d clippy: return_self_not_must_use is now disabled (pedantic) by default 2022-01-26 22:13:09 -08:00
Martin von Zweigbergk
f0240213cc cli: update the working copy if we detect that it's stale (#13)
Now that we have the operation ID recorded in the working copy state,
we can tell if the working copy is stale. When it is, we update it to
the repo view's checkout.
2022-01-19 22:26:16 -08:00
Martin von Zweigbergk
38180555de working_copy: keep track of operation ID (#13)
When there are concurrent operations that want to update the working
copy, it's useful to know which operation was the last to successfully
update the working copy. That can help use decide how to resolve a
mismatch between the repo view's record and the working copy's
record. If we detect such a difference, we can look at the working
copy's operation ID to see if it was updated by an operation before or
after we loaded the repo.

If the working copy's record says that it was updated at operation A
and we have loaded the repo at operation B (after A), we know that the
working copy is stale, so we can automatically update it (or tell the
user to run some command to update it if we think that's more
user-friendly).

Conversely, if we have loaded the repo at operation A and the working
copy's record says that it was updated at operation B, we know that
there was some concurrent operation that updated it. We can then
decide to print a warning telling the user that we skipped updating
because of the conflict. We already have logic for not updating the
working copy if the repo is loaded at an earlier operation, but maybe
we can drop that if we record the operation in the working copy (as
this patch does).
2022-01-19 19:15:29 -08:00
Martin von Zweigbergk
a2acb5fcb8 cli: while importing git HEAD, keep working copy locked
When importing git HEAD in a working copy shared with git, we reset
the working copy to the new commit at the end. If we fail to reset the
working copy, we shouldn't commit the operation. This patch mostly
fixes that by locking the working copy while we commit the
operation. There's still a small risk that the operation commits and
we fail to write the working copy state, but there's not much we can
do about that (or it's not worth the effort anyway).
2022-01-19 19:15:29 -08:00
Martin von Zweigbergk
419efb88f9 working_copy: update stale comment on LockedWorkingCopy
The recent refactoring introducing `WorkgingCopy::start_mutation()`
(25d19e8a65) made this comment incorrect.
2022-01-19 15:12:45 -08:00
Martin von Zweigbergk
cb5dd387ed cli: clarify a comment and some variable names 2022-01-19 15:12:23 -08:00
Martin von Zweigbergk
dd81e4a3a1 cli: create tree object from working copy right before using it
This is just to make the code more readable.
2022-01-19 13:32:09 -08:00
Martin von Zweigbergk
45a00e819d working_copy: pass only a TreeId to LockedWorkingCopy::check_out()
It only needs a `TreeId`.
2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
fabaf8b608 working_copy: move logic of check_out() onto LockedWorkingCopy
Having the checkout functionality in `LockedWorkingCopy` makes it a
little more flexible (one could imagine using it for udating working
copy files and then discarding the state changes, for example). It
also lets us reuse a few lines of code for locking. I left
`WorkingCopy::check_out()` for convenience because that's what all
current users want.
2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
9e1869dcef working_copy: pass in old commit ID to check_out()
`WorkingCopy::check_out()` currently fails if the commit recorded on
disk has changed since it was last read. It fails with a "concurrent
checkout" error. That usually works well in practice, but one can
imagine cases where it's not correct. For an example where the current
behavior is wrong, consider this sequence of events:

 1. Process A loads the repo and working copy.

 2. Process B loads the repo at operation A. It has not loaded the
    working copy yet.

 3. Process A writes an operation and updates the working copy.

 4. Process B loads the working copy and sees that it is checked out
    to the commit process B set it to. We don't currently have any
    checks that the working copy commit matches the view's checkout
    (though I plan to add that).

 5. Process B finishes its operation (which is now divergent with the
    operation written by process A). It updates the working copy to
    the checkout set in the repo view by process B. There's no data
    loss here, but the behavior is surprising because we would usually
    tell the user that we detected a concurrent update to the working
    copy.

We should instead check that the working copy's commit on disk matches
what the previous repo view said, i.e. the view at the start of the
operation we just committed. This patch does that by having the caller
pass in the expected old commit ID.
2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
7103860f7e cli: when untracking paths, release lock after finishing transaction 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
8c97fdf5d6 working_copy: remove untrack() now that we have more flexible reset() 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
4b91ad408c cli: use reset() in jj untrack 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
c52b001d9c cli: when importing Git HEAD in shared working copy, use reset() 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
cd4fbd3565 working_copy: add a reset() function for Git-like reset
We already have two usecases that can be modeled as updating the
`TreeState` without touching the working copy:

 1. `jj untrack` can be implemented as removing paths from the tree
    object and then doing a reset of the working copy state.

 2. Importing Git HEAD when sharing the working copy with a Git repo.

This patch adds that functionality to `TreeState`.
2022-01-19 08:32:59 -08:00
Martin von Zweigbergk
9a640bfe13 working_copy: save TreeState later, just before releasing lock
I was surprised that we save the `TreeState` before
`LockedWorkingCopy::finish()`. That means that even if the caller
instead decides to discard the changes, some changes will already have
been written.
2022-01-19 08:32:59 -08:00
Martin von Zweigbergk
25d19e8a65 working_copy: start improving interface for mutations
This patch changes the interface for making changes to the working
copy by replacing `write_tree()` and `untrack()` by a single
`start_mutation()` method. The two functions now live on the returned
`LockedWorkingCopy` object instead. That is more flexible because the
caller can make multiple changes while the working copy is locked. It
also helps us reduce the risk of buggy callers that read the commit ID
before taking the lock, because we can now make it accessible only on
`LockedWorkingCopy`.
2022-01-19 08:32:59 -08:00
Martin von Zweigbergk
2916dc3423 working_copy: make a &mut self argument not mutable 2022-01-19 08:32:51 -08:00
Martin von Zweigbergk
1fc19dbbaf working_copy: take initial commit in init() function
The working copy object knows the currently checked out commit ID. It
is set to `None` when the object is initialized. It is also set to
`None` when an existing working copy is loaded. In that case, it's
used only to facilitate lazy loading. However, that means that
`WorkingCopy::current_commit_id()` fails if the working copy has been
initalized but no checkout has been specified. I've never run into
that case, but it's ugly that it can happen. This patch fixes it by
having `WorkingCopy::init()` take a `CommitId`.
2022-01-17 14:12:55 -08:00
Martin von Zweigbergk
6fcd3b3af6 cli: avoid an unnecessary read of the working copy commit 2022-01-16 17:37:24 -08:00
Martin von Zweigbergk
9ce56f6cb7 cli: use color only when stdout is a TTY
This adds a `ui.color` config that can be set to "always", "never", or
"auto". If set to "auto", we use color iff stdout is a TTY.
2022-01-16 17:37:14 -08:00
Martin von Zweigbergk
0fadac38d6 working_copy: remove current_commit() (leaving current_commit_id()
`WorkingCopy::current_commit()` has been there from the beginning. It
has made less sense since we made the repo view keep track of the
current checkout. Let's remove it.
2022-01-15 17:11:56 -08:00
Martin von Zweigbergk
91c8c27cc5 cli: when untracking paths, get old commit id while under lock
Before this patch, we got the old commit ID before we took the lock on
the working copy, which means we might unnecessarily create divergence
if another process just committed the working copy.
2022-01-15 11:15:01 -08:00
Martin von Zweigbergk
ed9c23281b cli: make jj untrack not create divergent commit
We need to call `workspace_command.finish_transaction()` to rebase
descendants and hide the old heads.
2022-01-15 11:09:41 -08:00
Martin von Zweigbergk
4e20548e32 docs: some futher touch-ups of concurrency.md 2022-01-12 23:20:22 -08:00
Martin von Zweigbergk
8a0afc3016 gitignore: don't apply patterns to parent directories
If you create a `dir/.gitignore` file with pattern "dir" in it, it'll
currently match the parent directory, making e.g. the `dir/.gitignore`
file itself ignored. That was quite confusing, and it doesn't match
how Git behaves. This patch fixes the bug.
2022-01-12 11:27:49 -08:00
Martin von Zweigbergk
5b84e192fc gitignore: ignore a single CR at EOL
I ran into a tool that produced a `.gitignore` file with CRLF line
endings. I had not considered that case when implementing support for
`.gitignore`, so we interpreted the CR as part of the string, which of
course made the files not match.

This patch fixes the bug by ignoring a single CR at EOL. That seems to
be what Git does (I didn't see any information about it in the
documentation).
2022-01-12 10:58:09 -08:00
Martin von Zweigbergk
1e07b95e7b gitignore: derive Debug on structs 2022-01-12 09:37:36 -08:00
Martin von Zweigbergk
c47bb9373c cli: remove unnecessary override of --help description on subcommands
It turns out that the `--help` option is "global", so the description
we set on the top-level command already applies to subcommands (and
subsubcommands, etc.).
2022-01-12 09:23:19 -08:00
Martin von Zweigbergk
67b731b34a docs: mention concurrency as a feature in README 2022-01-10 13:05:29 -08:00
Martin von Zweigbergk
4c45844aba docs: fix a typo in concurrency doc 2022-01-10 07:58:27 -08:00
Martin von Zweigbergk
94fda7935a docs: add technical doc about lock-free concurrency design 2022-01-09 22:03:19 -08:00
Martin von Zweigbergk
2d6b66a274 stacked_table: rename start_modification() to start_mutation()
`start_mutation()` better matches the return type's name.
2022-01-05 15:17:24 -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
504148a81f cli: upgrade to clap 3.0 now that it's released 2022-01-05 12:43:14 -08:00
Martin von Zweigbergk
9ec0e4c1bb docs: use Git-style unified diff in the tutorial
The default (color-based) diffs are not readable in Markdown. Also,
it's useful for the user to learn about the `--git` flag.
2022-01-05 12:38:52 -08:00
Martin von Zweigbergk
037d66965d docs: start documenting Git compatibility 2022-01-03 22:40:58 -08:00
Martin von Zweigbergk
93250fe6c8 docs: link from README to post about rebase speed
For now, the best documentation we have of how fast `jj` is is the
GitHub discussion about rebase speed.
2022-01-03 21:36:56 -08:00
Martin von Zweigbergk
91e471cb73 clippy: disable return_self_not_must_use
A new Clippy version added a new warning when a function that returns
`Self` doesn't have `#[must_use]`. I feel like all the cases reported
by it were false positives. Most were functions on `CommitBuilder`,
where we take `mut self` and return `Self`. I don't think I've ever
forgotten to use the result of those.
2022-01-03 21:34:39 -08:00
Martin von Zweigbergk
f9e6b263a1 docs: explain how not exposing "the index" in the UI is a good thing 2021-12-18 09:22:35 -08:00
Martin von Zweigbergk
9eb4390a4d cli: fix a typo in help text of jj squash 2021-12-18 08:58:09 -08:00
Martin von Zweigbergk
71b0233efb docs: add doc about a first-class conflicts 2021-12-18 08:07:28 -08:00
Martin von Zweigbergk
ef4dbf216f docs: add links from README to detailed docs 2021-12-18 08:01:47 -08:00
Martin von Zweigbergk
423a894cba docs: consistently use hyphens in filenames 2021-12-18 07:56:48 -08:00
Martin von Zweigbergk
7b09a232bc docs: update doc about working copy now that conflicts are preserved
Conflicts are preserved in the working copy since ea82340654, I just
forgot to update the documentation.
2021-12-17 16:29:20 -08:00
Martin von Zweigbergk
66cedc804e docs: explain how to untrack a file while keeping it in the working copy
Issue #14 was fixed a while ago, but I forgot to update the
documentation.
2021-12-17 15:58:20 -08:00