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

feat(fossil_metrics): add fossil_metrics module #4874

Merged
merged 15 commits into from Sep 2, 2023
Merged

feat(fossil_metrics): add fossil_metrics module #4874

merged 15 commits into from Sep 2, 2023

Conversation

VegardSkui
Copy link
Contributor

@VegardSkui VegardSkui commented Jan 31, 2023

Description

Add a module to show the count of currently added and deleted lines in a Fossil check-out in the current directory. The module is analogous to the git_metrics module.

Motivation and Context

This is part of adding initial Fossil support to Starship. This lets users of Fossil repositories have some of the same functionality available in their check-outs as they already enjoy in their Git repositories. Initial support for Fossil was included in #4806, which added the fossil_branch module.

Contributes to the closing of #4036.

Screenshots (if appropriate):

NA

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Manual tests were ran both with and without Fossil installed and in multiple check-outs. I have also tested the module on FreeBSD.

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

Comment on lines 69 to 70
log::warn!("Error in module `fossil_metrics`:\nLast line of numstat diff missing.");
return None;
Copy link
Member

Choose a reason for hiding this comment

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

Error in module `fossil_metrics`:\n is a bit redundant, and the duplicate log message detector may have trouble with this. I would prefer having try_parse return a Result<Self, &str> instead. Please also add tests for some of the different error conditions.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't mean to say that you should be removing all error handling in the module, I think that is nice to have. The Error in module `fossil_metrics`:\n-prefix was redundant, because the log message will already contain WARN and the module name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I see. I tried to move closer to the implementation of git_metrics where an unexpected output leads to 0 changes reported, e.g. if the format of the command output changes in an update or the git binary is not actually Git. The different error conditions explicitly checked for previously should not be able to occur if a Fossil version later than v2.3 (2017-07-21) is installed (which introduced the --numstat option). I can revert the latest commit and fix the log messages if preferable, but I'm uncertain about what other input to test when it cannot be produced by Fossil.

@VegardSkui
Copy link
Contributor Author

VegardSkui commented Feb 8, 2023

A possible error condition is if the user has installed a version of Fossil >=v2.3 (2017-07-21), but older than v2.14 (2021-01-20). The final line with the total changes was introduced in v2.14, such that this module would then incorrectly report only the changes in whatever file is listed last. My initial thinking was that checking the installed version of Fossil on each run would be too much overhead in Starship (especially since the number of users of these versions is vanishingly small, for reference of the supported Debian repos only Buster ships one of these versions as far as I can see, and those users likely won't install a new version of Starship either), though the format of the last line could be checked before possibly looping over the earlier output and doing the summation manually.

@VegardSkui
Copy link
Contributor Author

There were an error in the Fossil check-out detection logic where subdirectories were not detected. This also affects the fossil_branch module, can I fix the error in fossil_branch in this pull request or should I create another? Also, is there an appropriate place for the is_checkout() function to be shared between the modules?

@davidkna
Copy link
Member

Please create another PR and try to have it share its code with the hg upwards search. You can put it into one of the utils modules or context.rs.

@davidkna
Copy link
Member

A possible error condition is if....

Please document this in the module docs.

Copy link
Member

@davidkna davidkna left a comment

Choose a reason for hiding this comment

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

This looks good to me if you document the range of supported fossil versions.

@andytom andytom merged commit e867cda into starship:master Sep 2, 2023
20 checks passed
@andytom
Copy link
Member

andytom commented Sep 2, 2023

Thank you for your contribution @VegardSkui and thanks for reviewing @davidkna.

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.

None yet

3 participants