{"thread":{"id":"385","subject":"[PATCH] allow cg-log to display commit entries for particular files/directories","startedAt":"2005-04-29T03:27:02Z","lastAt":"2005-04-29T03:27:02Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2117","messageId":"Pine.LNX.4.62.0504282308200.14033@localhost.localdomain","threadId":"385","inReplyTo":null,"subject":"[PATCH] allow cg-log to display commit entries for particular files/directories","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2005-04-29T03:27:02Z","receivedAt":"2005-04-29T03:27:02Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"This patch allows for one or more paths to be specified with the effect \nof restricting the log to commits that affected those files or files \nunder given directories.\n\nThis is not perfect as some merge commits might or might not be listed.\nBut usually they're not really interesting in the context of this \nfeature.  It is otherwise pretty simple and effective until a better \ntool is available.\n\nFor example:\n\n\tcg-log arch/arm/kernel/\n\nwill show all commits that affected files under arch/arm/kernel/ \nstarting from the head branch.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n\n--- k/cg-log\n+++ l/cg-log\n@@ -14,6 +14,9 @@\n #\n # Takes an id resolving to a commit to start from (HEAD by default),\n # or id1:id2 representing an (id1;id2] range of commits to show.\n+#\n+# May also take one or more files and/or directories to reduce the\n+# log to commits modifying those files/directories only.\n \n . cg-Xlib\n \n@@ -33,14 +36,16 @@ else\n \tcoldefault=\n fi\n \n-if echo \"$1\" | grep -q ':'; then\n-\tid1=$(commit-id $(echo \"$1\" | cut -d : -f 1)) || exit 1\n-\tid2=$(commit-id $(echo \"$1\" | cut -d : -f 2)) || exit 1\n+id=\"$1\"; [ -a \"$1\" ] && id=\"\" || shift\n+\n+if echo \"$id\" | grep -q ':'; then\n+\tid1=$(commit-id $(echo \"$id\" | cut -d : -f 1)) || exit 1\n+\tid2=$(commit-id $(echo \"$id\" | cut -d : -f 2)) || exit 1\n \trevls=\"rev-tree $id2 ^$id1\"\n \trevsort=\"sort -rn\"\n \trevfmt=\"rev-tree\"\n else\n-\tid1=\"$(commit-id $1)\" || exit 1\n+\tid1=\"$(commit-id $id)\" || exit 1\n \trevls=\"rev-list $id1\" || exit 1\n \trevsort=\"cat\"\n \trevfmt=\"rev-list\"\n@@ -48,6 +53,10 @@ fi\n \n $revls | $revsort | while read time commit parents; do\n \t[ \"$revfmt\" = \"rev-list\" ] && commit=\"$time\"\n+\tif [ $# -ne 0 ]; then\n+\t\tparent=$(cat-file commit $commit | sed -n '2s/parent //p;2Q')\n+\t\t[ \"$parent\" ] && [ \"$(diff-tree -r $commit $parent \"$@\")\" ] || continue\n+\tfi\n \techo $colheader\"\"commit ${commit%:*} $coldefault;\n \tcat-file commit $commit | \\\n \t\twhile read key rest; do\n"}]}