Skip to content

Commit e7fa478

Browse files
committed
revset, templater: deprecate git_head() and git_refs() functions
While these two are stored in view objects, we intentionally ignore them when undoing. This means that these fields don't have to be tracked by view/operation. I think we can move them away to GitBackend-specific data. We could provide git_head()/git_refs() that load data from GitBackend, but I don't think these template/revset functions are useful. I've never used them except for the git_head() template function, and its use case was to see whether the repository is colocated or not.
1 parent 4900c9c commit e7fa478

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1717

1818
### Deprecations
1919

20+
* The `git_head()` and `git_refs()` functions will be removed from revsets and
21+
templates. `git_head()` should point to the `@-` revision in colocated
22+
repositories. `git_refs()` can be approximated as
23+
`remote_bookmarks(remote=glob:*) | tags()`.
24+
2025
### New features
2126

2227
* Updated the executable bit representation in the local working copy to allow

cli/src/commit_templater.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,18 +1162,28 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
11621162
Ok(out_property.into_dyn_wrapped())
11631163
},
11641164
);
1165+
// TODO: Remove in jj 0.43+
11651166
map.insert(
11661167
"git_refs",
1167-
|language, _diagnostics, _build_ctx, self_property, function| {
1168+
|language, diagnostics, _build_ctx, self_property, function| {
1169+
diagnostics.add_warning(TemplateParseError::expression(
1170+
"commit.git_refs() is deprecated; use .remote_bookmarks()/tags() instead",
1171+
function.name_span,
1172+
));
11681173
function.expect_no_arguments()?;
11691174
let index = language.keyword_cache.git_refs_index(language.repo).clone();
11701175
let out_property = self_property.map(move |commit| index.get(commit.id()).to_vec());
11711176
Ok(out_property.into_dyn_wrapped())
11721177
},
11731178
);
1179+
// TODO: Remove in jj 0.43+
11741180
map.insert(
11751181
"git_head",
1176-
|language, _diagnostics, _build_ctx, self_property, function| {
1182+
|language, diagnostics, _build_ctx, self_property, function| {
1183+
diagnostics.add_warning(TemplateParseError::expression(
1184+
"commit.git_head() is deprecated; use .contained_in('@-') instead",
1185+
function.name_span,
1186+
));
11771187
function.expect_no_arguments()?;
11781188
let repo = language.repo;
11791189
let out_property = self_property.map(|commit| {

cli/src/config/colors.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"remote_bookmarks" = "magenta"
3232
"tag" = "magenta"
3333
"tags" = "magenta"
34+
# TODO: remove git_refs and git_head (but not git_ref) in jj 0.43+
3435
"git_ref" = "green"
3536
"git_refs" = "green"
3637
"git_head" = "green"

cli/tests/test_commit_template.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,15 @@ fn test_log_git_head() {
795795
○ true
796796
◆ false
797797
[EOF]
798+
------- stderr -------
799+
Warning: In template expression
800+
--> 1:1
801+
|
802+
1 | git_head
803+
| ^------^
804+
|
805+
= commit.git_head() is deprecated; use .contained_in('@-') instead
806+
[EOF]
798807
");
799808

800809
let output = work_dir.run_jj(["log", "--color=always"]);

docs/revsets.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ revsets (expressions) as arguments.
286286
tags `v123` and `rev1` but not the tag `v2`. If a tag is
287287
in a conflicted state, all its possible targets are included.
288288

289-
* `git_refs()`: All Git ref targets as of the last import. If a Git ref
290-
is in a conflicted state, all its possible targets are included.
291-
292-
* `git_head()`: The Git `HEAD` target as of the last import.
293-
294289
* `visible_heads()`: All visible heads (same as `heads(all())` if no hidden
295290
revisions are mentioned).
296291

docs/templates.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ This type cannot be printed. The following methods are defined.
161161
local one.
162162
* `.local_tags() -> List<CommitRef>`: All local tags pointing to the commit.
163163
* `.remote_tags() -> List<CommitRef>`: All remote tags pointing to the commit.
164-
* `.git_refs() -> List<CommitRef>`
165-
* `.git_head() -> Boolean`: True for the Git `HEAD` commit.
166164
* `.divergent() -> Boolean`: True if the commit's change id corresponds to multiple
167165
visible commits.
168166
* `.hidden() -> Boolean`: True if the commit is not visible (a.k.a. abandoned).

lib/src/revset.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,21 @@ static BUILTIN_FUNCTION_MAP: LazyLock<HashMap<&str, RevsetFunction>> = LazyLock:
932932
};
933933
Ok(RevsetExpression::tags(expr))
934934
});
935-
map.insert("git_refs", |_diagnostics, function, _context| {
935+
// TODO: Remove in jj 0.43+
936+
map.insert("git_refs", |diagnostics, function, _context| {
937+
diagnostics.add_warning(RevsetParseError::expression(
938+
"git_refs() is deprecated; use remote_bookmarks()/tags() instead",
939+
function.name_span,
940+
));
936941
function.expect_no_arguments()?;
937942
Ok(RevsetExpression::git_refs())
938943
});
939-
map.insert("git_head", |_diagnostics, function, _context| {
944+
// TODO: Remove in jj 0.43+
945+
map.insert("git_head", |diagnostics, function, _context| {
946+
diagnostics.add_warning(RevsetParseError::expression(
947+
"git_head() is deprecated; use @- instead",
948+
function.name_span,
949+
));
940950
function.expect_no_arguments()?;
941951
Ok(RevsetExpression::git_head())
942952
});

0 commit comments

Comments
 (0)