{"thread":{"id":"15783","subject":"How to list versioned files with modification status","startedAt":"2008-10-04T12:12:56Z","lastAt":"2008-10-05T09:04:12Z","messageCount":9,"participants":["Mark Burton","Alex Riesen","deskinm@umich.edu","Dmitry Potapov","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"92301","messageId":"20081004131256.586a5fbf@smartavionics.com","threadId":"15783","inReplyTo":null,"subject":"How to list versioned files with modification status","fromName":"Mark Burton","fromEmail":"markb@smartavionics.com","sentAt":"2008-10-04T12:12:56Z","receivedAt":"2008-10-04T12:12:56Z","isPatch":false,"sender":{"key":"markb@smartavionics.com","avatar":null},"body":"\nHi,\n\nI would like to be able to easily find those files in a git tree that\ndon't have pending modifications. Although ls-files can list the\nfiles that are modified, it can't list those that aren't or list all\nfiles with their modification status.\n\nThanks,\n\nMark\n\n-- \n\nSmart Avionics Ltd. -- producer of innovative avionics for homebuilt\naircraft.\n"},{"id":"92302","messageId":"81b0412b0810041440w131647aeo9c14f55cd38da635@mail.gmail.com","threadId":"15783","inReplyTo":"20081004131256.586a5fbf@smartavionics.com","subject":"Re: How to list versioned files with modification status","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-10-04T21:40:03Z","receivedAt":"2008-10-04T21:40:03Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"2008/10/4 Mark Burton <markb@smartavionics.com>:\n> I would like to be able to easily find those files in a git tree that\n> don't have pending modifications. Although ls-files can list the\n> files that are modified, it can't list those that aren't or list all\n> files with their modification status.\n\nMaybe if you look at git diff and diff-index,  you will find something\nwhat suits you better? Because \"modification\" is just a difference\nbetween a known (recorded in a commit or index) state and your\nworking tree.\n"},{"id":"92304","messageId":"loom.20081004T215458-15@post.gmane.org","threadId":"15783","inReplyTo":"81b0412b0810041440w131647aeo9c14f55cd38da635@mail.gmail.com","subject":"Re: How to list versioned files with modification status","fromName":"Mark Burton","fromEmail":"markb@ordern.com","sentAt":"2008-10-04T22:09:25Z","receivedAt":"2008-10-04T22:09:25Z","isPatch":false,"sender":{"key":"markb@ordern.com","avatar":null},"body":"Alex Riesen <raa.lkml <at> gmail.com> writes:\n\n> \n> 2008/10/4 Mark Burton <markb <at> smartavionics.com>:\n> > I would like to be able to easily find those files in a git tree that\n> > don't have pending modifications. Although ls-files can list the\n> > files that are modified, it can't list those that aren't or list all\n> > files with their modification status.\n> \n> Maybe if you look at git diff and diff-index,  you will find something\n> what suits you better? Because \"modification\" is just a difference\n> between a known (recorded in a commit or index) state and your\n> working tree.\n> \n\n'git diff --name-status' looks useful but it only shows the files that have\nchanged - I would like to see the names of the files that haven't changed. Even\nsvn could do that (svn status).\n\nThanks,\n\nMark\n"},{"id":"92305","messageId":"81b0412b0810041534o7b38507qe63db47cd07fdc16@mail.gmail.com","threadId":"15783","inReplyTo":"loom.20081004T215458-15@post.gmane.org","subject":"Re: How to list versioned files with modification status","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-10-04T22:34:31Z","receivedAt":"2008-10-04T22:34:31Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"2008/10/5 Mark Burton <markb@ordern.com>:\n> Alex Riesen <raa.lkml <at> gmail.com> writes:\n>> 2008/10/4 Mark Burton <markb <at> smartavionics.com>:\n>> > I would like to be able to easily find those files in a git tree that\n>> > don't have pending modifications. Although ls-files can list the\n>> > files that are modified, it can't list those that aren't or list all\n>> > files with their modification status.\n>>\n>> Maybe if you look at git diff and diff-index,  you will find something\n>> what suits you better? Because \"modification\" is just a difference\n>> between a known (recorded in a commit or index) state and your\n>> working tree.\n>\n> 'git diff --name-status' looks useful but it only shows the files that have\n> changed - I would like to see the names of the files that haven't changed.\n\nThere is nothing to do something like that, but...\n\n> Even svn could do that (svn status).\n\nwhat exactly are trying to achieve? It is just strange that no one\nasked for something like this before...\n"},{"id":"92307","messageId":"20081004225244.GD3052@riemann.deskinm.fdns.net","threadId":"15783","inReplyTo":"81b0412b0810041534o7b38507qe63db47cd07fdc16@mail.gmail.com","subject":"Re: How to list versioned files with modification status","fromName":"","fromEmail":"deskinm@umich.edu","sentAt":"2008-10-04T22:52:44Z","receivedAt":"2008-10-04T22:52:44Z","isPatch":false,"sender":{"key":"deskinm@umich.edu","avatar":"https://gravatar.com/avatar/d340a0e612cdf0a79535c71863c0b4c535e9aba63b42032226ae903e638b64f9?d=mp&s=160"},"body":"On Sun, Oct 05, 2008 at 12:34:31AM +0200, Alex Riesen wrote:\n> 2008/10/5 Mark Burton <markb@ordern.com>:\n> > Alex Riesen <raa.lkml <at> gmail.com> writes:\n> >> 2008/10/4 Mark Burton <markb <at> smartavionics.com>:\n> >> > I would like to be able to easily find those files in a git tree that\n> >> > don't have pending modifications. Although ls-files can list the\n> >> > files that are modified, it can't list those that aren't or list all\n> >> > files with their modification status.\n> >>\n> >> Maybe if you look at git diff and diff-index,  you will find something\n> >> what suits you better? Because \"modification\" is just a difference\n> >> between a known (recorded in a commit or index) state and your\n> >> working tree.\n> >\n> > 'git diff --name-status' looks useful but it only shows the files that have\n> > changed - I would like to see the names of the files that haven't changed.\n> \n> There is nothing to do something like that, but...\n> \n> > Even svn could do that (svn status).\n> \n> what exactly are trying to achieve? It is just strange that no one\n> asked for something like this before...\n\nApologies for the duplicate message; fighting between gmail and\nvger.kernel.org.\n\nHere's a terrible way to do this:\n\n$ GIT_EDITOR=: git commit -a -m 'throwaway' >/dev/null\n$ (git ls-tree -r HEAD; git ls-tree -r HEAD~1) \\\n| sort | uniq -d | sed -e 's/^[^ ]* [^ ]* [^\\t]*\\t//'\n$ git reset HEAD~1 >/dev/null\n\nDeskin Miller\n"},{"id":"92309","messageId":"loom.20081004T223639-341@post.gmane.org","threadId":"15783","inReplyTo":"81b0412b0810041534o7b38507qe63db47cd07fdc16@mail.gmail.com","subject":"Re: How to list versioned files with modification status","fromName":"Mark Burton","fromEmail":"markb@ordern.com","sentAt":"2008-10-04T23:02:59Z","receivedAt":"2008-10-04T23:02:59Z","isPatch":false,"sender":{"key":"markb@ordern.com","avatar":null},"body":"\n> > 'git diff --name-status' looks useful but it only shows the files that have\n> > changed - I would like to see the names of the files that haven't changed.\n> \n> There is nothing to do something like that, but...\n> \n> > Even svn could do that (svn status).\n> \n> what exactly are trying to achieve? It is just strange that no one\n> asked for something like this before...\n\nWhat I am trying to achieve is to list the versioned files that have no\npending modifications (didn't I say that in the original posting?)\n\nStrange, perhaps, but not completely useless in that it does tell you\nsomething about the state of the current working set of files.\n\nBTW - and sorry for posting the same question in two different emails, I\nthought the first one had not made it onto the list - I shall be more\npatient in the future.\n\nMark\n"},{"id":"92310","messageId":"20081004230922.GL21650@dpotapov.dyndns.org","threadId":"15783","inReplyTo":"20081004131256.586a5fbf@smartavionics.com","subject":"Re: How to list versioned files with modification status","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-10-04T23:09:22Z","receivedAt":"2008-10-04T23:09:22Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"On Sat, Oct 04, 2008 at 01:12:56PM +0100, Mark Burton wrote:\n> \n> I would like to be able to easily find those files in a git tree that\n> don't have pending modifications. Although ls-files can list the\n> files that are modified, it can't list those that aren't\n\nWell, it is a rather unusual task to have a special option devoted\nto it, and you always combine a few commands together like that:\n\ncomm -3 <(git ls-files|sort) <(git ls-files -m|sort)\n\nDmitry\n"},{"id":"92311","messageId":"alpine.LFD.2.00.0810041608150.3208@nehalem.linux-foundation.org","threadId":"15783","inReplyTo":"loom.20081004T215458-15@post.gmane.org","subject":"Re: How to list versioned files with modification status","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-10-04T23:10:17Z","receivedAt":"2008-10-04T23:10:17Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nOn Sat, 4 Oct 2008, Mark Burton wrote:\n>\n> 'git diff --name-status' looks useful but it only shows the files that have\n> changed - I would like to see the names of the files that haven't changed. Even\n> svn could do that (svn status).\n\nNobody has ever asked for such a crazy thing, but here's a test-patch to \nteach 'git ls-files' the '--unmodified' flag.\n\nIt's strictly bigger than need be, partly because ls-files is a horror, \npartly because it needed that 'name_status()' helper function to make it \nnot turn into something even worse.\n\nI also fixed a git ls-files buglet: a deleted file implies modification, \nso if you ask for --deleted _and_ --modified at the same time, you'll see \na deleted file listed twice. Use '-v' to see the type. This makes it \nonly show it once - as deleted if you asked for that information, \notherwise as modified.\n\nSo with something like this, you can do\n\n\tgit ls-files -v --modified --deleted --unmodified\n\nand you'll see all files with a tag in front (the tag for unmodified is \nempty).\n\nNot very well tested (aka \"Hey, it's a patch from Linus, caveat emptor!\")\n\n\t\tLinus\n\n---\n builtin-ls-files.c |   48 +++++++++++++++++++++++++++++++++++++++---------\n 1 files changed, 39 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 068f424..27a318a 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -18,6 +18,7 @@ static int show_others;\n static int show_stage;\n static int show_unmerged;\n static int show_modified;\n+static int show_unmodified;\n static int show_killed;\n static int show_valid_bit;\n static int line_terminator = '\\n';\n@@ -35,6 +36,7 @@ static const char *tag_removed = \"\";\n static const char *tag_other = \"\";\n static const char *tag_killed = \"\";\n static const char *tag_modified = \"\";\n+static const char *tag_unmodified = \"\";\n \n \n /*\n@@ -218,6 +220,20 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)\n \twrite_name_quoted(ce->name + offset, stdout, line_terminator);\n }\n \n+enum show_state {\n+\tunmodified, deleted, modified\n+};\n+\n+static enum show_state name_status(struct cache_entry *ce)\n+{\n+\tstruct stat st;\n+\tint err = lstat(ce->name, &st);\n+\n+\tif (err)\n+\t\treturn deleted;\n+\treturn ce_modified(ce, &st, 0) ? modified : unmodified;\n+}\n+\n static void show_files(struct dir_struct *dir, const char *prefix)\n {\n \tint i;\n@@ -248,19 +264,27 @@ static void show_files(struct dir_struct *dir, const char *prefix)\n \t\t\tshow_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);\n \t\t}\n \t}\n-\tif (show_deleted | show_modified) {\n+\tif (show_deleted | show_modified | show_unmodified) {\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tstruct cache_entry *ce = active_cache[i];\n-\t\t\tstruct stat st;\n-\t\t\tint err;\n \t\t\tint dtype = ce_to_dtype(ce);\n \t\t\tif (excluded(dir, ce->name, &dtype) != dir->show_ignored)\n \t\t\t\tcontinue;\n-\t\t\terr = lstat(ce->name, &st);\n-\t\t\tif (show_deleted && err)\n-\t\t\t\tshow_ce_entry(tag_removed, ce);\n-\t\t\tif (show_modified && ce_modified(ce, &st, 0))\n-\t\t\t\tshow_ce_entry(tag_modified, ce);\n+\t\t\tswitch (name_status(ce)) {\n+\t\t\tdefault:\n+\t\t\t\tif (show_unmodified)\n+\t\t\t\t\tshow_ce_entry(tag_unmodified, ce);\n+\t\t\t\tbreak;\n+\t\t\tcase deleted:\n+\t\t\t\tif (show_deleted) {\n+\t\t\t\t\tshow_ce_entry(tag_removed, ce);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\t/* Fall through */\n+\t\t\tcase modified:\n+\t\t\t\tif (show_modified)\n+\t\t\t\t\tshow_ce_entry(tag_modified, ce);\n+\t\t\t}\n \t\t}\n \t}\n }\n@@ -457,6 +481,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\ttag_modified = \"C \";\n \t\t\ttag_other = \"? \";\n \t\t\ttag_killed = \"K \";\n+\t\t\ttag_unmodified = \"  \";\n \t\t\tif (arg[1] == 'v')\n \t\t\t\tshow_valid_bit = 1;\n \t\t\tcontinue;\n@@ -474,6 +499,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\trequire_work_tree = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--unmodified\")) {\n+\t\t\tshow_unmodified = 1;\n+\t\t\trequire_work_tree = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"-o\") || !strcmp(arg, \"--others\")) {\n \t\t\tshow_others = 1;\n \t\t\trequire_work_tree = 1;\n@@ -593,7 +623,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \n \t/* With no flags, we default to showing the cached files */\n \tif (!(show_stage | show_deleted | show_others | show_unmerged |\n-\t      show_killed | show_modified))\n+\t      show_killed | show_modified | show_unmodified))\n \t\tshow_cached = 1;\n \n \tread_cache();\n"},{"id":"92324","messageId":"loom.20081005T090050-722@post.gmane.org","threadId":"15783","inReplyTo":"alpine.LFD.2.00.0810041608150.3208@nehalem.linux-foundation.org","subject":"Re: How to list versioned files with modification status","fromName":"Mark Burton","fromEmail":"markb@ordern.com","sentAt":"2008-10-05T09:04:12Z","receivedAt":"2008-10-05T09:04:12Z","isPatch":false,"sender":{"key":"markb@ordern.com","avatar":null},"body":"Linus Torvalds <torvalds <at> linux-foundation.org> writes:\n\n> Nobody has ever asked for such a crazy thing, but here's a test-patch to \n> teach 'git ls-files' the '--unmodified' flag.\n> \n> ...\n\nMany thanks for the patch, it does exactly what I wanted. Thanks also to the\nother people who contributed suggestions.\n\nMark\n"}]}