Commit Graph

821 Commits

Author SHA1 Message Date
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
Martin von Zweigbergk
006cb37183 docs: replace jj concepts by markdown docs
I wanted to have all the documentation available on the command line,
but that makes it harder to maintain and link to. Let's move it to
markdown instead. We may later be able to add some way of presenting
the markdown in the terminal (or maybe by first converting it to
reStructuredText).
2021-12-17 15:18:41 -08:00
Martin von Zweigbergk
9e591def26 cli: add jj show command for showing commit description and diff
This functionality is probably what I miss most from git/hg.
2021-12-17 13:28:09 -08:00
Martin von Zweigbergk
8d3ad34009 cli: extract function for showing diff style based on args and config
I'm about to add a `jj show` command (like `git show`), and that'll
have the same arguments and config for deciding which style of diff to
show.
2021-12-17 11:28:07 -08:00
Martin von Zweigbergk
277f42d98a revsets: add author() and committer() functions (#46)
Filtering by the author or committer is quite common.
2021-12-15 22:50:29 -08:00
Martin von Zweigbergk
7d3d0fe83c revsets: allow the .. operator to be used as prefix or suffix (#46)
It makes sense to omit either of the arguments of the `..` operator,
even though `..x` is equivalent to `:x`. `x..`, with a implied right
argument of `heads()` is more useful.
2021-12-15 22:16:22 -08:00
Martin von Zweigbergk
bc92b82ed4 revsets: use a single grammar rule for the : operator (#46) 2021-12-15 21:57:55 -08:00
Martin von Zweigbergk
588389e89f docs: add pointer to new revset doc in tutorial (#46) 2021-12-15 21:41:11 -08:00
Martin von Zweigbergk
4c71c763e9 docs: document revsets (#46)
Now that revset operators are not as embarrassing as before, let's
document them.
2021-12-15 16:56:45 -08:00