Tíquete #41355

空白文字しか含まない行を差分から除外したい

: 2021-01-28 17:34 Última Atualização: 2021-01-31 00:24

Relator:
(Anônimo)
Dono:
(Nenhum)
Estado:
Fechado
Componente:
(Nenhum)
Marcos:
(Nenhum)
Prioridade:
5 - Medium
Gravidade:
5 - Medium
Resolução:
Accepted
Arquivo:
Nenhum

Details

diffutils 2.9 以降で実装された

「空白無視、かつ空行無視が設定されているときは、半角スペースとタブしか含まない行を差分から除外」

(If -b or -w is also specified, -B now considers lines to be empty if they contain only white space.)

をWinMergeのソースにとりこんでみました。

diffutils 2.9 のソースをそのまま貼りつけはできなかったので、ver2.16.8-jp-11のソースと見比べながら書き換えた結果、下記のような感じになりました。

  • hunk 内に半角スペース・タブ・改行しかなければ差分扱いにしない
  • hunk 内に空白でない文字がある場合は、「空白文字しか含まない行」も含めて hunk 全体を差分とする (従来の動作に同じ)
  1. /* /Src/diffutils/src/util.c */
  2. int is_blank_line (char const *pch)
  3. {
  4. while ((*pch)!='\0')
  5. {
  6. if ((*pch)=='\n' || (*pch)=='\r')
  7. break;
  8. if ((*pch)!=' ' && (*pch)!='\t')
  9. return 0;
  10. pch++;
  11. }
  12. return 1;
  13. }
  14. void
  15. analyze_hunk (struct change *hunk,
  16. int *first0, int *last0,
  17. int *first1, int *last1,
  18. int *deletes, int *inserts, const struct file_data fd[])
  19. {
  20. int l0, l1, show_from, show_to;
  21. int i;
  22. int trivial = ignore_blank_lines_flag;
  23. struct change *next;
  24. show_from = show_to = 0;
  25. *first0 = hunk->line0;
  26. *first1 = hunk->line1;
  27. next = hunk;
  28. do
  29. {
  30. l0 = next->line0 + next->deleted - 1;
  31. l1 = next->line1 + next->inserted - 1;
  32. show_from += next->deleted;
  33. show_to += next->inserted;
  34. for (i = next->line0; i <= l0 && trivial; i++)
  35. {
  36. if (!ignore_blank_lines_flag)
  37. {
  38. trivial = 0;
  39. }
  40. else if (ignore_all_space_flag | ignore_space_change_flag)
  41. {
  42. if (is_blank_line(fd[0].linbuf[i]) == 0)
  43. trivial = 0;
  44. }
  45. else if (!iseolch(fd[0].linbuf[i][0]) && fd[0].linbuf[i][0] != 0)
  46. {
  47. trivial = 0;
  48. }
  49. }
  50. for (i = next->line1; i <= l1 && trivial; i++)
  51. {
  52. if (!ignore_blank_lines_flag)
  53. {
  54. trivial = 0;
  55. }
  56. else if (ignore_all_space_flag | ignore_space_change_flag)
  57. {
  58. if (is_blank_line(fd[1].linbuf[i]) == 0)
  59. trivial = 0;
  60. }
  61. else if (!iseolch(fd[1].linbuf[i][0]) && fd[1].linbuf[i][0] != 0)
  62. {
  63. trivial = 0;
  64. }
  65. }
  66. }
  67. while ((next = next->link) != NULL);
  68. *last0 = l0;
  69. *last1 = l1;
  70. /* If all inserted or deleted lines are ignorable,
  71. tell the caller to ignore this hunk. */
  72. if (trivial)
  73. show_from = show_to = 0;
  74. /* WinMerge editor needs to know if there were trivial changes though,
  75. so stash that off in the trivial field */
  76. if (trivial)
  77. hunk->trivial = 1;
  78. else
  79. hunk->trivial = 0;
  80. *deletes = show_from;
  81. *inserts = show_to;
  82. }

Ticket History (3/4 Histories)

2021-01-28 17:34 Updated by: None
  • New Ticket "空白文字しか含まない行を差分から除外したい" created
2021-01-28 23:52 Updated by: sdottaka
Comentário

ご連絡ありがとうございます。 月末のリリースには間に合いませんが、次々回のリリースで取り込めるか確認してみます。

2021-01-31 00:23 Updated by: sdottaka
Comentário

以下のcommit で取り込ませていただきました。ありがとうございます。

https://github.com/WinMerge/winmerge/commit/fcc7597b3b9494f4d952a1b171537d5dd6427a61

なお、is_blank_line() は、 行がNUL文字で終端すると仮定していますが、 行内にNUL文字が含まれてしまっていた場合に誤認識を避けるため、行の終端をポインタで渡すように変更しています。

2021-01-31 00:24 Updated by: sdottaka
  • Estado Update from Aberto to Fechado
  • Resolução Update from Nenhum to Accepted

Attachment File List

No attachments

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login