{"thread":{"id":"2966","subject":"git-ls-files -o no recurse?","startedAt":"2006-01-04T18:51:32Z","lastAt":"2006-01-07T19:34:24Z","messageCount":9,"participants":["Darrin Thompson","Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"14166","messageId":"1136400692.5919.11.camel@localhost.localdomain","threadId":"2966","inReplyTo":null,"subject":"git-ls-files -o no recurse?","fromName":"Darrin Thompson","fromEmail":"darrint@progeny.com","sentAt":"2006-01-04T18:51:32Z","receivedAt":"2006-01-04T18:51:32Z","isPatch":false,"sender":{"key":"darrint@progeny.com","avatar":null},"body":"git-ls-files -o reports _all_ the unknown files it finds in a work area.\nSubversion and probably other systems \"simply ignore all the files \nand directories inside an unknown directory and just note the directory\nas unknown.\" (A quote from my porcelain's mailing list.)\n\nI'd like to make this friendly behavior the default in my porcelain.\nUnfortunately, getting the same result from a porcelain requires\nimplementing a non-trivial algorithm to discover common prefixes, worry\nabout performance on large projects, etc.\n\nWould it be hard to make git-ls-files optionally do this?\n\n--\nDarrin\n"},{"id":"14167","messageId":"Pine.LNX.4.64.0601041330550.3668@g5.osdl.org","threadId":"2966","inReplyTo":"1136400692.5919.11.camel@localhost.localdomain","subject":"Re: git-ls-files -o no recurse?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-04T21:31:25Z","receivedAt":"2006-01-04T21:31:25Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 4 Jan 2006, Darrin Thompson wrote:\n> \n> Would it be hard to make git-ls-files optionally do this?\n\nSomething like the appended may or may not be what you're looking for..\n\n\t\tLinus\n---\ndiff --git a/ls-files.c b/ls-files.c\nindex 5e9ac71..2e3e2e8 100644\n--- a/ls-files.c\n+++ b/ls-files.c\n@@ -19,6 +19,7 @@ static int show_stage = 0;\n static int show_unmerged = 0;\n static int show_modified = 0;\n static int show_killed = 0;\n+static int show_ignored_directories = 0;\n static int line_terminator = '\\n';\n \n static int prefix_len = 0, prefix_offset = 0;\n@@ -233,6 +234,19 @@ static void add_name(const char *pathnam\n \tdir[nr_dir++] = ent;\n }\n \n+static int dir_exists(const char *dirname, int len)\n+{\n+\tint pos = cache_name_pos(dirname, len);\n+\tif (pos >= 0)\n+\t\treturn 1;\n+\tpos = -pos-1;\n+\tif (pos >= active_nr)\n+\t\treturn 0;\n+\tif (strncmp(active_cache[pos]->name, dirname, len))\n+\t\treturn 0;\n+\treturn active_cache[pos]->name[len] == '/';\n+}\n+\n /*\n  * Read a directory tree. We currently ignore anything but\n  * directories, regular files and symlinks. That's because git\n@@ -280,6 +294,10 @@ static void read_directory(const char *p\n \t\t\t\t\tcontinue;\n \t\t\t\t/* fallthrough */\n \t\t\tcase DT_DIR:\n+\t\t\t\tif (show_ignored_directories) {\n+\t\t\t\t\tif (!dir_exists(fullname, baselen + len))\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t}\n \t\t\t\tmemcpy(fullname + baselen + len, \"/\", 2);\n \t\t\t\tread_directory(fullname, fullname,\n \t\t\t\t\t       baselen + len + 1);\n@@ -622,6 +640,10 @@ int main(int argc, const char **argv)\n \t\t\tshow_killed = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--directory\")) {\n+\t\t\tshow_ignored_directories = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"-u\") || !strcmp(arg, \"--unmerged\")) {\n \t\t\t/* There's no point in showing unmerged unless\n \t\t\t * you also show the stage information.\n"},{"id":"14195","messageId":"1136481352.5597.2.camel@localhost.localdomain","threadId":"2966","inReplyTo":"Pine.LNX.4.64.0601041330550.3668@g5.osdl.org","subject":"Re: git-ls-files -o no recurse?","fromName":"Darrin Thompson","fromEmail":"darrint@progeny.com","sentAt":"2006-01-05T17:15:52Z","receivedAt":"2006-01-05T17:15:52Z","isPatch":false,"sender":{"key":"darrint@progeny.com","avatar":null},"body":"On Wed, 2006-01-04 at 13:31 -0800, Linus Torvalds wrote:\n> \n> On Wed, 4 Jan 2006, Darrin Thompson wrote:\n> > \n> > Would it be hard to make git-ls-files optionally do this?\n> \n> Something like the appended may or may not be what you're looking for..\n> \n\nWorked great!\n\n> @@ -19,6 +19,7 @@ static int show_stage = 0;\n>  static int show_unmerged = 0;\n>  static int show_modified = 0;\n>  static int show_killed = 0;\n> +static int show_ignored_directories = 0;\n>  static int line_terminator = '\\n';\n\nDid you perhaps mean s/ignored/other/g ? I thought maybe you were being\nclever but I couldn't get it to do anything useful with -i, only -o.\n\n--\nDarrin\n"},{"id":"14196","messageId":"Pine.LNX.4.64.0601050926440.3169@g5.osdl.org","threadId":"2966","inReplyTo":"1136481352.5597.2.camel@localhost.localdomain","subject":"Re: git-ls-files -o no recurse?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-05T17:31:57Z","receivedAt":"2006-01-05T17:31:57Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 5 Jan 2006, Darrin Thompson wrote:\n> \n> Worked great!\n\nOk. You can bug Junio about it when he returns, maybe he thinks it's a \ngreat feature.\n\n> > +static int show_ignored_directories = 0;\n> \n> Did you perhaps mean s/ignored/other/g ? I thought maybe you were being\n> clever but I couldn't get it to do anything useful with -i, only -o.\n\nYeah. \n\n\t\tLinus\n"},{"id":"14210","messageId":"7vk6ddq8x2.fsf@assigned-by-dhcp.cox.net","threadId":"2966","inReplyTo":"Pine.LNX.4.64.0601041330550.3668@g5.osdl.org","subject":"Re: git-ls-files -o no recurse?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-06T22:38:17Z","receivedAt":"2006-01-06T22:38:17Z","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> On Wed, 4 Jan 2006, Darrin Thompson wrote:\n>> \n>> Would it be hard to make git-ls-files optionally do this?\n>\n> Something like the appended may or may not be what you're looking for..\n>\n> \t\tLinus\n\nNot to mention test scripts, I suspect that making this the\ndefault would break existing callers including the famous\n\"git-init-db && git-add .\" pattern.  The other commonplace use\nis git-status, which might benefit from this option.  If we are\ngoing to use it in git-status, we may want to give them trailing\nslashes to make them stand out, though.\n"},{"id":"14252","messageId":"1136658055.6141.1.camel@localhost.localdomain","threadId":"2966","inReplyTo":"7vk6ddq8x2.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-ls-files -o no recurse?","fromName":"Darrin Thompson","fromEmail":"darrint@progeny.com","sentAt":"2006-01-07T18:20:55Z","receivedAt":"2006-01-07T18:20:55Z","isPatch":false,"sender":{"key":"darrint@progeny.com","avatar":null},"body":"This adds a test a test for the --directory option to git-ls-files.\n\nIs '--directory' really what we want?\n\n t/t3003-ls-files-others-directory.sh |   38\n++++++++++++++++++++++++++++++++++\n 1 files changed, 38 insertions(+), 0 deletions(-)\n create mode 100644 t/t3003-ls-files-others-directory.sh\n\napplies-to: 5001806332081159b00c35291d6aea232ed7e909\nd484a8477d430a5fb2cefd2cf7008a5973d1fea5\ndiff --git a/t/t3003-ls-files-others-directory.sh\nb/t/t3003-ls-files-others-directory.sh\nnew file mode 100644\nindex 0000000..d1d3d86\n--- /dev/null\n+++ b/t/t3003-ls-files-others-directory.sh\n@@ -0,0 +1,38 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Darrin Thompson\n+# Based on an earlier test by Junio C Hamano\n+#\n+\n+test_description='git-ls-files test (--others --directory)\n+\n+This test runs git-ls-files --others --directory with the following on\n+the filesystem.\n+\n+    path0       - a file\n+    path1\t- a symlink\n+    path2/file2 - a file in a directory\n+\n+The --directory option should cause path2 to be in the listing, but\n+not path2/file2.\n+'\n+. ./test-lib.sh\n+\n+date >path0\n+ln -s xyzzy path1\n+mkdir path2\n+date >path2/file2\n+test_expect_success \\\n+    'git-ls-files --directory --others to show output.' \\\n+    'git-ls-files --directory --others >output'\n+cat >expected <<EOF\n+output\n+path0\n+path1\n+path2\n+EOF\n+\n+test_expect_success \\\n+    'git-ls-files --directory --others should not pick up dir\ncontents.' \\\n+    'diff output expected'\n+test_done\n---\n0.99.9i\n"},{"id":"14253","messageId":"1136658207.6141.4.camel@localhost.localdomain","threadId":"2966","inReplyTo":"7vk6ddq8x2.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-ls-files -o no recurse?","fromName":"Darrin Thompson","fromEmail":"darrint@progeny.com","sentAt":"2006-01-07T18:23:27Z","receivedAt":"2006-01-07T18:23:27Z","isPatch":false,"sender":{"key":"darrint@progeny.com","avatar":null},"body":"Here's a rejiggered version of the original Linus patch. The names have\nbeen changed a little.\n\nEnjoy.\n\nIt prevents git from recursing into \"other\" directories when used with\nthe -o option.\n\n---\n\n ls-files.c |   22 ++++++++++++++++++++++\n 1 files changed, 22 insertions(+), 0 deletions(-)\n\napplies-to: 4e7e791ecc24975530de1f2855cf5f17f112140b\n741ec8ad5b7f3717bb462c2becfd00974da7ec16\ndiff --git a/ls-files.c b/ls-files.c\nindex 5e9ac71..cba8ca1 100644\n--- a/ls-files.c\n+++ b/ls-files.c\n@@ -19,6 +19,7 @@ static int show_stage = 0;\n static int show_unmerged = 0;\n static int show_modified = 0;\n static int show_killed = 0;\n+static int show_other_directories = 0;\n static int line_terminator = '\\n';\n \n static int prefix_len = 0, prefix_offset = 0;\n@@ -233,6 +234,19 @@ static void add_name(const char *pathnam\n \tdir[nr_dir++] = ent;\n }\n \n+static int dir_exists(const char *dirname, int len)\n+{\n+\tint pos = cache_name_pos(dirname, len);\n+\tif (pos >= 0)\n+\t\treturn 1;\n+\tpos = -pos-1;\n+\tif (pos >= active_nr)\n+\t\treturn 0;\n+\tif (strncmp(active_cache[pos]->name, dirname, len))\n+\t\treturn 0;\n+\treturn active_cache[pos]->name[len] == '/';\n+}\n+\n /*\n  * Read a directory tree. We currently ignore anything but\n  * directories, regular files and symlinks. That's because git\n@@ -280,6 +294,10 @@ static void read_directory(const char *p\n \t\t\t\t\tcontinue;\n \t\t\t\t/* fallthrough */\n \t\t\tcase DT_DIR:\n+\t\t\t\tif (show_other_directories) {\n+\t\t\t\t\tif (!dir_exists(fullname, baselen + len))\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t}\n \t\t\t\tmemcpy(fullname + baselen + len, \"/\", 2);\n \t\t\t\tread_directory(fullname, fullname,\n \t\t\t\t\t       baselen + len + 1);\n@@ -622,6 +640,10 @@ int main(int argc, const char **argv)\n \t\t\tshow_killed = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--directory\")) {\n+\t\t\tshow_other_directories = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"-u\") || !strcmp(arg, \"--unmerged\")) {\n \t\t\t/* There's no point in showing unmerged unless\n \t\t\t * you also show the stage information.\n---\n0.99.9i\n"},{"id":"14256","messageId":"7vace7khbi.fsf@assigned-by-dhcp.cox.net","threadId":"2966","inReplyTo":"1136658207.6141.4.camel@localhost.localdomain","subject":"Re: git-ls-files -o no recurse?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-07T18:45:37Z","receivedAt":"2006-01-07T18:45:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Darrin Thompson <darrint@progeny.com> writes:\n\n> Here's a rejiggered version of the original Linus patch. The names have\n> been changed a little.\n>\n> Enjoy.\n>\n> It prevents git from recursing into \"other\" directories when used with\n> the -o option.\n\nLooks same to what I have in the proposed updates branch, so we\nare on the same page.  Thanks.\n\nI have been unsure about the name \"--directory\", like you said.\nThe most accurate one I thought of so far is:\n\n  --dont-recurse-into-directories-without-tracked-files\n\nbut it is way too long.  We cannot even say \"untracked\ndirectories\" (we do not track directories) to shorten it a bit.\n"},{"id":"14258","messageId":"Pine.LNX.4.64.0601071131570.3169@g5.osdl.org","threadId":"2966","inReplyTo":"7vace7khbi.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-ls-files -o no recurse?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-07T19:34:24Z","receivedAt":"2006-01-07T19:34:24Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 7 Jan 2006, Junio C Hamano wrote:\n> \n> I have been unsure about the name \"--directory\", like you said.\n\nWell, I didn't like \"--directory\" either, but couldn't come up with \nanything better. How about just \"--no-recurse\", which is not technically \naccurate (we always recurse into directories we know about), but might be \nmore understandable.\n\nThe reason I called it \"--directory\" was that it would talk about \ndirectories that it doesn't know about (as opposed to individual files it \ndoesn't know about). So \"--other --directory\" kind of makes sense if you \nread it that way (\"show files and directories we don't know about\").\n\nBut yeah, it's not a great name.\n\n\t\tLinus\n"}]}