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 |
df83e62 to
43bc512
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. cf. <xmqq8q8bpl03.fsf@gitster.g> 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> |
|
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:
|
ee53c92 to
4db558b
Compare
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 extend diff's line-range filtering to work with more options, including --stat and -G. In the same way, line_range_callback's fields are terse and do not clearly name their role, while at the same time, the comment explaining line_range_callback is overly 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>
4db558b to
102a294
Compare
Currently, the diff line-range filter stores preimage removal lines in a buffer until a postimage line arrives whose line number can confirm if the preimage line is part of a relevant line range or not. However, storing preimage lines in a separate buffer is unnecessary. Worse than this, the logic has a bug causing a preimage line that is not part of the line range target to be included when it immediately follows a postimage line that is part of the target range. Preimage lines will always precede their postimage counterpart both in content line number and emission order from xdiff's line callback function. That means preimage lines can just be stored in the same buffer as postimage lines and flushed as appropriate depending on whether or not the postimage lines lie within the target line 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 aforementioned bug by construction. Also, simplify line_range_filter's state management by calculating the old and new line counts that should be emitted in the diff hunk header when flushing rather than storing counters in line_range_filter. Add a test to t/t4211-line-log.sh that verifies the aforementioned 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 when it comes to postimage or preimage sides with 0 line changes. For a side that has no lines (count 0) the begin is the line before the change, and it omits a line count of 1 from the header. Rather than fixing this case in line-range's implementation, expose the function xdiff uses for emitting its headers and use it instead to keep the emitted header format consistent both 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. This extracted logic is used in the subsequent commits that enable additional line range targeted diff modes. No logical behavior change. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
102a294 to
994bac9
Compare
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 just awaiting support.
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Reuse the line_range_filter in builtin_checkdiff() so -L supports the --check option. Document and ungate the newly enabled option, 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. Update documentation and add tests accordingly. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
994bac9 to
5f606e6
Compare
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 history of a single function with the --stat family,
counted over just that function's lines rather than the whole file:
Finding where a pattern changed inside one function with -G, ignoring
matches elsewhere in the file:
The first 3 commits are preparatory cleanup for the main feature
changes and could potentially be separated. The last 4 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.
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