git show

built-in
0.0% Savings
0 Commands
0 Tokens saved
4 Tests

Install

tokf install daabbac52c4f74f651af5b07db2ae9a46f53604c48d72b25b6a175994b146380
Safety checks passed

Filter definition

# git-show.toml — reduce a full commit patch to metadata + per-file counts
#
# Raw: commit metadata, message, and the full patch (often thousands of lines)
# Filtered: sha, author, date, subject, and one line per file with counts
#
# This filter used to `run = "git show --stat {args}"`, which destroyed the
# patch before tokf ever saw it — `tokf raw <id>` could not give it back
# (issue #430). The reduction now happens here, over the real output.

command = "git show"
description = "Summarise a commit as metadata plus per-file change counts"

# Skip the filter when the user explicitly asks for patch content or a
# different output shape than this reduction produces.
passthrough_args = [
  "-p",
  "--patch",
  "--stat",        # git's own stat rendering
  "--numstat",
  "--shortstat",
  "--format",
  "--pretty",
  "--raw",
]

# Anchored to column 0: patch content and commit messages can both mention
# "fatal:", and a substring match would collapse a legitimate commit to a
# single error line. Only git's own errors start at column 0.
match_output = [
  { pattern = "(?m)^fatal: ", output = "✗ {line_containing}" },
]

[[section]]
name = "file-headers"
match = '^diff --git '
collect_as = "file_header_lines"

# NOTE: the counting sections, the per-file [[chunk]] and the totals
# aggregates below are duplicated in git/diff.toml. tokf filters have no
# include mechanism (config resolution is first-match-wins, by design),
# so this is copied on purpose — but it is logic, not boilerplate.
# Fix the sign-prefix patterns in both files or neither.
# Whole-output counts for the totals line.
#
# These are stateful on purpose: they only collect inside a hunk body (between
# an `@@` header and the next file's `diff --git`). That matters because
# `git show <rev>:<path>` prints a *file*, not a diff — and a markdown file
# full of `- bullet` lines would otherwise be counted as deletions, replacing
# the file's contents with a fabricated "0 files changed, N deletions".
# With nothing collected, the filter falls through and prints the file as-is.
#
# The patterns exclude the `+++ b/…` / `--- a/…` headers — and nothing else.
# An earlier, simpler `^\+([^+]|$)` also swallowed every content line whose own
# first character was `+` or `-` (markdown bullets, YAML list items, `--flag`
# in a script), silently undercounting very ordinary diffs. Read them as
# "starts with the sign, but is not the literal `+++ `/`--- ` header"; the
# alternation spells out the 1-, 2- and 3-character cases because Rust's regex
# crate has no lookahead.
[[section]]
name = "added"
enter = '^@@ '
exit = '^diff --git '
match = '^\+([^+]|$|\+([^+]|$)|\+\+[^ ])'
collect_as = "added_lines"

[[section]]
name = "removed"
enter = '^@@ '
exit = '^diff --git '
match = '^-([^-]|$|-([^-]|$)|--[^ ])'
collect_as = "removed_lines"

# Commit metadata. `body_extract` keeps the first match per rule, which is what
# reduces a multi-paragraph commit message to its subject line.
[[chunk]]
split_on = '^commit [0-9a-f]{7,}'
collect_as = "commit"

[chunk.extract]
pattern = '^commit ([0-9a-f]{7})'
as = "sha"

[[chunk.body_extract]]
pattern = '^Author: (.*)$'
as = "author"

[[chunk.body_extract]]
pattern = '^Date:   (.*)$'
as = "date"

[[chunk.body_extract]]
pattern = '^    (\S.*)$'
as = "subject"

# One chunk per file, counting its own added/removed lines.
[[chunk]]
split_on = '^diff --git '
collect_as = "files"

# Use the `b/` (destination) path so renames report where the file ended up.
[chunk.extract]
pattern = '^diff --git a/.* b/(.*)$'
as = "path"

[[chunk.aggregate]]
pattern = '^\+([^+]|$|\+([^+]|$)|\+\+[^ ])'
count_as = "added"

[[chunk.aggregate]]
pattern = '^-([^-]|$|-([^-]|$)|--[^ ])'
count_as = "removed"

[on_success]
output = """{commit | each: "{sha} {subject}\n{author} · {date}" | join: "\n"}

{files | each: "{path} | +{added} -{removed}" | join: "\n"}
{file_count} files changed, {insertions} insertions(+), {deletions} deletions(-)"""

[[on_success.aggregates]]
from = "file_header_lines"
pattern = '^diff --git '
count_as = "file_count"

[[on_success.aggregates]]
from = "added_lines"
pattern = '^\+'
count_as = "insertions"

[[on_success.aggregates]]
from = "removed_lines"
pattern = '^-'
count_as = "deletions"

[on_failure]
tail = 5

Examples

git show <rev>:<path> prints the file, not a fabricated diffstat ~8 tokens → ~8 tokens
Raw output
# Notes

- alpha
- beta
- gamma
Filtered output
# Notes

- alpha
- beta
- gamma
bad revision shows fatal error ~21 tokens → ~10 tokens (52% saved)
Raw output
fatal: bad object 'nonexistent'
fatal: the remote end hung up unexpectedly
Filtered output
✗ fatal: bad object 'nonexistent'
a merge commit with no patch is passed through, not reported as empty ~53 tokens → ~53 tokens
Raw output
commit 4c28872f4ba3f5f6b8a1c2d3e4f5061728394a5b
Merge: 1a2b3c4 5d6e7f8
Author: Ada Lovelace <ada@example.com>
Date:   Mon Jul 20 10:10:00 2026 +0200

    Merge branch 'feature' into main
Filtered output
commit 4c28872f4ba3f5f6b8a1c2d3e4f5061728394a5b
Merge: 1a2b3c4 5d6e7f8
Author: Ada Lovelace <ada@example.com>
Date:   Mon Jul 20 10:10:00 2026 +0200

    Merge branch 'feature' into main
full commit patch reduces to metadata plus per-file counts ~230 tokens → ~60 tokens (74% saved)
Raw output
commit 4c28872f4ba3f5f6b8a1c2d3e4f5061728394a5b
Author: Ada Lovelace <ada@example.com>
Date:   Mon Jul 20 10:10:00 2026 +0200

    feat(filter): add chunk-based reduction

    A longer explanation of the change spanning
    several lines of body text.

    Refs #430

diff --git a/src/filter/mod.rs b/src/filter/mod.rs
index c2f62a6..79d15bc 100644
--- a/src/filter/mod.rs
+++ b/src/filter/mod.rs
@@ -10,6 +10,9 @@ impl Engine {
     pub fn new() -> Self {
         Self::default()
     }
+
+    pub fn reduce(&self) -> String {
+        String::new()
+    }
 }
diff --git a/src/config.rs b/src/config.rs
index 49728a7..d2d8dfb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -3,5 +3,4 @@ pub struct Config {
     pub name: String,
-    pub unused: bool,
-    pub also_unused: bool,
+    pub used: bool,
 }
Filtered output
4c28872 feat(filter): add chunk-based reduction
Ada Lovelace <ada@example.com> · Mon Jul 20 10:10:00 2026 +0200

src/filter/mod.rs | +4 -0
src/config.rs | +1 -2
2 files changed, 5 insertions(+), 2 deletions(-)
Warning: Community filters are third-party code. Review the filter definition above before installing it in production environments.
Browse all filters