Commit graph

3061 commits

Author SHA1 Message Date
Yuya Nishihara
b290af8e29 op_walk: include operation ids in multiple match error 2024-08-03 09:22:26 +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
Stephen Jennings
ff9e739798 revset: create DatePattern type
Creates a DatePattern type that can be created by parsing a string in any
format supported by the chrono-english crate, including:

- 2024-03-25
- 2024-03-25T00:00:00
- 2024-03-25T00:00:00-08:00
- 2 weeks ago
- 5 minutes ago
- yesterday
- yesterday 5pm
- yesterday 10:30
- yesterday 15:30
- tomorrow

A `kind` can be specified to indicate whether the pattern should match dates at
or after (`after`) or strictly before (`before`) the given instant.

chrono-english supports US and UK dialects to disambiguate mm/dd/yy from
dd/mm/yy, but for now we default to US. This should probably be a config
setting.
2024-08-01 09:04:07 -07:00
dploch
bfa1ce8936 workspace: make the constructor public
This allows constructing a workspace in a custom environment where the standard filesystem API cannot be used
2024-07-31 19:45:37 -04:00
dploch
5f7e3883e8 repo: define a public constructor for RepoLoader
This enables the creation of Repo objects in environments without standard filesystem support, by allowing the caller to load the store objects however they see fit. This confines interaction with the filesystem to the WorkingCopy abstractions.
2024-07-31 19:45:37 -04:00
Yuya Nishihara
d2f933eed3 commit_builder: remove unneeded &mut from .write_hidden()
Since the backend::Commit has to be cloned, .write_hidden() doesn't mutate the
self.commit object.
2024-07-25 22:39:00 +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
Martin von Zweigbergk
352ca72314 tests: make helpers create non-legacy trees
Extracted and modified from #3746 by @ilyagr.
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
da221eb888 repo: load index eagerly to simplify error handling
If readonly_index() and index() returned Result, it would propagate to many
call sites. That seems bad for API ergonomics. Suppose most "repo" commands
depend on an index, I think it's okay to load index eagerly:

 - "jj config" doesn't load repo (nor index)
 - "jj workspace root" doesn't load repo (nor index)
 - some other mutation commands load index when printing commit summary
 - many other commands load index when resolving revset
2024-07-23 18:26:16 +09:00
Yuya Nishihara
626aa90610 repo: use DetachedCommitBuilder constructors
I think this makes it clear that the builder doesn't add any rewrite records
to the mut_repo.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
337dcef6ee commit_builder: add public interface that writes temporary commit to store
In order to render description template, we'll need a Commit object that
represents the old state (with new tree and parents) before updating the
commit description. The added functions will help generate an intermediate
Commit object.

Alternatively, we can create an in-memory Commit object with some fake
CommitId. It should be lightweight, but might cause weird issue because the
fake id wouldn't be found in the store.

I think it's okay to write a temporary commit and rely on GC as we do for
merge trees. However, I should note that temporary commits are more likely to
be preserved as they are pinned by no-gc refs until "jj util gc".
2024-07-23 18:22:40 +09:00
Yuya Nishihara
b4bf1358a5 commit_builder: extract inner builder which isn't lifetimed by mut_repo
This allows us to construct a builder, format description template with an
intermediate commit, then write() a final commit object to the repo.

I originally considered removing mut_repo from CommitBuilder at all, but
rewriter APIs rely on that CommitBuilder has &mut_repo, and splitting them
would make call sites uglier.

The inner builder methods are based on &mut Self instead of Self, because it's
easier to wrap, and users of the inner builder will bind it to a named variable
anyway.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
6516a40c19 commit_builder: extract free function that sets up signing and write commit
I'll add another write() method that doesn't consume self, which will have to
clone self.commit.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
fab310f53f commit_builder: keep Store internally
I'm going to extract an inner builder that is free from &mut MutableRepo
lifetime.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
49d92a0480 commit_builder: remove redundant boxing from signing fn closure 2024-07-23 18:22:40 +09:00
Yuya Nishihara
209e076bfc commit_builder: use .clone_from() to silence nightly clippy warning
It's not wrong that String::clone_from() could potentially be cheaper.
2024-07-23 18:22:40 +09:00
Benjamin Tan
58a813cb18 repo: add RepoLoader::merge_operations 2024-07-22 19:16:42 +08:00
Benjamin Tan
87ea9102f0 repo: add MutableRepo::merge_index 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
Yuya Nishihara
845793a7ad str_util: remove Eq + PartialEq from StringPattern
I'm going to add regex support, and compiled Regex object isn't comparable.
2024-07-22 12:00:52 +09:00
Yuya Nishihara
5783631271 tests: use assert_matches!() to compare StringPattern 2024-07-22 12:00:52 +09:00
Yuya Nishihara
9d5eda107d commit_builder: inline mut_repo.write_commit()
As the doc comment says, it's called only from CommitBuilder. Let's clarify
that. I'm also planning to extract a builder that only writes to the store
(without mutably borrowing a mut_repo.) It will help implement description
template.
2024-07-20 09:06:46 +09:00
Ilya Grigoriev
e2f12d91cc conflicts: switch to multi-line regex, fix minor bug
The multi-line regex will be used for other purposes soon.
2024-07-18 18:42:40 -07:00
Ilya Grigoriev
d095570718 conflicts: demo minor bug 2024-07-18 18:42:40 -07:00
Ilya Grigoriev
f3de66e603 conflicts: demo failure to materialize if conflicts don't end in a newline
#3968
2024-07-18 18:42:40 -07:00
Matt Kulukundis
6ffe05290d copy-tracking: move unit tests into backend specific file 2024-07-18 05:44:56 -04: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
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
e5b49c7d52 files: extract pre-processing part from merge()
I'll make the first half generic over T: AsRef<[u8]>.
2024-07-18 11:34:43 +09:00
Yuya Nishihara
895eead4b8 revset: add diff_contains(text[, files]) to search diffs
The text pattern is applied prior to comparison as we do in Mercurial. This
might affect hunk selection, but is much faster than computing diff of full
file contents. For example, the following hunk wouldn't be caught by
diff_contains("a") because the line "b\n" is filtered out:

    - a
      b
    + a

Closes #2933
2024-07-18 01:01:16 +09:00
Yuya Nishihara
eabff4c0b4 revset: propagate BackendError from inner file() predicate function
We should probably add error propagation path to Revset iterator, and predicate
functions will return Result<bool, RevsetEvaluationError>.
2024-07-18 01:01:16 +09:00
Yuya Nishihara
a6a67fa8fd revset: pass Commit object to inner file() predicate function
Commit object extraction is common across predicate functions.
2024-07-18 01:01:16 +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
Matt Kulukundis
3043b83a8f copy-tracking: add get_copy_records to Store 2024-07-16 13:18:49 -04: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
Yuya Nishihara
c74cf2d80d revset: use .ok_or_else() to handle missing workspace context
FWIW, this might be changed to non-error so that "file()" revset can be used
at server side.
2024-07-16 10:18:57 +09:00
Matt Kulukundis
df021083c9 diff: add unit tests for copy tracking in the git backend 2024-07-15 16:49:10 -04:00
Yuya Nishihara
6f6381d06e diff: leverage BStr for better debug printing 2024-07-14 23:26:29 +09:00
Yuya Nishihara
502547d6a5 diff: add generic DiffHunk constructors
For the same reason as the previous patch. I'm going to make DiffHunk leverage
BStr wrapper instead of custom Debug impl.

b"" literals in tests are changed to &str to get around type incompatibility
between &[u8; N].
2024-07-14 23:26:29 +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
Yuya Nishihara
2ca3bad0ee diff: split non-generic part from Diff::for_tokenizer() 2024-07-14 23:26:29 +09:00
Yuya Nishihara
5601fb40f8 cargo: add "bstr" dependency
I'm going to replace some Debug impls with BStr, and we already depend on
"bstr" through "gix".
2024-07-14 23:26:29 +09:00
Yuya Nishihara
ac2bddbc3d cargo: remove unused "bytes" dependency 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
Tim Janik
11f56800fa test_gpg: fix warnings ending up on stdout
Signed-off-by: Tim Janik <timj@gnu.org>
2024-07-12 10:32:13 +09:00
Tim Janik
219a63540f local_working_copy: fix warnings ending up on stdout
As suggested by @crackcomm on discord, use eprintln!() to print warnings
to avoid messing up template output, e.g.:

jj --no-pager --ignore-working-copy show --tool true -T change_id -r rv...
rv...ignoring git submodule at "some/submodule"

Signed-off-by: Tim Janik <timj@gnu.org>
2024-07-12 10:32:13 +09:00
Yuya Nishihara
ffd7b41d2b revset: rename expect_literal_with() to expect_expression_with()
The return type T doesn't have to be a literal, and I'm going to use this
function to reparse fileset expression. We might also want to add another
expect_literal_with() helper that parses enum-like string value.
2024-07-12 10:31:45 +09:00
Yuya Nishihara
415c831e30 revset: flatten union nodes in AST to save recursion stack
Maybe it'll also be good to keep RevsetExpression::Union(_) flattened, but
that's not needed to get around stack overflow. The constructed expression
tree is balanced.

test_expand_symbol_alias() is slightly adjusted since there are more than
one representation for "a|b|c" now.

Fixes #4031
2024-07-11 11:20:25 +09:00