{"thread":{"id":"43340","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","startedAt":"2006-12-14T10:31:05Z","lastAt":"2006-12-15T10:22:49Z","messageCount":9,"participants":["Johannes Schindelin","Junio C Hamano","Shawn Pearce","Jakub Narebski","Santi Béjar"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"297493","messageId":"Pine.LNX.4.63.0612141129320.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43340","inReplyTo":null,"subject":"[PATCH] git-show: grok blobs, trees and tags, too","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-14T10:31:05Z","receivedAt":"2006-12-14T10:31:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSince git-show is pure Porcelain, it is the ideal candidate to\npretty print other things than commits, too.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n Documentation/git-show.txt |   40 ++++++++++++++++++---\n builtin-log.c              |   82 +++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 114 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-show.txt b/Documentation/git-show.txt\nindex 4c880a8..1d9d781 100644\n--- a/Documentation/git-show.txt\n+++ b/Documentation/git-show.txt\n@@ -3,20 +3,27 @@ git-show(1)\n \n NAME\n ----\n-git-show - Show one commit with difference it introduces\n+git-show - Show blobs, trees, tags and commits with difference they introduce\n \n \n SYNOPSIS\n --------\n-'git-show' <option>...\n+'git-show' [options] <object>...\n \n DESCRIPTION\n -----------\n-Shows commit log and textual diff for a single commit.  The\n-command internally invokes 'git-rev-list' piped to\n-'git-diff-tree', and takes command line options for both of\n-these commands. It also presents the merge commit in a special\n-format as produced by 'git-diff-tree --cc'.\n+Shows one or more objects.\n+\n+For commits it shows the log message and textual diff. It also\n+presents the merge commit in a special format as produced by\n+'git-diff-tree --cc'.\n+\n+For tags, it shows the tag message and the referenced objects.\n+\n+For trees, it shows the names (equivalent to gitlink:git-ls-tree[1]\n+with \\--name-only).\n+\n+For plain blobs, it shows the plain contents.\n \n This manual page describes only the most frequently used options.\n \n@@ -28,6 +35,25 @@ OPTIONS\n \n include::pretty-formats.txt[]\n \n+\n+EXAMPLES\n+--------\n+\n+git show v1.0.0::\n+\tShows the tag `v1.0.0`.\n+\n+git show v1.0.0^{tree}::\n+\tShows the tree pointed to by the tag `v1.0.0`.\n+\n+git show next~10:Documentation/README\n+\tShows the contents of the file `Documentation/README` as\n+\tthey were current in the 10th last commit of the branch\n+\t`next`.\n+\n+git show master:Makefile master:t/Makefile\n+\tConcatenates the contents of said Makefiles in the head\n+\tof the branch `master`.\n+\n Author\n ------\n Written by Linus Torvalds <torvalds@osdl.org> and\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 6821a08..17014f7 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -10,6 +10,7 @@\n #include \"revision.h\"\n #include \"log-tree.h\"\n #include \"builtin.h\"\n+#include \"tag.h\"\n #include <time.h>\n #include <sys/time.h>\n \n@@ -71,9 +72,43 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)\n \treturn cmd_log_walk(&rev);\n }\n \n+static int show_object(const unsigned char *sha1, int suppress_header)\n+{\n+\tunsigned long size;\n+\tchar type[20];\n+\tchar *buf = read_sha1_file(sha1, type, &size);\n+\tint offset = 0;\n+\n+\tif (!buf)\n+\t\treturn error(\"Could not read object %s\", sha1_to_hex(sha1));\n+\n+\tif (suppress_header)\n+\t\twhile (offset < size && buf[offset++] != '\\n') {\n+\t\t\tint new_offset = offset;\n+\t\t\twhile (new_offset < size && buf[new_offset++] != '\\n')\n+\t\t\t\t; /* do nothing */\n+\t\t\toffset = new_offset;\n+\t\t}\n+\n+\tif (offset < size)\n+\t\tfwrite(buf + offset, size - offset, 1, stdout);\n+\tfree(buf);\n+\treturn 0;\n+}\n+\n+static int show_tree_object(const unsigned char *sha1,\n+\t\tconst char *base, int baselen,\n+\t\tconst char *pathname, unsigned mode, int stage)\n+{\n+\tprintf(\"%s%s\\n\", pathname, S_ISDIR(mode) ? \"/\" : \"\");\n+\treturn 0;\n+}\n+\n int cmd_show(int argc, const char **argv, const char *prefix)\n {\n \tstruct rev_info rev;\n+\tstruct object_array_entry *objects;\n+\tint i, count, ret = 0;\n \n \tgit_config(git_log_config);\n \tinit_revisions(&rev, prefix);\n@@ -85,7 +120,52 @@ int cmd_show(int argc, const char **argv, const char *prefix)\n \trev.ignore_merges = 0;\n \trev.no_walk = 1;\n \tcmd_log_init(argc, argv, prefix, &rev);\n-\treturn cmd_log_walk(&rev);\n+\n+\tcount = rev.pending.nr;\n+\tobjects = rev.pending.objects;\n+\tfor (i = 0; i < count && !ret; i++) {\n+\t\tstruct object *o = objects[i].item;\n+\t\tconst char *name = objects[i].name;\n+\t\tswitch (o->type) {\n+\t\tcase OBJ_BLOB:\n+\t\t\tret = show_object(o->sha1, 0);\n+\t\t\tbreak;\n+\t\tcase OBJ_TAG: {\n+\t\t\tstruct tag *t = (struct tag *)o;\n+\n+\t\t\tprintf(\"%stag %s%s\\n\\n\",\n+\t\t\t\t\tdiff_get_color(rev.diffopt.color_diff,\n+\t\t\t\t\t\tDIFF_COMMIT),\n+\t\t\t\t\tt->tag,\n+\t\t\t\t\tdiff_get_color(rev.diffopt.color_diff,\n+\t\t\t\t\t\tDIFF_RESET));\n+\t\t\tret = show_object(o->sha1, 1);\n+\t\t\tobjects[i].item = (struct object *)t->tagged;\n+\t\t\ti--;\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase OBJ_TREE:\n+\t\t\tprintf(\"%stree %s%s\\n\\n\",\n+\t\t\t\t\tdiff_get_color(rev.diffopt.color_diff,\n+\t\t\t\t\t\tDIFF_COMMIT),\n+\t\t\t\t\tname,\n+\t\t\t\t\tdiff_get_color(rev.diffopt.color_diff,\n+\t\t\t\t\t\tDIFF_RESET));\n+\t\t\tread_tree_recursive((struct tree *)o, \"\", 0, 0, NULL,\n+\t\t\t\t\tshow_tree_object);\n+\t\t\tbreak;\n+\t\tcase OBJ_COMMIT:\n+\t\t\trev.pending.nr = rev.pending.alloc = 0;\n+\t\t\trev.pending.objects = NULL;\n+\t\t\tadd_object_array(o, name, &rev.pending);\n+\t\t\tret = cmd_log_walk(&rev);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tret = error(\"Unknown type: %d\", o->type);\n+\t\t}\n+\t}\n+\tfree(objects);\n+\treturn ret;\n }\n \n"},{"id":"296815","messageId":"20061214103741.GD1747@spearce.org","threadId":"43340","inReplyTo":"Pine.LNX.4.63.0612141129320.3635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-14T10:37:41Z","receivedAt":"2006-12-14T10:37:41Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>..\n\nNice!  I like this.\n\n> +git show master:Makefile master:t/Makefile\n> +\tConcatenates the contents of said Makefiles in the head\n> +\tof the branch `master`.\n> +\n\nUh, isn't that what cat does?  Shouldn't this be \"git cat\"?  :-)\n\nNevermind.  :)\n\n-- \n"},{"id":"298572","messageId":"Pine.LNX.4.63.0612141146410.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43340","inReplyTo":"20061214103741.GD1747@spearce.org","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-14T10:47:07Z","receivedAt":"2006-12-14T10:47:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 14 Dec 2006, Shawn Pearce wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> \n> > +git show master:Makefile master:t/Makefile\n> > +\tConcatenates the contents of said Makefiles in the head\n> > +\tof the branch `master`.\n> > +\n> \n> Uh, isn't that what cat does?  Shouldn't this be \"git cat\"?  :-)\n\nShhh! The dogs are sleeping!\n\nCiao,\nDscho\n"},{"id":"296239","messageId":"7v3b7i92ez.fsf@assigned-by-dhcp.cox.net","threadId":"43340","inReplyTo":"Pine.LNX.4.63.0612141129320.3635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-14T10:50:44Z","receivedAt":"2006-12-14T10:50:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> +\t\t\tret = show_object(o->sha1, 1);\n> +\t\t\tobjects[i].item = (struct object *)t->tagged;\n> +\t\t\ti--;\n> +\t\t\tbreak;\n\nGood hack ;-).\n"},{"id":"296017","messageId":"Pine.LNX.4.63.0612141156290.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43340","inReplyTo":"7v3b7i92ez.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-14T10:58:39Z","receivedAt":"2006-12-14T10:58:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 14 Dec 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > +\t\t\tret = show_object(o->sha1, 1);\n> > +\t\t\tobjects[i].item = (struct object *)t->tagged;\n> > +\t\t\ti--;\n> > +\t\t\tbreak;\n> \n> Good hack ;-).\n\nTail recursion ;-)\n\nIt has a nice side effect, too: the _name_ of the object is not changed, \nso if you show a tag which references a tree, you will see the name of the \ntag as if it were the name of the tree.\n\nCiao,\nDscho\n"},{"id":"297443","messageId":"eltng7$te5$2@sea.gmane.org","threadId":"43340","inReplyTo":"Pine.LNX.4.63.0612141129320.3635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-15T08:50:36Z","receivedAt":"2006-12-15T08:50:36Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Johannes Schindelin wrote:\n\n> +For tags, it shows the tag message and the referenced objects.\n[...]\n> +EXAMPLES\n> +--------\n> +\n> +git show v1.0.0::\n> +       Shows the tag `v1.0.0`.\n\nThis changes semantic. Before this patch \"git show v1.0.0\" showed\n_commit_, not a tag. Well, you can get commit using \"git show v1.0.0^{}\"...\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"298097","messageId":"8aa486160612150118y44744533t16af6d3086ac6b21@mail.gmail.com","threadId":"43340","inReplyTo":"Pine.LNX.4.63.0612141129320.3635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2006-12-15T09:18:58Z","receivedAt":"2006-12-15T09:18:58Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On 12/14/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> Since git-show is pure Porcelain, it is the ideal candidate to\n> pretty print other things than commits, too.\n\nI think \"git show ${tag}\" should be more like \"git show ${commit}\",\nthat is, with the tagger and date information and the indent, as:\n\n$ git show v1.4.4.2\ntag v1.4.4.2\nTagger: Junio C Hamano <junkio@cox.net>\nDate: ${Date}\n\n    GIT 1.4.4.2\n    -----BEGIN PGP SIGNATURE-----\n    Version: GnuPG v1.4.5 (GNU/Linux)\n\n    iD8DBQBFdx8+wMbZpPMRm5oRAsOXAJsGY8DIYey1TZlEXIGq5+8MNgEl1QCfQC0f\n    c5SmdLmAm2KPsCf+bCuoK+k=\n    =oDuA\n    -----END PGP SIGNATURE-----\ncommit 49ed2bc4660c7cd0592cf21cc514080574d06320\n...\n\n>\n> +EXAMPLES\n> +--------\n> +\n> +git show v1.0.0::\n> +       Shows the tag `v1.0.0`.\n\nand the commit (or object) it references.\n\nI would add:\n\ngit show v1.0.0^{}::\n      Shows only the commit referenced by the tag `v1.0.0`.\n\n\n"},{"id":"295432","messageId":"Pine.LNX.4.63.0612151121240.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43340","inReplyTo":"eltng7$te5$2@sea.gmane.org","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-15T10:22:01Z","receivedAt":"2006-12-15T10:22:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 15 Dec 2006, Jakub Narebski wrote:\n\n> Johannes Schindelin wrote:\n> \n> > +For tags, it shows the tag message and the referenced objects.\n> [...]\n> > +EXAMPLES\n> > +--------\n> > +\n> > +git show v1.0.0::\n> > +       Shows the tag `v1.0.0`.\n> \n> This changes semantic. Before this patch \"git show v1.0.0\" showed \n> _commit_, not a tag. Well, you can get commit using \"git show \n> v1.0.0^{}\"...\n\nAs Santi pointed out, this also shows the commit. Not only the tag.\n\nCiao,\nDscho\n"},{"id":"294411","messageId":"Pine.LNX.4.63.0612151122080.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43340","inReplyTo":"8aa486160612150118y44744533t16af6d3086ac6b21@mail.gmail.com","subject":"Re: [PATCH] git-show: grok blobs, trees and tags, too","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-15T10:22:49Z","receivedAt":"2006-12-15T10:22:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 15 Dec 2006, Santi Béjar wrote:\n\n> On 12/14/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > \n> > Since git-show is pure Porcelain, it is the ideal candidate to\n> > pretty print other things than commits, too.\n> \n> I think \"git show ${tag}\" should be more like \"git show ${commit}\",\n> that is, with the tagger and date information and the indent, as:\n> \n> $ git show v1.4.4.2\n> tag v1.4.4.2\n> Tagger: Junio C Hamano <junkio@cox.net>\n> Date: ${Date}\n> \n>    GIT 1.4.4.2\n>    -----BEGIN PGP SIGNATURE-----\n>    Version: GnuPG v1.4.5 (GNU/Linux)\n> \n>    iD8DBQBFdx8+wMbZpPMRm5oRAsOXAJsGY8DIYey1TZlEXIGq5+8MNgEl1QCfQC0f\n>    c5SmdLmAm2KPsCf+bCuoK+k=\n>    =oDuA\n>    -----END PGP SIGNATURE-----\n> commit 49ed2bc4660c7cd0592cf21cc514080574d06320\n> ...\n\nOkay. You code it?\n\n> > +EXAMPLES\n> > +--------\n> > +\n> > +git show v1.0.0::\n> > +       Shows the tag `v1.0.0`.\n> \n> and the commit (or object) it references.\n> \n> I would add:\n> \n> git show v1.0.0^{}::\n>      Shows only the commit referenced by the tag `v1.0.0`.\n\nOkay. You provide a patch?\n\nCiao,\nDscho\n"}]}