git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH gitweb] Visually indicating patch size with horizontal bars

From
Junio C Hamano <junkio@cox.net>
Date
Oct 28, 2005, 09:31 UTC
Message-ID
<7v3bmmvvgx.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20051028005029.GA2654@pe.Belkin>
Chris Shoemaker <c.shoemaker@cox.net> writes:
> Ok, but that cache would live inside GIT_DIR an be shared with gitk,
> right?

It is up to gitk. If your cache file format is simple, concise and easy to access, then it might be useful for gitk to take advantage of it. Although I doubt many people would run gitk and gitweb on the same repository (usually the former is run on the private developer repository and the latter public one).

Caching the 'git-diff-tree -p | git-apply --numstat' output might be useful and compact enough. I often wonder if the commit page (i.e. gitweb?p=$repository;a=commit;h=$sha1) might be more useful if it had diffstat drawing on each blob line at the end of the page, and the output from the above pipe can be used for that.

I wonder how big that thing would become if we cache it for the whole history, using something simple and lightweight like berkeley db or dbm, 20-byte commit ID as the key (for now, ignoring merges, but we could use 40-byte commit-parent ID pair as the key) and a list of the number of insertions and deletions for affected paths as the value. If we can do it quickly enough, you could put the cache update in post-update hook, so that every time you push into the public repository the patch-size cache is updated for gitweb's use. This can be done by the repository owner, and gitweb can stay read-only consumer of the information.

Just in case people find this useful, here is a patch to implement git-apply --numstat.

    ------------
[PATCH] git-apply --numstat

The new option, --numstat, shows number of inserted and deleted lines for each path. It is similar to --stat output but is meant to be more machine friendly by giving number of added and deleted lines and unabbreviated paths.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
git diff
diff --git a/apply.c b/apply.c
index e5c0b7d..73dfd0c 100644
--- a/apply.c
+++ b/apply.c
@@ -13,18 +13,20 @@
 //  --check turns on checking that the working tree matches the
 //    files that are being modified, but doesn't apply the patch
 //  --stat does just a diffstat, and doesn't actually apply
+//  --numstat does numeric diffstat, and doesn't actually apply
 //  --index-info shows the old and new index info for paths if available.
 //
 static int check_index = 0;
 static int write_index = 0;
 static int diffstat = 0;
+static int numstat = 0;
 static int summary = 0;
 static int check = 0;
 static int apply = 1;
 static int show_index_info = 0;
 static int line_termination = '\n';
 static const char apply_usage[] =
-"git-apply [--stat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] <patch>...";
+"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] <patch>...";
 
 /*
  * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -1317,6 +1319,20 @@ static void stat_patch_list(struct patch
 	printf(" %d files changed, %d insertions(+), %d deletions(-)\n", files, adds, dels);
 }
 
+static void numstat_patch_list(struct patch *patch)
+{
+	for ( ; patch; patch = patch->next) { 
+		const char *name;
+		name = patch->old_name ? patch->old_name : patch->new_name;
+		printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
+		if (line_termination && quote_c_style(name, NULL, NULL, 0))
+			quote_c_style(name, NULL, stdout, 0);
+		else
+			fputs(name, stdout);
+		putchar('\n');
+	}
+}
+
 static void show_file_mode_name(const char *newdelete, unsigned int mode, const char *name)
 {
 	if (mode)
@@ -1650,6 +1666,9 @@ static int apply_patch(int fd)
 	if (diffstat)
 		stat_patch_list(list);
 
+	if (numstat)
+		numstat_patch_list(list);
+	
 	if (summary)
 		summary_patch_list(list);
 
@@ -1683,6 +1702,11 @@ int main(int argc, char **argv)
 			diffstat = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--numstat")) {
+			apply = 0;
+			numstat = 1;
+			continue;
+		}
 		if (!strcmp(arg, "--summary")) {
 			apply = 0;
 			summary = 1;
Previous: Andreas EricssonNext: Martin Langhoff
Message 9 of 27 in “Visually indicating patch size with horizontal bars”
  1. Visually indicating patch size with horizontal barsChris Shoemaker, Oct 27, 2005
  2. Junio C HamanoOct 27, 2005
  3. Chris ShoemakerOct 27, 2005
  4. Linus TorvaldsOct 28, 2005
  5. Chris ShoemakerOct 28, 2005
  6. Martin LanghoffOct 28, 2005
  7. H. Peter AnvinOct 28, 2005
  8. Andreas EricssonOct 28, 2005
  9. Junio C HamanoOct 28, 2005
  10. Martin LanghoffOct 28, 2005
  11. Linus TorvaldsOct 28, 2005
  12. Junio C HamanoOct 28, 2005
  13. Linus TorvaldsOct 28, 2005
  14. Kay SieversOct 28, 2005
  15. Chris ShoemakerOct 28, 2005
  16. Petr BaudisNov 1, 2005
  17. Martin LanghoffNov 1, 2005
  18. Petr BaudisNov 1, 2005
  19. Andreas EricssonNov 2, 2005
  20. Johannes SchindelinNov 2, 2005
  21. Andreas EricssonNov 2, 2005
  22. Johannes SchindelinNov 2, 2005
  23. Chris ShoemakerNov 2, 2005
  24. Kay SieversNov 2, 2005
  25. Petr BaudisDec 5, 2005
  26. Chris ShoemakerDec 5, 2005
  27. Josef WeidendorferOct 28, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.