line-log: scope stat, check, and -G to -L line ranges - #2152
Conversation
7977925 to
2ea00b6
Compare
2bc09ca to
f69ccfb
Compare
|
/preview |
|
Preview email sent as pull.2152.git.1781800932.gitgitgadget@gmail.com |
|
/submit |
|
Submitted as pull.2152.git.1781806593.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
43bc512 to
ee53c92
Compare
|
There is an issue in commit 72a86b9:
|
8c40fed to
2f123c5
Compare
|
There was a status update in the "Cooking" section about the branch The 'git log -L<range>:<path>' command has been taught to limit various 'diff' operations, such as '--stat', '--check', and '-G', to the specified range and path. Needs review. source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com> |
diff's line-range filtering logic uses the line_range_callback struct to represent filtering state. However, this name does not clearly reflect the role it plays. This is especially relevant as we expand diff's line-range filtering to work with more options, including --stat and -G. Also, line_range_callback's fields are terse, while the comment explaining line_range_callback is verbose and out of place compared to its surroundings. Rename line_range_callback to line_range_filter, and replace the verbose comment with a concise one, instead preferring descriptive field and variable names that are self-explanatory over comments. No logical behavior change. Some fields are grouped under a new struct in the newly renamed line_range_filter. Everything else is just a rename. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Currently, the diff line-range filter buffers preimage removal lines until a postimage line arrives. That line's number confirms whether the preimage line falls in a relevant range. However, storing preimage lines in a separate buffer is unnecessary. Worse, the logic has a bug: a preimage line outside the target range is included when it immediately follows an in-range postimage line. Preimage lines will always precede their postimage counterpart both in content line number and emission order from xdiff's line callback function. So preimage lines can share the postimage buffer. The filter flushes them based on whether the postimage lines fall within the target range. Remove logic related to storing preimage lines in a separate "removal" buffer and prepending them to the accumulating_hunk's line buffer. Instead, store those lines in the accumulating_hunk's line_buffer immediately and flush everything as appropriate based on postimage line numbers that arrive. This resolves the bug by construction. Also, calculate the old and new line counts for the diff hunk header when flushing rather than storing counters in line_range_filter to simplify state management further. Add a test to t/t4211-line-log.sh that verifies the preimage line emission bug is fixed. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Currently, diff's line-range filter implements its own method for emitting diff hunk headers. This mostly matches what xdiff itself outputs, but there is a discrepancy for postimage or preimage sides with 0 line changes. For a side with no lines (count 0), the begin is the line before the change. The header omits the line count of 1. Rather than fix this case in the line-range implementation, expose the function xdiff uses to emit its headers. Reusing it keeps the header format consistent with and without -L. Update test scenarios and fixtures to reflect the now consistent header format. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Extract logic for initializing the line-range filter and running a diff for a specific line range. This logic is needed for any diff that targets a line range independent of the current patch display path. The subsequent commits use this logic to enable additional line range targeted diff modes. No logical behavior change. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Reuse the line_range_filter in builtin_diffstat() so -L supports
the stat formats and add tests verifying the new behavior.
Ungate the newly enabled options and drop "yet" from the generic
-L rejection message ("does not yet support the requested diff
format"). Some rejected formats do not fit -L at all, so "yet"
wrongly implies they are all awaiting support.
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Reuse the line_range_filter in builtin_checkdiff() so -L supports the --check option. Add orig_hunk_fn field similar to orig_line_fn that forwards xdiff_emit_hunk_fn calls when we flush filtered hunks. This is necessary because --check relies on receiving calls to its checkdiff_consume_hunk function for managing state. Document and ungate the newly enabled option, and add tests verifying the new behavior. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Teach -G to only search the line ranges specified by -L. Teaching -S is left as future work, so it still matches the entire file even if -L is specified. Rather than being part of diff.c's builtin implementations, the diffcore-pickaxe functionality interacts with xdiff-interface as a separate component. Add a sibling to xdi_diff_outf(), called diff_emit_line_ranges(), that limits emitted lines to the given line ranges. Use diff_emit_line_ranges() when searching text if line ranges have been specified. If textconv is enabled, use normal diffing instead of diff_emit_line_ranges() since line range tracking relies on the line coordinates of the original, pre-textconv file. Update documentation and add tests accordingly. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
2f123c5 to
cff5c12
Compare
|
/preview |
|
Preview email sent as pull.2152.v3.git.1788411011.gitgitgadget@gmail.com |
|
/submit |
|
Submitted as pull.2152.v3.git.1788411919.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
Teach -L to work with the --stat family of options and --check. Also,
teach -G to search within the line ranges specified by -L. This series
continues the previous work[1][2] extending -L to work with more diff
options, and, for example, enables:
Reviewing the --stat history of a single function:
Finding where a pattern changed inside one function with -G, while
ignoring matches elsewhere in the file:
The first 4 commits are preparatory cleanup for the main feature
changes and could potentially be separated. The last 3 commits
implement the new features.
Patches:
reflect its role as a general filter for other diff features. Also,
replace verbose comments with descriptive field and variable names.
header format for all cases by exposing xdiff's header generating
function.
can reuse it.
Changes since v2:
verbosity and extraneous detail that makes the series hard to reason
about. Replace block comments with descriptive field and variable
names.
[1] https://lore.kernel.org/git/pull.2094.v3.git.1780001267.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/pull.2099.git.1777230630020.gitgitgadget@gmail.com/
Cc: "D. Ben Knoble" ben.knoble@gmail.com