Page MenuHomePhabricator

git-clang-format: refactor to support upcoming --staged flag

Authored by lodato on Dec 12 2017, 5:16 PM.



The only user-visible change is rewriting of the --help message to make the different modes more clear.

Internally, this is a significant refactoring to make the source and destination of the diff to be more clear by using subclasses rather than conditionals. The purpose is to support the next patch in this series, which adds support for a --staged flag. But even if that does not go through, the intent is for this code to be a readability improvement.

Note: In run_clang_format_and_save_to_tree(), we now generate the entire index up front rather than feeding it in line-by-line via a generator. The reason we must do this is because, in the future --staged implementation, we need to read from the index *before* calling crate_tree() since create_tree() uses a temporary index file. In practice, this will have no performance impact because the previous commit (D41130) switched to loading it all into memory in create_tree() anyway.

Diff Detail

Event Timeline

lodato created this revision.Dec 12 2017, 5:16 PM
klimek accepted this revision.Dec 13 2017, 1:02 AM



Don't we want to die if len(commits) > 2?

This revision is now accepted and ready to land.Dec 13 2017, 1:02 AM
lodato updated this revision to Diff 126792.Dec 13 2017, 10:58 AM

Re-add check for len(commits) > 2.

lodato marked an inline comment as done.Dec 13 2017, 10:58 AM

Oops! Fixed. Thanks for catching this!