0002-grep-fix-builds-with-with-no-thread-support.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. From 2225e1ea20481a7c0da526891470abf9ece623e7 Mon Sep 17 00:00:00 2001
  2. From: Brandon Williams <bmwill@google.com>
  3. Date: Fri, 17 Mar 2017 11:41:55 -0700
  4. Subject: [PATCH] grep: fix builds with with no thread support
  5. Commit 0281e487fd91 ("grep: optionally recurse into submodules")
  6. added functions grep_submodule() and grep_submodule_launch() which
  7. use "struct work_item" which is defined only when thread support
  8. is available.
  9. The original implementation of grep_submodule() used the "struct
  10. work_item" in order to gain access to a strbuf to store its output which
  11. was to be printed at a later point in time. This differs from how both
  12. grep_file() and grep_sha1() handle their output. This patch eliminates
  13. the reliance on the "struct work_item" and instead opts to use the
  14. output function stored in the output field of the "struct grep_opt"
  15. object directly, making it behave similarly to both grep_file() and
  16. grep_sha1().
  17. Reported-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
  18. Signed-off-by: Brandon Williams <bmwill@google.com>
  19. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
  20. Signed-off-by: Junio C Hamano <gitster@pobox.com>
  21. Signed-off-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
  22. ---
  23. builtin/grep.c | 21 +++++++++------------
  24. 1 file changed, 9 insertions(+), 12 deletions(-)
  25. diff --git a/builtin/grep.c b/builtin/grep.c
  26. index 2c727ef..33561f2 100644
  27. --- a/builtin/grep.c
  28. +++ b/builtin/grep.c
  29. @@ -538,7 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
  30. int status, i;
  31. const char *end_of_base;
  32. const char *name;
  33. - struct work_item *w = opt->output_priv;
  34. + struct strbuf child_output = STRBUF_INIT;
  35. end_of_base = strchr(gs->name, ':');
  36. if (gs->identifier && end_of_base)
  37. @@ -593,14 +593,16 @@ static int grep_submodule_launch(struct grep_opt *opt,
  38. * child process. A '0' indicates a hit, a '1' indicates no hit and
  39. * anything else is an error.
  40. */
  41. - status = capture_command(&cp, &w->out, 0);
  42. + status = capture_command(&cp, &child_output, 0);
  43. if (status && (status != 1)) {
  44. /* flush the buffer */
  45. - write_or_die(1, w->out.buf, w->out.len);
  46. + write_or_die(1, child_output.buf, child_output.len);
  47. die("process for submodule '%s' failed with exit code: %d",
  48. gs->name, status);
  49. }
  50. + opt->output(opt, child_output.buf, child_output.len);
  51. + strbuf_release(&child_output);
  52. /* invert the return code to make a hit equal to 1 */
  53. return !status;
  54. }
  55. @@ -641,19 +643,14 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
  56. } else
  57. #endif
  58. {
  59. - struct work_item w;
  60. + struct grep_source gs;
  61. int hit;
  62. - grep_source_init(&w.source, GREP_SOURCE_SUBMODULE,
  63. + grep_source_init(&gs, GREP_SOURCE_SUBMODULE,
  64. filename, path, sha1);
  65. - strbuf_init(&w.out, 0);
  66. - opt->output_priv = &w;
  67. - hit = grep_submodule_launch(opt, &w.source);
  68. + hit = grep_submodule_launch(opt, &gs);
  69. - write_or_die(1, w.out.buf, w.out.len);
  70. -
  71. - grep_source_clear(&w.source);
  72. - strbuf_release(&w.out);
  73. + grep_source_clear(&gs);
  74. return hit;
  75. }
  76. }
  77. --
  78. 2.6.2