{"thread":{"id":"7655","subject":"Fix some \"git ls-files -o\" fallout from gitlinks","startedAt":"2007-04-14T23:22:08Z","lastAt":"2007-04-14T23:22:08Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"39350","messageId":"Pine.LNX.4.64.0704141609170.5473@woody.linux-foundation.org","threadId":"7655","inReplyTo":null,"subject":"Fix some \"git ls-files -o\" fallout from gitlinks","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-04-14T23:22:08Z","receivedAt":"2007-04-14T23:22:08Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nSince \"git ls-files\" doesn't really pass down any details on what it \nreally wants done to the directory walking code, the directory walking \ncode doesn't really know whether the caller wants to know about gitlink \ndirectories, or whether it wants to just know about ignored files.\n\nSo the directory walking code will return those gitlink directories unless \nthe caller has explicitly told it not to (\"dir->show_other_directories\" \ntells the directory walker to only show \"other\" directories).\n\nThis kind of confuses \"git ls-files -o\", because\n - it didn't really expect to see entries listed that were already in the \n   index, unless they  were unmerged, and would die on that unexpected \n   setup, rather than just \"continue\".\n - it didn't know how to match directory entries with the final \"/\" \n\nThis trivial change updates the \"show_other_files()\" function to handle \nboth of these issues gracefully. There really was no reason to die, when \nthe obviously correct thing for the function was to just ignore files it \nalready knew about (that's what \"other\" means here!).\n\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n\nQuite frankly, I also debated just telling the directory reading functions \nexactly what we wanted, and we migth want to do that too (moving all the \n\"static int\" flags in builtin-ls-files.c to just be bitfield members of \nthe \"struct dir_struct\" instead). \n\nBut regardless of whether we'd like to extend and flesh out the \n\"read_directory()\" interface, this is definitely the right thing to do \n*anyway*.\n\n builtin-ls-files.c |   32 +++++++++++++++++++++++++-------\n 1 files changed, 25 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 74a6aca..f7c066b 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -89,20 +89,38 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)\n static void show_other_files(struct dir_struct *dir)\n {\n \tint i;\n+\n+\n+\t/*\n+\t * Skip matching and unmerged entries for the paths,\n+\t * since we want just \"others\".\n+\t *\n+\t * (Matching entries are normally pruned during\n+\t * the directory tree walk, but will show up for\n+\t * gitlinks because we don't necessarily have\n+\t * dir->show_other_directories set to suppress\n+\t * them).\n+\t */\n \tfor (i = 0; i < dir->nr; i++) {\n-\t\t/* We should not have a matching entry, but we\n-\t\t * may have an unmerged entry for this path.\n-\t\t */\n \t\tstruct dir_entry *ent = dir->entries[i];\n-\t\tint pos = cache_name_pos(ent->name, ent->len);\n+\t\tint len, pos;\n \t\tstruct cache_entry *ce;\n+\n+\t\t/*\n+\t\t * Remove the '/' at the end that directory\n+\t\t * walking adds for directory entries.\n+\t\t */\n+\t\tlen = ent->len;\n+\t\tif (len && ent->name[len-1] == '/')\n+\t\t\tlen--;\n+\t\tpos = cache_name_pos(ent->name, len);\n \t\tif (0 <= pos)\n-\t\t\tdie(\"bug in show-other-files\");\n+\t\t\tcontinue;\t/* exact match */\n \t\tpos = -pos - 1;\n \t\tif (pos < active_nr) { \n \t\t\tce = active_cache[pos];\n-\t\t\tif (ce_namelen(ce) == ent->len &&\n-\t\t\t    !memcmp(ce->name, ent->name, ent->len))\n+\t\t\tif (ce_namelen(ce) == len &&\n+\t\t\t    !memcmp(ce->name, ent->name, len))\n \t\t\t\tcontinue; /* Yup, this one exists unmerged */\n \t\t}\n \t\tshow_dir_entry(tag_other, ent);\n"}]}