git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] ls-files.c: add --dedup option

From
胡哲宁 <adlternative@gmail.com>
Date
Jan 17, 2021, 03:49 UTC
Message-ID
<CAOLTT8QNhz4PrMhAt9y58n+-bEjeOE+xst8rzcg-x045Amw7iw@mail.gmail.com>
In-Reply-To
<CAPig+cQBi7jdq64==U630Ht1YDcH+9komLNv-hZMnEhQ1Q-V9A@mail.gmail.com>

Eric,Thanks! I have little confuse about I can use` test_when_finished "git switch master" `, but I can't use` test_when_finished "git switch -" `, why?

Eric Sunshine <sunshine@sunshineco.com> 于2021年1月16日周六 下午3:13写道:
Show 120 quoted lines
>
> On Thu, Jan 14, 2021 at 7:22 AM 阿德烈 via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > In order to provide users a better experience
> > when viewing information about files in the index
> > and the working tree, the `--dedup` option will suppress
> > some duplicate options under some conditions.
> > [...]
>
> I have a few very minor comments alongside Junio's review comments...
>
> > Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> > ---
> > diff --git a/t/t3012-ls-files-dedup.sh b/t/t3012-ls-files-dedup.sh
> > @@ -0,0 +1,54 @@
> > +test_description='git ls-files --dedup test.
> > +
> > +This test prepares the following in the cache:
> > +
> > +    a.txt       - a file(base)
> > +    a.txt      - a file(master)
> > +    a.txt       - a file(dev)
> > +    b.txt       - a file
> > +    delete.txt  - a file
> > +    expect1    - a file
> > +    expect2    - a file
> > +
> > +'
>
> This test script description is outdated now. Perhaps shorten it to:
>
>     test_description='ls-files dedup tests'
>
> Or, it might be suitable to simply add the new test to the existing
> t3004-ls-files-basic.sh instead.
>
> > +test_expect_success 'setup' '
> > +       > a.txt &&
> > +       > b.txt &&
> > +       > delete.txt &&
> > +       cat >expect1<<-\EOF &&
>
> Style nits: no space after redirection operator and a space before
> redirection operator:
>
>     >a.txt &&
>     >b.txt &&
>     >delete.txt &&
>     cat >expect1 <<-\EOF &&
>
> > +       cat >expect2<<-EOF &&
>
> Nit: missing the backslash (and wrong spacing):
>
>     cat >expect2 <<-\EOF &&
>
> > +       echo a>a.txt &&
> > +       echo b>b.txt &&
>
> Style:
>
>     echo a >a.txt &&
>     echo b >b.txt &&
>
> > +       echo delete >delete.txt &&
> > +       git add a.txt b.txt delete.txt &&
> > +       git commit -m master:2 &&
> > +       git checkout HEAD~ &&
> > +       git switch -c dev &&
>
> If someone adds a new test after this test, then that new test will
> run in the "dev" branch, which might be unexpected or undesirable. It
> often is a good idea to ensure that tests do certain types of cleanup
> to avoid breaking subsequent tests. Here, it would be a good idea to
> ensure that the test switches back to the original branch when it
> finishes (regardless of whether it finishes successfully or
> unsuccessfully).
>
>     git switch -c dev &&
>     test_when_finished "git switch master" &&
>
> Or you could use `git switch -` if you don't want to hard-code the
> name "master" in the test (since there has been effort lately to
> remove that name from tests.
>
> > +       echo change >a.txt &&
> > +       git add a.txt &&
> > +       git commit -m dev:1 &&
> > +       test_must_fail git merge master &&
> > +       git ls-files -t --dedup >actual1 &&
> > +       test_cmp expect1 actual1 &&
> > +       rm delete.txt &&
> > +       git ls-files -d -m -t --dedup >actual2 &&
> > +       test_cmp expect2 actual2
>
> We usually don't bother giving temporary files unique names like
> "actual1" and "actual2" unless those files must exist at the same
> time. This is because unique names like this may confuse readers into
> wondering if there is some hidden interdependency between the files.
> In this case, the files don't need to exist at the same time, so it
> may be better simply to use the names "actual" and "expect", like
> this:
>
>     ...other stuff...
>     cat >expect <<-\EOF &&
>     ...
>     EOF
>     git ls-files -t --dedup >actual &&
>     test_cmp expect actual &&
>     rm delete.txt &&
>     cat >expect <<-\EOF &&
>     ...
>     EOF
>     git ls-files -d -m -t --dedup >actual &&
>     test_cmp expect actual
>
> (It also has the benefit that the "expect" content is closer to the
> place where it is actually used, which may make it a bit easier for a
> person reading the test to understand what is supposed to be
> produced.)
Previous: Eric SunshineNext: Eric Sunshine
Message 14 of 65 in “builtin/ls-files.c:add git ls-file --dedup option”
  1. builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 6, 2021
  2. Eric SunshineJan 7, 2021
  3. Junio C HamanoJan 7, 2021
  4. 0/2 builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 8, 2021
  5. 1/2 builtin/ls-files.c:add git ls-file --dedup optionZheNing Hu via GitGitGadget, Jan 8, 2021
  6. 2/2 builtin:ls-files.c:add git ls-file --dedup optionZheNing Hu via GitGitGadget, Jan 8, 2021
  7. Eric SunshineJan 14, 2021
  8. 胡哲宁Jan 14, 2021
  9. ls-files.c: add --dedup option阿德烈 via GitGitGadget, Jan 14, 2021
  10. Junio C HamanoJan 15, 2021
  11. 胡哲宁Jan 17, 2021
  12. Junio C HamanoJan 17, 2021
  13. Eric SunshineJan 16, 2021
  14. 胡哲宁Jan 17, 2021
  15. Eric SunshineJan 17, 2021
  16. Junio C HamanoJan 17, 2021
  17. Eric SunshineJan 18, 2021
  18. 0/3 builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 17, 2021
  19. 1/3 ls_files.c: bugfix for --deleted and --modifiedZheNing Hu via GitGitGadget, Jan 17, 2021
  20. Junio C HamanoJan 17, 2021
  21. 2/3 ls_files.c: consolidate two for loops into oneZheNing Hu via GitGitGadget, Jan 17, 2021
  22. 3/3 ls-files: add --deduplicate optionZheNing Hu via GitGitGadget, Jan 17, 2021
  23. Junio C HamanoJan 17, 2021
  24. Junio C HamanoJan 17, 2021
  25. 胡哲宁Jan 18, 2021
  26. 胡哲宁Jan 18, 2021
  27. Junio C HamanoJan 18, 2021
  28. 胡哲宁Jan 19, 2021
  29. 0/3 builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 19, 2021
  30. 3/3 ls-files.c: add --deduplicate optionZheNing Hu via GitGitGadget, Jan 19, 2021
  31. Junio C HamanoJan 20, 2021
  32. 胡哲宁Jan 21, 2021
  33. Junio C HamanoJan 21, 2021
  34. 胡哲宁Jan 22, 2021
  35. Johannes SchindelinJan 22, 2021
  36. Junio C HamanoJan 22, 2021
  37. GitGitGadget and `next`, was Re: [PATCH v5 3/3] ls-files.c: add --deduplicate optionJohannes Schindelin, Mar 19, 2021
  38. Junio C HamanoMar 19, 2021
  39. 胡哲宁Jan 23, 2021
  40. ls-files.c: add --deduplicate optionZheNing Hu, Jan 22, 2021
  41. Junio C HamanoJan 22, 2021
  42. 胡哲宁Jan 23, 2021
  43. 2/3 ls_files.c: consolidate two for loops into oneZheNing Hu via GitGitGadget, Jan 19, 2021
  44. Junio C HamanoJan 20, 2021
  45. 胡哲宁Jan 21, 2021
  46. 1/3 ls_files.c: bugfix for --deleted and --modifiedZheNing Hu via GitGitGadget, Jan 19, 2021
  47. Junio C HamanoJan 20, 2021
  48. 胡哲宁Jan 21, 2021
  49. 0/3 builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 23, 2021
  50. 1/3 ls_files.c: bugfix for --deleted and --modifiedZheNing Hu via GitGitGadget, Jan 23, 2021
  51. Junio C HamanoJan 23, 2021
  52. 2/3 ls_files.c: consolidate two for loops into oneZheNing Hu via GitGitGadget, Jan 23, 2021
  53. Junio C HamanoJan 23, 2021
  54. 3/3 ls-files.c: add --deduplicate optionZheNing Hu via GitGitGadget, Jan 23, 2021
  55. Junio C HamanoJan 23, 2021
  56. 1/3 ls_files.c: bugfix for --deleted and --modifiedJunio C Hamano, Jan 23, 2021
  57. 2/3 ls_files.c: consolidate two for loops into oneJunio C Hamano, Jan 23, 2021
  58. 3/3 ls-files.c: add --deduplicate optionJunio C Hamano, Jan 23, 2021
  59. 0/3 builtin/ls-files.c:add git ls-file --dedup option阿德烈 via GitGitGadget, Jan 24, 2021
  60. 1/3 ls_files.c: bugfix for --deleted and --modifiedZheNing Hu via GitGitGadget, Jan 24, 2021
  61. Junio C HamanoJan 24, 2021
  62. 胡哲宁Jan 25, 2021
  63. Junio C HamanoJan 25, 2021
  64. 2/3 ls_files.c: consolidate two for loops into oneZheNing Hu via GitGitGadget, Jan 24, 2021
  65. 3/3 ls-files.c: add --deduplicate optionZheNing Hu via GitGitGadget, Jan 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.