Use indents to generate context for diffs
Problem to solve.
Often diffs are missing the context of where the code is written (condition or loop, function, class, XML element, JSON element).
Proposal
A good heuristic might be to look at indents as most file formats today indent more specific parts. The context for line A would be line B if:
- B appears before A
- B's indent (prefix tab count of space count) is lower than A's indent
The full context for line A would be B and it's own context recursively.
That would make a patch change from (using https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22207/diffs as an example):
@-179,6 +180,7 @@ module QA ... autoload :Repository, 'qa/page/project/settings/repository' autoload :CICD, 'qa/page/project/settings/ci_cd' autoload :DeployKeys, 'qa/page/project/settings/deploy_keys' + autoload :DeployTokens, 'qa/page/`ject/settings/deploy_tokens' autoload :ProtectedBranches, 'qa/page/project/settings/protected_branches' autoload :SecretVariables, 'qa/page/project/settings/secret_variables' autoload :Runners, 'qa/page/project/settings/runners' ...
to
@-179,6 +180,7 @@ module QA *module QA * module Page * module Project * module Settings ... autoload :Repository, 'qa/page/project/settings/repository' autoload :CICD, 'qa/page/project/settings/ci_cd' autoload :DeployKeys, 'qa/page/project/settings/deploy_keys' + autoload :DeployTokens, 'qa/page/`ject/settings/deploy_tokens' autoload :ProtectedBranches, 'qa/page/project/settings/protected_branches' autoload :SecretVariables, 'qa/page/project/settings/secret_variables' autoload :Runners, 'qa/page/project/settings/runners' ...
which allows identification of context in a single glance.
What does success look like, and how can we measure that?
Success can be measured by less repetitive "expand" actions to discover the true context of the change.