Accidentally, I realized that diff3 has an option called --show-c-function, from diff(1):

-p, --show-c-function
show which C function each change is in

Which I might have seen before and I actually had seen the results, but never realized that. Anyway, I was actually looking for something1 else, an option to limit2 the amount of changes.

The option probably is too simple to care, I can’t seem to find any output example through the first page of search results. So, I created simple test files

diff -u 1.c 2.c diff -up 1.c 2.c
--- 1.c <SNIP TIMESTAMP>
+++ 2.c <SNIP TIMESTAMP>
@@ -4,5 +4,5 @@
 {
   //
   //
-  printf("Hello!\n");
+  printf("Hello World!\n");
 }
--- 1.c <SNIP TIMESTAMP>
+++ 2.c <SNIP TIMESTAMP>
@@ -4,5 +4,5 @@ int main(void)
 {
   //
   //
-  printf("Hello!\n");
+  printf("Hello World!\n");
 }

The function, int main(void) is shown in the range information.

Git3 seems to support such feature by default, I don’t need to supply any options, already showing which function the change is in:

$ git diff e3b44be^! lib/td.c | cat
diff --git a/lib/td.c b/lib/td.c
index b1c591d..27477fb 100644
--- a/lib/td.c
+++ b/lib/td.c
@@ -42,7 +42,7 @@ sprint_td(char *str, long long t, <SNIP>
   /* space between two components */
   bool need_space = false;

-  if (t == 0) {
+  if (t == 0 && !print_all_numbers) {
     sprintf(str, "0 seconds");
     return strlen(str);
   }

It also has a --function-context to show more than just the function name, from git-diff(1):

-W, --function-context
Show whole surrounding functions of changes.

As for Hg (Mercurial)3, --show-function is, from hg(1):

-p, --show-function
show which function each change is in

They both don’t specify the programming language in the option name as the c in Diff’s --show-c-function. I checked with a Python code:

$ hg diff -p -r 6f0a7d3..006e58c b.py
diff -r 6f0a7d39706e -r 006e58c1d4ef b.py
--- a/b.py      Mon Apr 08 18:11:07 2013 +0800
+++ b/b.py      Thu Jul 25 10:52:12 2013 +0800
@@ -321,8 +321,8 @@ def main():
       c = Checker()
       c.process(StringIO(post['content']))
       c.check()
-      c.print_report()
-      c.print_summary()
+      print
+      c.print_all()
       return

     if 'blog' not in post:

Hg can find the function name where the change is in, so does Git, but that might just be the regular expression can find the names, or there wouldn’t be a --show-function-line=RE option in Diff.

The functionality --show-c-function, which I actually have been using in Git, but I’ve never noticed, truly didn’t recall seeing those function names, even I always check Diffs before committing. So, this probably doesn’t mean much for me, but at least I’d remember there is a such thing.


[1]Got a repository that receives line changes of hundreds in about a month, which I don’t care to review before committing, but still need them in revisions, and if I diff’d it, I’d definitely regret.
[2]head -n # isn’t the solution and it does the job poorly, it doesn’t understand the diff output but simply cut the lines. What I am looking for is like Gentoo’s eix, if too many packages, it stops at configured amount of maximum displaying and tells the user, who decides to use EIX_LIMIT to show all.
[3](1, 2, 3) GNU Diff 3.3, Git 2.3.6, Hg 2.8.2.