3762 Commits

Author SHA1 Message Date
Ilya Grigoriev
bb902b69b5 Revert "git_backend: stop writing tree ids to proto"
This reverts commit b8ca9ae and adds a comment.

In commit 4d42604 (a year ago), we started writing the trees involved in
conflicted commits to the Git commit object in addition to the proto
storage. We validated that the two record matched when reading commits
until as recently as f7b14be (about a week ago). Just after that, in
commit b8ca9ae, we stopped writing the tree ids to the proto storage.
That means that any version of jj between 4d42604 and f7b14be would
error fail when reading a conflicted commit created by new versions.
While we don't guarantee forward compatibility, it's easy to do so here,
so let's be friendly to older versions by rolling back b8ca9ae so we
continue to write the conflicted tree ids to both places for a while
more.

(Thanks to Martin for the detailed explanation!)

Fixes https://github.com/jj-vcs/jj/issues/6185
2025-03-31 23:19:21 +00:00
Yuya Nishihara
3f5f872204 view: rename workspace "id" to "name"
This matches the current implementation.
2025-03-31 03:39:29 +00:00
Yuya Nishihara
e66c545438 view: replace WorkspaceId by string-like newtypes
I think this makes more sense because WorkspaceId is currently a human-readable
name. In error/status messages, workspace names are now printed in revset
syntax.

New WorkspaceId types do not implement Default. It would be weird if string-like
type had non-empty Default::default(). The DEFAULT constant is provided instead.
2025-03-31 03:39:29 +00:00
Yuya Nishihara
f87db58617 view: rename RemoteRefState::Tracking to Tracked
In jj's model, a local bookmark "tracks" remote bookmarks. It's wrong to call
a remote bookmark state as "tracking".
2025-03-31 01:41:31 +00:00
Yuya Nishihara
e4982a9c33 git: report HEAD export failure as warning
It's safe to commit transaction even if HEAD couldn't be updated due to
concurrent changes.

Closes #6098
2025-03-30 01:46:00 +00:00
Yuya Nishihara
cd1ee943e6 git: split GitResetHeadError, add UpdateHeadRef variant
This helps handle "HEAD" export failure differently. At this point, the set of
error variants look distinct enough to split the error types.
2025-03-30 01:46:00 +00:00
Yuya Nishihara
c33be3839d git: remove redundant error context messages, rename variants
Wrapped errors are usually displayed after "Failed to import refs ...", etc., so
the context is obvious. I also removed "Internal"/"Error" for consistency.
2025-03-30 01:46:00 +00:00
Yuya Nishihara
d6be4a598e git: use GitRefName newtypes in push functions 2025-03-28 01:29:30 +00:00
Yuya Nishihara
fb8e45d6f9 view: introduce GitRefName newtypes
We don't reuse the RefName type here because fully-qualified Git ref name
shouldn't be considered a local ref name in jj.
2025-03-28 01:29:30 +00:00
Yuya Nishihara
bcf3d5869b revset: add optional local variables to RevsetParseContext 2025-03-27 13:23:58 +00:00
Yuya Nishihara
483e7941b4 revset: add support for local variables expansion
I think this can be used in order to substitute remote name in the default push
revset expression?

  push(remote) = remote_bookmarks(remote=remote)..@
2025-03-27 13:23:58 +00:00
Yuya Nishihara
ffad6fe96f revset: extract internal context struct from RevsetParseContext
This allows callers to mutate RevsetParseContext if needed.

RevsetParseContext was changed to an opaque struct at 4e0abf06317f "revset: make
RevsetParseContext opaque." I think the intent there was to hide implementation
details from revset extension functions. This is now achieved by opaque
LoweringContext.

Another reason of this change is that aliases_map is no longer needed when
transforming AST to UserRevsetExpression.
2025-03-26 13:03:41 +00:00
Yuya Nishihara
3656a62bf5 git: use RemoteName newtype in remote management functions 2025-03-26 13:03:37 +00:00
Yuya Nishihara
aa0327667f git: extract default_fetch_refspec(remote) helper 2025-03-26 13:03:37 +00:00
Yuya Nishihara
d44251a2a5 git: use RemoteName newtype in push functions 2025-03-26 13:03:37 +00:00
Yuya Nishihara
4ff2827d00 git: use RemoteName/RefName newtypes in fetch functions 2025-03-26 13:03:37 +00:00
Yuya Nishihara
b9f51ff992 ref_name: add RefName::to_remote_symbol(remote) for convenience 2025-03-26 13:03:37 +00:00
Yuya Nishihara
02722eae54 view: port bookmark/tag name types to RefName/RemoteName
I tried to minimize this patch, but it seemed rather complicated than porting
most callers all at once. Remote management functions in git.rs are unchanged.
They'll be ported separately.

With this change, many non-template bookmark/remote name outputs should be
rendered in revset syntax.
2025-03-26 11:07:06 +00:00
Yuya Nishihara
05e10920e6 view: wrap (remote, name) pair in RemoteRefSymbol by flatten_remote_bookmarks()
Since RemoteRefSymbol is now hosted by ref_name module, it seems good that
op_store depends on it.
2025-03-26 11:07:06 +00:00
Yuya Nishihara
db4382d395 str_util: add filter_btree_map_*() that can accept Ref/RemoteName newtypes
It's a bit weird that Deref is required, but this helps deduce the query type.
Maybe we can add typed StringPattern wrapper, but I'm not sure if that's a good
idea.

Alternatively, RefNameBuf could implement Borrow<str>, but that means the map
could be looked up by weakly-typed string keys.
2025-03-26 11:07:06 +00:00
Yuya Nishihara
d227479450 git: use "if" to reject bad branch/remote names in parse_git_ref()
This will help port branch/remote names to RefName/RemoteName types.
2025-03-26 11:07:06 +00:00
Yuya Nishihara
cc8a80c548 ref_name: move RemoteRefSymbol types from refs module 2025-03-26 11:07:06 +00:00
Yuya Nishihara
0efc9423d5 ref_name: add RefName and RemoteName newtypes
These types are akin to ObjectId types, but for refs. Perhaps, WorkspaceId can
be ported to impl_name_type!().

These types don't implement Display because it would be source of subtle bugs
if a string-like type could be formatted differently. For example, we would
have to be careful to not format!("refs/heads/{name}") if the name implemented
a default Display in revset syntax.
2025-03-26 11:07:06 +00:00
Yuya Nishihara
c9cd59ada7 content_hash: forward String::hash() to str
This is basically the same as Vec<T> and [T].
2025-03-26 11:07:06 +00:00
Baltasar Dinis
8ae80523e4 git: forward rejection reason on push
We've been finding that a lot of bug reports on `jj git push` come from
sub-standard error reporting on the reasons the failure happens.

It can come from a number of places:
 - hook failure
 - remote branch protection
 - git config

This commit forwards the reason as explained by the ouptut of git push
to help users figure out what is happening.
2025-03-26 04:46:38 +00:00
Baltasar Dinis
89bb1c4e71 git: refactor push ref error reporting
We need to report more complicated errors on push.
Firstly, we can have a mix of unexpected ref locations and remote
rejections. We should report both at the same time.

Second, git gives us a reason for why a push failed.
For this to work, it's relevant to refactor the current error reporting
path to allow us to inject this information.
2025-03-26 04:46:38 +00:00
Martin von Zweigbergk
108aae1d9b git: set --intent-to-add on new files
In colocated repos, we set up the Git index to make `git diff` closely
match `jj diff`. However, `git diff` will not include new files. We're
long talked about using the `git add --intent-to-add` feature to make
the match closer. This patch implements that. It does so both after
updating the working copy and after snapshotting. After updating the
working copy, the new file in the working-copy commit (compared to the
parent(s)) are marked as intent-to-add. After snapshotting, newly
snapshotted files are marked as intent-to-add, and deleted ones that
were previously marked as intent-to-add are removed from the index.

Closes #6122
2025-03-25 13:40:13 +00:00
Scott Taylor
301f14e856 git_backend: don't allow single tree in jj:trees header
It is important for this case to be an error, because otherwise it would
be possible to construct a non-conflicted commit which appears to have a
different tree when viewed using `jj` than when viewed using Git. This
could potentially be used to hide malicious code in commits in such a
way that on GitHub, the code would appear normal, but it would become
malicious when cloned using `jj`.

Prior to f7b14beacc678a9b351ae65224df43a96aa26392, if a commit had a
`jj:trees` header with only a single tree, it would result in a panic of
"root tree should have been initialized to a legacy id". This commit
restores the error behavior by adding an explicit check for this case.
2025-03-25 12:42:39 +00:00
Scott Taylor
c96d7856a7 git_backend: add test for jj:trees with one tree
This demonstrates an issue which will be fixed by the next commit.
2025-03-25 12:42:39 +00:00
Martin von Zweigbergk
e392448288 time_util: replace use of chrono-english by interim
https://rustsec.org/advisories/RUSTSEC-2024-0395 recommends switching
from `chrono-english` to `interim` because the former is unmaintained.
2025-03-24 23:59:21 +00:00
Yuya Nishihara
5ee1dbbd22 git: wrap list of failed exports in struct
I have no immediate plan, but I think we can make "jj git export" show exported
refs. The FailedRefExport type is replaced with a plain tuple since we have a
named type wrapping (symbol, reason) pairs now.
2025-03-24 01:18:24 +00:00
Yuya Nishihara
c75dbfdabb git: rename "branch" in export code path 2025-03-24 01:18:24 +00:00
Martin von Zweigbergk
b8ca9ae806 git_backend: stop writing tree ids to proto
We have been writing conflicted tree ids to the `jj:trees` commit
header since 4d426049 (just over a year ago) and we have been able to
read them from there since the same commit. This patch updates the
write path so we no longer redundantly write the trees to the proto
storage.
2025-03-23 16:12:22 +00:00
Martin von Zweigbergk
f7b14beacc git_backend: if jj:trees header exists, ignore tree ids from proto
We write the `jj:trees` commit header since 4d426049. If the
information is written to that header, we should not require it to
also be in the proto storage.
2025-03-23 16:12:22 +00:00
Martin von Zweigbergk
e7a36bbd8d git_backend: remove some unused code for legacy conflicts
We have called `import_head_commits_with_tree_conflicts()` only with
`uses_tree_conflict_format=true` outside of tests since aa0fbd9f.
2025-03-23 16:12:22 +00:00
Yuya Nishihara
7404338362 git: replace remaining caller of old parse_git_ref() 2025-03-23 11:02:49 +00:00
Yuya Nishihara
f6800787ed git: inline parsing of remote default branch
This should be simpler than using parse_git_ref_inner(), and we'll drop git2
support anyway.
2025-03-23 11:02:49 +00:00
Yuya Nishihara
8ed9c36377 git: in import_refs(), use sorted vec as map of bookmarks/tags
For consistency with export_refs().

changed_git_refs doesn't have to be sorted, but the sorting cost wouldn't matter
in practice.
2025-03-23 01:32:29 +00:00
Yuya Nishihara
b6419ca790 git: in import_refs(), split known remote bookmarks/tags maps
It's simpler, and more consistent with export_refs().
2025-03-23 01:32:29 +00:00
Yuya Nishihara
ddaa909977 git: extract inner loop that compares known refs and actual refs to import
I'll split known_remote_refs to bookmarks and tags, and the input Git refs
iterators are also filtered by ref types.
2025-03-23 01:32:29 +00:00
Yuya Nishihara
7d59d0564e git: use translated remote symbols in export_refs()
I also made to_git_ref_name() stricter as it seemed odd that empty tag name and
remote name were allowed.
2025-03-23 01:32:29 +00:00
Yuya Nishihara
c3a32c4265 git: in export_refs(), use sorted Vec as map of bookmarks
I'm going to change the key type from RefName to RemoteSymbolBuf, but the std
BTreeMap/HashMap doesn't support lookup by un-Borrow-able ref types. We can use
hashbrown::HashMap, but there aren't popular alternative for ordered maps.
Since we don't need random insertion and lookup, we can simply use Vec.
2025-03-23 01:32:29 +00:00
Yuya Nishihara
e52ddda98f conflicts: pack MaterializedTreeValue::File fields, use read_all() helper
This pattern is common.
2025-03-23 01:31:15 +00:00
Yuya Nishihara
a1eff5057a conflicts: extract MaterializedFileValue type from absorb
The interface is slightly adjusted because it wouldn't make much sense that
generic read_all() method returned BString.
2025-03-23 01:31:15 +00:00
Martin von Zweigbergk
1a98a73ae4 fix: avoid an unnecessary clone 2025-03-21 19:56:26 +00:00
Caleb White
680c41c30f signing: add gpgsm backend
The adds support for PKCS#12 certificates through the `gpgsm` backend.

Closes #5856
2025-03-20 17:01:39 +00:00
Fedor Sheremetyev
364ece09e0 signing: Don't show console on Windows
When used inside GUI application, enabling GPG or SSH signing causes console window to appear temporarily.

std::process::Command needs special flags to prevent that. More details: https://stackoverflow.com/a/60958956
2025-03-19 18:40:16 +00:00
Fedor Sheremetyev
a028e4a03a git: Don't show console on Windows
When used inside GUI application, git.subprocess=true option causes console window to appear temporarily.

std::process::Command needs special flags to prevent that. More details: https://stackoverflow.com/a/60958956
2025-03-19 18:40:16 +00:00
Martin von Zweigbergk
bdbb7afbbb protos: finish local_store->simple_store migration from f8ab8a0e 2025-03-19 17:32:02 +00:00
Ilya Grigoriev
1247aaf7f0 lib str_utils: make debug output for Glob StringPatterns more concise
For example, we'll have `Glob(GlobPattern("ig/*"))` instead of the
former

```
Glob(Pattern { original: "ig/*", tokens: [ Char( 'i', ), Char( 'g', ), Char( '/', ), AnySequence, ], is_recursive: false,
})
```
2025-03-18 06:02:05 +00:00