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

Refactor config-merging #147

Merged
merged 3 commits into from
Feb 7, 2025
Merged

Conversation

blairconrad
Copy link
Contributor

Fixes #146.

@blairconrad
Copy link
Contributor Author

@tummychow, a work-in-progress. Mostly because I have ideas that I am not sure are compatible with yours, so here's a (functional) PR that at least starts a conversation.

@@ -730,15 +717,16 @@ lines

become_new_author(&ctx);

ctx.repo.config()
ctx.repo
.config()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you can see, from a bonus commit that fixed bad formatting I previously introduced. You seem pragmatic, but I'm not sure how you feel about introducing such a bonus commit into this PR.

(As an aside, if keeping a good format is important to you (and I suspect it is, or the whole repo wouldn't've been formatted), is there interest in having a job that would check formatting when PRs come in? It could either prevent the merge or serve as a warning.)

Copy link
Owner

Choose a reason for hiding this comment

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

yeah, formatting in ci sgtm, and having this commit here is also fine with me

)
}

fn bool_value(repo: &Repository, setting_name: &str, default_value: bool) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed to me to be a reasonable start at deduping. Requires a different function per type of config data (and there's only one usize, so I didn't bother extracting). Happy to hear what you think could be improved.

Copy link
Owner

Choose a reason for hiding this comment

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

quite reasonable

),
force_author: config.force_author
|| config.force
|| bool_value(&repo, FORCE_AUTHOR_CONFIG_NAME, FORCE_AUTHOR_DEFAULT),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the liberty of inlining the above two calls to get the configuration data from git. The long constant names introduce wrapping, which maybe spoils the effect. If you prefer the methods back, happy to re-add.

_ => ONE_FIXUP_PER_COMMIT_DEFAULT,
}
}

pub fn auto_stage_if_nothing_staged(repo: &git2::Repository) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if you'd want the values from these methods added to the Config object so we don't have to call them from throughout the code. Easy enough to do, if you like it, but introduces questions:

  1. do we want to expand Config with the extra attributes?
  2. if not, how do you feel about a new struct that holds the unified settings? It wouldn't bloat Config, and will eventually allow dropping of the force attribute when it's only used to enable the other force_ attributes
  3. if you did like the idea of a second struct, naming becomes trickier; me, I'd avoid Config for either the new or existing struct (already taken by git's config) and probably look for name that indicate how the one struct comes from command-line arguments and the new one represents the unified settings. I'm just thinking out loud here.

Copy link
Owner

Choose a reason for hiding this comment

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

let's leave em as standalone functions for now. Config was originally intended to carry the cli arguments. i'm not tied to that interpretation of it, but no need to move everything in there atm

Copy link
Owner

@tummychow tummychow left a comment

Choose a reason for hiding this comment

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

pr looks fine to me, i would merge this as-is. were there more things you wanted to do or discuss?

@blairconrad blairconrad changed the title [WIP] Refactor config-merging Refactor config-merging Feb 7, 2025
@blairconrad
Copy link
Contributor Author

pr looks fine to me, i would merge this as-is. were there more things you wanted to do or discuss?

Ah, thanks. Mostly just concerned about matching your intent. Thanks for comments. Removed WIP from title. Merge away!

@tummychow tummychow merged commit 1999cfd into tummychow:master Feb 7, 2025
3 checks passed
@blairconrad blairconrad deleted the refactor-config branch February 7, 2025 11:37
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.

Refactor config-building in lib.rs's run_with_repo
2 participants