{"thread":{"id":"3884","subject":"Tentative built-in \"git show\"","startedAt":"2006-04-15T19:09:56Z","lastAt":"2006-04-15T20:57:14Z","messageCount":3,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18708","messageId":"Pine.LNX.4.64.0604151203060.3701@g5.osdl.org","threadId":"3884","inReplyTo":null,"subject":"Tentative built-in \"git show\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-15T19:09:56Z","receivedAt":"2006-04-15T19:09:56Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis uses the \"--no-walk\" flag that I never actually implemented (but I'm \nsure I mentioned it) to make \"git show\" be essentially the same thing as \n\"git whatchanged --no-walk\".\n\nIt just refuses to add more interesting parents to the revision walking \nhistory, so you don't actually get any history, you just get the commit \nyou asked for.\n\nI was going to add \"--no-walk\" as a real argument flag to git-rev-list \ntoo, but I'm not sure anybody actually needs it. Although it might be \nuseful for porcelain, so I left the door open.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis is obviously against Junio's current \"next\" branch, which has the \nlog/whatchanged unification.\n\nThat special-case of\n\n\tif (!strcmp(av[0], \"show\"...\n\nis truly ugly, but it needs to happen after setup_revisions(), for all the \nsame reasons that I suggested it might be a good idea to split up \n\"init_revisions()\" out of setup_revisions().\n\ndiff --git a/git.c b/git.c\nindex 939a34c..c87accf 100644\n--- a/git.c\n+++ b/git.c\n@@ -363,6 +363,20 @@ static int cmd_whatchanged(int ac, const\n \treturn cmd_log_wc(ac, av, ep, &wcopt);\n }\n \n+static int cmd_show(int ac, const char **av, char **ep)\n+{\n+\tstruct whatchanged_opt wcopt;\n+\n+\tmemset(&wcopt, 0, sizeof(wcopt));\n+\twcopt.do_diff = 1;\n+\tinit_log_tree_opt(&wcopt.logopt);\n+\twcopt.logopt.ignore_merges = 0;\n+\twcopt.logopt.combine_merges = 1;\n+\twcopt.logopt.dense_combined_merges = 1;\n+\twcopt.logopt.diffopt.recursive = 1;\n+\treturn cmd_log_wc(ac, av, ep, &wcopt);\n+}\n+\n static void handle_internal_command(int argc, const char **argv, char **envp)\n {\n \tconst char *cmd = argv[0];\n@@ -373,6 +387,7 @@ static void handle_internal_command(int \n \t\t{ \"version\", cmd_version },\n \t\t{ \"help\", cmd_help },\n \t\t{ \"log\", cmd_log },\n+\t\t{ \"show\", cmd_show },\n \t\t{ \"whatchanged\", cmd_whatchanged },\n \t};\n \tint i;\ndiff --git a/log-tree.c b/log-tree.c\nindex cb0d0b1..17e976a 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -182,6 +182,8 @@ int parse_whatchanged_opt(int ac, const \n \tint left = 1;\n \n \tac = setup_revisions(ac, av, rev, \"HEAD\");\n+\tif (!strcmp(av[0], \"show\"))\n+\t\trev->no_walk = 1;\n \twhile (1 < ac) {\n \t\tconst char *arg = av[1];\n \t\tif (!strncmp(arg, \"--pretty\", 8)) {\ndiff --git a/log-tree.h b/log-tree.h\ndiff --git a/revision.c b/revision.c\nindex 0505f3f..0c3c392 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -375,6 +375,9 @@ static void add_parents_to_list(struct r\n \tif (revs->prune_fn)\n \t\trevs->prune_fn(revs, commit);\n \n+\tif (revs->no_walk)\n+\t\treturn;\n+\n \tparent = commit->parents;\n \twhile (parent) {\n \t\tstruct commit *p = parent->item;\n@@ -714,6 +717,8 @@ int setup_revisions(int argc, const char\n \n void prepare_revision_walk(struct rev_info *revs)\n {\n+\tif (revs->no_walk)\n+\t\treturn;\n \tsort_by_date(&revs->commits);\n \tif (revs->limited)\n \t\tlimit_list(revs);\ndiff --git a/revision.h b/revision.h\nindex 8970b57..ff2a13e 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -26,6 +26,7 @@ struct rev_info {\n \t/* Traversal flags */\n \tunsigned int\tdense:1,\n \t\t\tno_merges:1,\n+\t\t\tno_walk:1,\n \t\t\tremove_empty_trees:1,\n \t\t\tlifo:1,\n \t\t\ttopo_order:1,\n"},{"id":"18711","messageId":"7v3bgefxkp.fsf@assigned-by-dhcp.cox.net","threadId":"3884","inReplyTo":"Pine.LNX.4.64.0604151203060.3701@g5.osdl.org","subject":"Re: Tentative built-in \"git show\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-15T19:28:06Z","receivedAt":"2006-04-15T19:28:06Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> This uses the \"--no-walk\" flag that I never actually implemented (but I'm \n> sure I mentioned it) to make \"git show\" be essentially the same thing as \n> \"git whatchanged --no-walk\".\n\nI sometimes do \"git show -4\" myself, and wondered why defaulting\nto \"-n 1\"is insufficient, but if you do something like this to\ncheck the tip of each branch:\n\n\tgit show master next pu\n\nthis may make sense.\n\nOtherwise, it feels to me that (I haven't had caffeine nor\nnicotine yet, so I need to re-think this later) log, show and\nwhatchanged are the same program in disguise with different set\nof defaults.\n\n        log\t\t--pretty\n        show\t\t--pretty -n1 -p\n        whatchanged\t--pretty -r\n\n... which implies that some of them might become historical\ncuriosity and no real reason to teach about each of them in the\ntutorial.\n"},{"id":"18714","messageId":"Pine.LNX.4.64.0604151345050.3701@g5.osdl.org","threadId":"3884","inReplyTo":"7v3bgefxkp.fsf@assigned-by-dhcp.cox.net","subject":"Re: Tentative built-in \"git show\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-15T20:57:14Z","receivedAt":"2006-04-15T20:57:14Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 15 Apr 2006, Junio C Hamano wrote:\n> \n> I sometimes do \"git show -4\" myself, and wondered why defaulting\n> to \"-n 1\"is insufficient\n\nI detest -n1 for a variety of reasons, and giving multiple refs is just \none of them.\n\nThe reason I like \"--no-walk\" is that it's conceptually much stronger, and \nmore efficient. Remember how we tried to optimize \"-1\" (as used by gitweb) \nby adding magic special cases to get_revision()? And how they always ended\nup being problematic because of how they interact with all the other \noptions?\n\nSo we don't do it any more, and as a result, \"git-rev-list -1 HEAD\" will \nactually walk all the parents too.\n\nIn contrast, \"--no-walk\" just does exactly what you tell it: don't start \nwalking the parents. It's kind of equivalent to -1 with one argument, but \nin the presense of path limiting it actually does the RightThing(tm), \nunlike -1.\n\nTry this as a replacement for \"git show\":\n\n\tgit log -1 kernel/\n\tgit log --no-walk kernel/\n\non the current kernel source tree to see the difference. \"--no-walk\" gives \nthe right answer (for some definition of \"right\"). While -1 gives a \ntotally random answer that has nothing to do with the current HEAD (except \nthat it's _reachable_ from the current HEAD).\n\nSo I think \"-n 1\" is fundamentally incompatible with \"git show\". Git \n\"show\" is \"show _this_ commit\". While \"-1\" fundamentally means \"show the \n_first_ commit when you walk the tree\". Which is really really \nfundamentally different.\n\nIn contrast \"--no-walk\" tells you exactly what it is about. Don't walk the \ntree. Show _this_ commit.\n\n(Now, the reason I said 'for _some_ definition of \"right\"' is that the \nquestion about path limiting in the absense of commit walking is somewhat \nambiguous. The current \"git show\" shows the commit regardless. My \nsuggested patch will potentially prune the commit away, and if the \nspecified commit does not touch the path, no commit is shown at all. \nBoth make sense. While \"git-rev-list -1\" does _not_ make sense)\n\n\t\t\tLinus\n"}]}