{"thread":{"id":"20046","subject":"[RFC] Tree blame (git blame <directory>)","startedAt":"2009-07-07T08:58:38Z","lastAt":"2009-07-07T08:58:38Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"117546","messageId":"200907071058.39390.jnareb@gmail.com","threadId":"20046","inReplyTo":null,"subject":"[RFC] Tree blame (git blame <directory>)","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-07-07T08:58:38Z","receivedAt":"2009-07-07T08:58:38Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Currently git-blame supports only ordinary files (blobs).  If you try to \nuse git-blame on directory, it errors-out with a bit cryptic error \nmessage:\n\n  $ git blame Documentation\n  fatal: unsupported file type Documentation\n\nMeanwhile some git web interface (e.g. GitHub and Gitorious), most \nprobably following web interfaces for file-based VCS like ViewVC for \nCVS and Subversion, provide kind of \"tree blame\" view as default view \nfor directory contents.  It means that for each element (entry) in \ngiven directory it shows 'last changed' info, namely author, date and \nsummary of commit that changed given entry to current version.\n\nI don't know what algorithm they use to generate this info (well,\nI could find out in the case of Gitorious... if I read Ruby ;-)), \nbut I suspect that they might a bit inefficient algorithm to find such \ninfo.  Some time ago I tried to add such 'tree_blame' view to gitweb:\nyou can check the result in the 'gitweb/tree_blame' branch in my \ngit/jnareb-git.git repository at repo.or.cz:\n  http://repo.or.cz/w/git/jnareb-git.git?a=commitdiff;h=gitweb/tree_blame\n\n\nIt would be nice if \"git blame <directory>\" would give us required \ninformation; for tools such like GitHub, Gitorious or gitweb one could \nuse '--porcelain' or '--incremental' output.\n\nUnfortunately I don't know this part of code good enough to write it\neasily myself. I would think that it wouldn't be too hard to code it;\ncertainly easier than git-blame for ordinary files.\n\nI think that ordinary git-blame output for trees (directories) could\nmimic \"ls -l\" output format as far as possible, i.e. when currently\n  $ git ls-tree --abbrev v1.6.3.3\ngenerates the following output:\n  ...\n  100644 blob e57630e     walker.c\n  100644 blob 8a149e1     walker.h\n  100644 blob 7eb3218     wrapper.c\n  100644 blob 4c29255     write_or_die.c\n  100644 blob 819c797     ws.c\n  100644 blob 1b6df45     wt-status.c\n  100644 blob 78add09     wt-status.h\n  100644 blob b9b0db8     xdiff-interface.c\n  100644 blob 7352b9a     xdiff-interface.h\n  040000 tree ef5d413     xdiff\n\nthen\n  $ git blame --abbrev v1.6.3.3 -- .\nwould generate\n\n  100644 blob e57630e ba19a80 Junio C Hamano      Feb 10 17:42   walker.c\n  100644 blob 8a149e1 c13b263 Daniel Barkalow     Apr 26  2008   walker.h\n  100644 blob 7eb3218 fc71db3 Alex Riesen         Apr 29 23:21   wrapper.c\n  100644 blob 4c29255 559e840 Junio C Hamano      Jul 20  2008   write_or_die.c\n  100644 blob 819c797 a437900 Junio C Hamano      Jun 21 02:35   ws.c\n  100644 blob 1b6df45 2af202b Linus Torvalds      Jun 18 10:28   wt-status.c\n  100644 blob 78add09 6c2ce04 Marius Storm-Olsen  Jun  5  2008   wt-status.h\n  100644 blob b9b0db8 eb3a9dd Benjamin Kramer     Mar  7 21:02   xdiff-interface.c\n  100644 blob 7352b9a 86295bb Rene Scharfe        Oct 25  2008   xdiff-interface.h\n  040000 tree ef5d413 5719db9 Charles Bailey      May 25 01:21   xdiff/\n\nor something like that.  Date doesn't have to be in this strange format\nused by 'ls'.  Also instead of name we can use username part of email,\nor just email; OTOH git-blame uses above format for author.\n\nThe porcelain / incremental output format for \"git blame <directory>\"\nwouldn't need to be changed much from \"git blame <file>\"; line numbers\ndo not matter though, as what is important is SHA-1 of entry (blob, tree\nor commit).\n  $ git blame --porcelain v1.6.3.3 -- .\nThe blame output for last two lines could look like the following:\n  86295bb6bac1482d29650d1f77f19d8e7a7cc2fe 7352b9a9c204c2b1d4ca9df5ce040fe22d6f521c\n  author Rene Scharfe\n  author-mail <rene.scharfe@lsrfire.ath.cx>\n  author-time 1224941475\n  author-tz +0200\n  committer Junio C Hamano\n  committer-mail <gitster@pobox.com>\n  committer-time 1224961771\n  committer-tz -0700\n  summary add xdi_diff_hunks() for callers that only need hunk lengths\n  filename xdiff-interface.h\n  100644 blob 7352b9a9c204c2b1d4ca9df5ce040fe22d6f521c    xdiff-interface.h\n  5719db91ce5915ee07c50f1afdc94fe34e91529f ef5d413237b3a390007fba56671b00d7c371ae1e\n  author Charles Bailey\n  author-mail <charles@hashpling.org>\n  author-time 1243210874\n  author-tz +0100\n  committer Junio C Hamano\n  committer-mail <gitster@pobox.com>\n  committer-time 1243234594\n  committer-tz -0700\n  summary add xdi_diff_hunks() for callers that only need hunk lengths\n  filename xdiff\n  040000 tree ef5d413237b3a390007fba56671b00d7c371ae1e    xdiff\n\n\nWhat do you think about adding such feature?  \n\nIt either could use infrastructure for better '--follow' implementation,\nor lead to better implementation of '--follow' option (which currently\nas it is now works only for simplest cases).  Probably.\n\n-- \nJakub Narebski\nPoland\n"}]}