Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit_templater: encode elided node as Option<Commit> #3319

Merged
merged 2 commits into from
Mar 24, 2024

Conversation

yuja
Copy link
Contributor

@yuja yuja commented Mar 18, 2024

#3260

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@yuja yuja force-pushed the push-usppyytsxypy branch 2 times, most recently from 1f3d5f3 to 602f09e Compare March 18, 2024 15:56
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about this. I like the idea of having optional values in general, but I I'm not convinced the jj log template should have Option<Commit> as context object (I'm not convinced they shouldn't either).

@yuja
Copy link
Contributor Author

yuja commented Mar 19, 2024

but I I'm not convinced the jj log template should have Option<Commit> as context object (I'm not convinced they shouldn't either).

This is primarily designed for the graph node template. I thought it could apply to the text part, but I agree it wouldn't be that useful.

Regarding the context object, I hope we can eventually relax it to any types known to the template language. Perhaps, CommitTemplateLanguage will define all types dependent on the Repo, and renamed to RepoTemplateLanguage.

@yuja
Copy link
Contributor Author

yuja commented Mar 19, 2024

Regarding the context object, I hope we can eventually relax it to any types known to the template language.

Since self in templater is basically a property function that clones &Context, we can get rid of the Context type from the inner template during compilation, and inject self property as a placeholder property. It allows us to select arbitrary context type without exploding the number of the extension types.

impl TemplateLanguage for CommitTemplateLanguage {
    type Context = ();
}

let placehodler = ..; // Rc<RefCell<C>> stuff to insert arbitrary "self" variable
let make_self = || some_wrapping(placeholder);
ctx.local_variables.insert("self", &make_self);
let inner_template: Box<Template<()>> = build(language, &ctx, node)?;
let outer_template: Template<C> = Wrapper { inner_template, placeholder }

It's a bit messy, but seems doable.

FWIW, do you like the idea of using Context = Option<Commit> in graph node template?

@ilyagr
Copy link
Contributor

ilyagr commented Mar 21, 2024

I am mainly reacting to the title of the PR, so I could easily be missing the point, but I'd love for an elided node to eventually keep track of approximately how many commits were elided. Perhaps the type should be called something else, even if it's equivalent to Option<Commit> today.

@yuja
Copy link
Contributor Author

yuja commented Mar 21, 2024

for an elided node to eventually keep track of approximately how many commits were elided.

Yes. It suggests that the "(elided revisions)" text shouldn't be a part of the common commit template.

I still think Option<Commit> is good for a graph node template:

templates.log_node = 'if(self, if(current_working_copy, "@", "o"), "=")'

yuja added 2 commits March 23, 2024 16:35
I think Option<Commit> is the simplest encoding of the log node.

The behavior of an Option type is closer to nullable types rather than the
Option in Rust. I don't think we would want to write opt.map(|x| x.f()) or
opt.unwrap().f(). We can of course add opt?.f() syntax, but it will be a short
for "if(opt, opt.f())"?
Since elided graph entry has no associated commits, it makes some sense to
represent as None?
@yuja yuja force-pushed the push-usppyytsxypy branch from 602f09e to 702fa0f Compare March 23, 2024 07:41
@yuja yuja marked this pull request as ready for review March 23, 2024 07:47
@yuja
Copy link
Contributor Author

yuja commented Mar 23, 2024

This is now ready for review.

  • The log text template is unchanged, and its context is of Commit type.
  • The log node template is changed to Option<Commit> type.

@yuja yuja changed the title commit_templater: encode elided node as Option<Commit> (PoC) commit_templater: encode elided node as Option<Commit> Mar 23, 2024
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. What do you think, @algmyr and @ilyagr?

@algmyr
Copy link
Contributor

algmyr commented Mar 23, 2024

LGTM, eventually we would probably want to expose more things like ascii/non-ascii and at that point elided could maybe be a property. But until that point this simplifies things.

@yuja
Copy link
Contributor Author

yuja commented Mar 24, 2024

expose more things like ascii/non-ascii and at that point elided could maybe be a property.

For ascii/non-ascii, maybe we can add config_<type>(key) (or config(key).to_<type>()) accessor.

@yuja yuja merged commit c311131 into jj-vcs:main Mar 24, 2024
16 checks passed
@yuja yuja deleted the push-usppyytsxypy branch March 24, 2024 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants