{"thread":{"id":"16858","subject":"git rev-list with --name-status?","startedAt":"2008-12-24T22:53:00Z","lastAt":"2008-12-25T20:13:21Z","messageCount":5,"participants":["skillzero@gmail.com","Junio C Hamano","demerphq"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98654","messageId":"2729632a0812241453x4ae50362g4bcd3317e5be0429@mail.gmail.com","threadId":"16858","inReplyTo":null,"subject":"git rev-list with --name-status?","fromName":"","fromEmail":"skillzero@gmail.com","sentAt":"2008-12-24T22:53:00Z","receivedAt":"2008-12-24T22:53:00Z","isPatch":false,"sender":{"key":"skillzero@gmail.com","avatar":null},"body":"Is there a way to print the equivalent of --name-status with git\nrev-list? The post-receive script that comes with git for sending\ncomment emails does this to generate the commit log:\n\ngit rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n\tgit rev-list --pretty --stdin $oldrev..$newrev\n\nI'd like to also include the output of --name-status so the email\nshows which files were changed by each commit (rather than just a\nsummary at the end since our pushes sometimes have a lot of commits in\nthem).\n\ngit rev-list doesn't seem to support --name-status and git log doesn't\nseem to support --stdin. Is there a better way to do what I want?\n"},{"id":"98679","messageId":"7vhc4tc4y7.fsf@gitster.siamese.dyndns.org","threadId":"16858","inReplyTo":"2729632a0812241453x4ae50362g4bcd3317e5be0429@mail.gmail.com","subject":"Re: git rev-list with --name-status?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-25T03:24:32Z","receivedAt":"2008-12-25T03:24:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"skillzero@gmail.com writes:\n\n> I'd like to also include the output of --name-status so the email\n> shows which files were changed by each commit (rather than just a\n> summary at the end since our pushes sometimes have a lot of commits in\n> them).\n>\n> git rev-list doesn't seem to support --name-status and git log doesn't\n> seem to support --stdin. Is there a better way to do what I want?\n\nThe plumbing rev-list never runs diff internally.\n\nDepending on what you want, \"git log --stat\" or \"git log --name-only\" or\neven \"git log --name-status -B -C\" may serve you nicely.\n\n\"Depending on what you want\" is the key phrase that indicates that what\nyou are asking for would be most likely found in Porcelains, not plumbing.\n\nEven though there is not much reason to _avoid_ using \"log\" these days,\nyou could do your own scripting for whatever reason; perhaps you feel like\nit would be a more macho thing to do (which isn't), perhaps you want more\ncustomization than options supported by the stock \"log\" Porcelain gives\nyou.\n\nIn olden days, people scripted around plumbing, partly because the\nPorcelains were implemented that way, and partly because the choices the\nPorcelains back then gave you was limited than what we have now.  Your\nscript may look like this:\n\n    git-rev-list --parents $range |\n    while read commit parents\n    do\n            ... do whatever you want with them ...\n    done\n\nor\n\n    git-rev-list --pretty --parents $range |\n    perl -e '\n    \twhile (<>) {\n        \tif (/^commit /../^$/) {\n\t\t\tif (/^commit (\\S+)(.*)?/) {\n\t\t\t\t... we have a new commit; flush what\n                                ... you accumulated for the previous one.\n\t\t\t\t... and prepare for this commit.\n\t\t\t\t... $1 is the commit, $2 has parents you\n                                ... can further split\n                        }\n\t\t\t... do \"header\" things here ...\n                        next;\n                }\n                s/^    //;\n                ... do \"log\" things here ...\n\t}\n        ... flush what you accumulated for the last commit.\n    '                \n"},{"id":"98695","messageId":"9b18b3110812251024n1a824eedpa127309d48acf351@mail.gmail.com","threadId":"16858","inReplyTo":"2729632a0812241453x4ae50362g4bcd3317e5be0429@mail.gmail.com","subject":"Re: git rev-list with --name-status?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2008-12-25T18:24:34Z","receivedAt":"2008-12-25T18:24:34Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2008/12/24  <skillzero@gmail.com>:\n> Is there a way to print the equivalent of --name-status with git\n> rev-list? The post-receive script that comes with git for sending\n> comment emails does this to generate the commit log:\n>\n> git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n>        git rev-list --pretty --stdin $oldrev..$newrev\n>\n> I'd like to also include the output of --name-status so the email\n> shows which files were changed by each commit (rather than just a\n> summary at the end since our pushes sometimes have a lot of commits in\n> them).\n>\n> git rev-list doesn't seem to support --name-status and git log doesn't\n> seem to support --stdin. Is there a better way to do what I want?\n\nI wrote the following shell script function which you can add to your\npost-receive-mail script. Any git rev-list --pretty statements there\ncan have the --pretty removed and have their output redirected to\nthis, and you get what you want. An  existing function changed to use\nit follows. Theres probably prettier ways to do this, but hope it\nhelps. Id send a diff of the script as a whole except that its full of\nother likely irrelevent changes.\n\nYves\n\n# show_log_for_sha1s_on_std()\n#\n# take a list of sha1's on STDIN and print out their logs.\n#\n# if there are\n#\n# 0 commits output a notice saying there no changes in this update\n#\n# 1 commits - show the log only\n#\n# >1 commits - show log with --name-status output (list of files with\nM/D/A type tags\n# next to them for Modified Deleted and Added)\n#\n# This partly exists because we can't use --name-status with rev-list, and\n# because we cant use --stdin with git log (even tho the docs might say\n# otherwise in older gits). Although since we count SHA1's we can also do some\n# special stuff like dealing with the 0/1/N commits differently.\n\nshow_log_for_sha1s_on_stdin()\n{\n                perl -e'\n                        chomp(my @sha1= <>);\n                        if (!@sha1) {\n                                print \"No new revisions added by this update\\n\";\n                        }\n                        else {\n                            my $ns= @sha1 > 1 ? \" --name-status\" : \"\";\n                            for my $idx (0..$#sha1) {\n                                print $idx ? \"\\n\" :  \"\" ,\n                                      `git-log --pretty$ns -1 $sha1[$idx]`;\n                                }\n                        }\n                '\n}\n\ngenerate_create_branch_email()\n{\n        # This is a new branch and so oldrev is not valid\n        echo \"        at  $newrev ($newrev_type)\"\n        echo \"\"\n\n        echo $LOGBEGIN\n        # This shows all log entries that are not already covered by\n        # another ref - i.e. commits that are now accessible from this\n        # ref that were previously not accessible\n        # (see generate_update_branch_email for the explanation of this\n        # command)\n        git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n        git rev-list --stdin $newrev | show_log_for_sha1s_on_stdin\n        echo $LOGEND\n}\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"98698","messageId":"7vr63w84iy.fsf@gitster.siamese.dyndns.org","threadId":"16858","inReplyTo":"2729632a0812241453x4ae50362g4bcd3317e5be0429@mail.gmail.com","subject":"Re: git rev-list with --name-status?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-25T18:59:33Z","receivedAt":"2008-12-25T18:59:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"skillzero@gmail.com writes:\n\n> Is there a way to print the equivalent of --name-status with git\n> rev-list? The post-receive script that comes with git for sending\n> comment emails does this to generate the commit log:\n>\n> git rev-parse --not --branches | grep -v $(git rev-parse $refname) |\n> \tgit rev-list --pretty --stdin $oldrev..$newrev\n\nI should have noticed this earlier.\n\nYou seem to be referring to contrib/hooks/post-receive-email as \"The\nscript that comes with git\".  It does have customization possibility\nalready implemented and documented:\n\n    hooks.showrev\n       The shell command used to format each revision in the email, with\n       \"%s\" replaced with the commit id.  Defaults to \"git rev-list -1\n       --pretty %s\", displaying the commit id, author, date and log\n       message.  To list full patches separated by a blank line, you\n       could set this to \"git show -C %s; echo\".\n\nOne of my day-job repositories has:\n\n    [hooks]\n            mailinglist = some-secret-project@day-job-domain.com\n            emailprefix = \"[SOME-SECRET-PROJECT GIT] \"\n            showrev = \"git show --stat %s; echo\"\n\nI think you can use \"git show --name-status %s; echo\" instead, if you like\nthe --name-status output.\n"},{"id":"98699","messageId":"2729632a0812251213h1de24995v9ad0a0df4e6967f8@mail.gmail.com","threadId":"16858","inReplyTo":"7vr63w84iy.fsf@gitster.siamese.dyndns.org","subject":"Re: git rev-list with --name-status?","fromName":"","fromEmail":"skillzero@gmail.com","sentAt":"2008-12-25T20:13:21Z","receivedAt":"2008-12-25T20:13:21Z","isPatch":false,"sender":{"key":"skillzero@gmail.com","avatar":null},"body":"On Thu, Dec 25, 2008 at 10:59 AM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> You seem to be referring to contrib/hooks/post-receive-email as \"The\n> script that comes with git\".  It does have customization possibility\n> already implemented and documented:\n>\n>    hooks.showrev\n>       The shell command used to format each revision in the email, with\n>       \"%s\" replaced with the commit id.  Defaults to \"git rev-list -1\n>       --pretty %s\", displaying the commit id, author, date and log\n>       message.  To list full patches separated by a blank line, you\n>       could set this to \"git show -C %s; echo\".\n>\n> ...\n>\n> I think you can use \"git show --name-status %s; echo\" instead, if you like\n> the --name-status output.\n\nThanks, that's perfect. I was using an older version of\ncontrib/hooks/post-receive-email that didn't have hooks.showrev so I\ndidn't realize it already had support for what I wanted.\n"}]}