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

Re: [PATCH v8 3/3] bisect--helper: `write_terms` shell function in C

From
Christian Couder <christian.couder@gmail.com>
Date
May 24, 2016, 07:33 UTC
Message-ID
<CAP8UFD1WZ=5e9u5awrHDG-vhMR5dw5NNY_yVEkp2o0rgx59nnQ@mail.gmail.com>
In-Reply-To
<20160524072124.2945-4-pranit.bauva@gmail.com>
On Tue, May 24, 2016 at 9:21 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 104 quoted lines
> Reimplement the `write_terms` shell function in C and add a `write-terms`
> subcommand to `git bisect--helper` to call it from git-bisect.sh . Also
> remove the subcommand `--check-term-format` as it can now be called from
> inside the function write_terms() C implementation.
>
> Also `|| exit` is added when calling write-terms subcommand from
> git-bisect.sh so as to exit whenever there is an error.
>
> Using `--write-terms` subcommand is a temporary measure to port shell
> function to C so as to use the existing test suite. As more functions
> are ported, this subcommand will be retired and will be called by some
> other method.
>
> Mentored-by: Lars Schneider <larsxschneider@gmail.com>
> Mentored-by: Christian Couder <chriscool@tuxfamily.org>
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
>  builtin/bisect--helper.c | 36 +++++++++++++++++++++++++++++-------
>  git-bisect.sh            | 22 +++++++---------------
>  2 files changed, 36 insertions(+), 22 deletions(-)
>
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> index 3c748d1..91027b0 100644
> --- a/builtin/bisect--helper.c
> +++ b/builtin/bisect--helper.c
> @@ -4,9 +4,11 @@
>  #include "bisect.h"
>  #include "refs.h"
>
> +static GIT_PATH_FUNC(git_path_bisect_write_terms, "BISECT_TERMS")
> +
>  static const char * const git_bisect_helper_usage[] = {
>         N_("git bisect--helper --next-all [--no-checkout]"),
> -       N_("git bisect--helper --check-term-format <term> <orig_term>"),
> +       N_("git bisect--helper --write-terms <bad_term> <good_term>"),
>         NULL
>  };
>
> @@ -56,18 +58,38 @@ static int check_term_format(const char *term, const char *orig_term)
>         return 0;
>  }
>
> +static int write_terms(const char *bad, const char *good)
> +{
> +       FILE *fp;
> +       int res;
> +
> +       if (!strcmp(bad, good))
> +               return error(_("please use two different terms"));
> +
> +       if (check_term_format(bad, "bad") || check_term_format(good, "good"))
> +               return -1;
> +
> +       fp = fopen(git_path_bisect_write_terms(), "w");
> +       if (!fp)
> +               return error_errno(_("could not open the file BISECT_TERMS"));
> +
> +       res = fprintf(fp, "%s\n%s\n", bad, good);
> +       fclose(fp);
> +       return (res < 0) ? -1 : 0;
> +}
> +
>  int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
>  {
>         enum {
>                 NEXT_ALL = 1,
> -               CHECK_TERM_FMT
> +               WRITE_TERMS
>         } cmdmode = 0;
>         int no_checkout = 0;
>         struct option options[] = {
>                 OPT_CMDMODE(0, "next-all", &cmdmode,
>                          N_("perform 'git bisect next'"), NEXT_ALL),
> -               OPT_CMDMODE(0, "check-term-format", &cmdmode,
> -                        N_("check format of the term"), CHECK_TERM_FMT),
> +               OPT_CMDMODE(0, "write-terms", &cmdmode,
> +                        N_("write the terms to .git/BISECT_TERMS"), WRITE_TERMS),
>                 OPT_BOOL(0, "no-checkout", &no_checkout,
>                          N_("update BISECT_HEAD instead of checking out the current commit")),
>                 OPT_END()
> @@ -82,10 +104,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
>         switch (cmdmode) {
>         case NEXT_ALL:
>                 return bisect_next_all(prefix, no_checkout);
> -       case CHECK_TERM_FMT:
> +       case WRITE_TERMS:
>                 if (argc != 2)
> -                       die(_("--check-term-format requires two arguments"));
> -               return check_term_format(argv[0], argv[1]);
> +                       die(_("--write-terms requires two arguments"));
> +               return write_terms(argv[0], argv[1]);
>         default:
>                 die("BUG: unknown subcommand '%d'", cmdmode);
>         }
> diff --git a/git-bisect.sh b/git-bisect.sh
> index 7d7965d..cd39bd0 100755
> --- a/git-bisect.sh
> +++ b/git-bisect.sh
> @@ -210,7 +210,7 @@ bisect_start() {
>         eval "$eval true" &&
>         if test $must_write_terms -eq 1
>         then
> -               write_terms "$TERM_BAD" "$TERM_GOOD"
> +               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
This `|| exit` is not needed because...
>         fi &&
>         echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit

... there is an `|| exit` on the line above (which is chained using `&&` to the previous lines).

Previous: Pranit BauvaNext: Junio C Hamano
Message 108 of 110 in “bisect--helper: convert a function in shell to C”
  1. bisect--helper: convert a function in shell to CPranit Bauva, Mar 21, 2016
  2. Stefan BellerMar 22, 2016
  3. Christian CouderMar 22, 2016
  4. Pranit BauvaMar 22, 2016
  5. Pranit BauvaMar 22, 2016
  6. bisect--helper: convert a function in shell to CPranit Bauva, Mar 22, 2016
  7. Johannes SchindelinMar 22, 2016
  8. Johannes SchindelinMar 22, 2016
  9. Pranit BauvaMar 22, 2016
  10. Johannes SchindelinMar 23, 2016
  11. Junio C HamanoMar 22, 2016
  12. Johannes SchindelinMar 22, 2016
  13. Pranit BauvaMar 22, 2016
  14. Stefan BellerMar 22, 2016
  15. Johannes SchindelinMar 23, 2016
  16. Pranit BauvaMar 22, 2016
  17. Johannes SchindelinMar 23, 2016
  18. Pranit BauvaMar 23, 2016
  19. bisect--helper: convert a function in shell to CPranit Bauva, Mar 23, 2016
  20. Johannes SchindelinMar 23, 2016
  21. Pranit BauvaMar 23, 2016
  22. Junio C HamanoMar 23, 2016
  23. Pranit BauvaMar 23, 2016
  24. Junio C HamanoMar 23, 2016
  25. Pranit BauvaMar 23, 2016
  26. 0/2 bisect--helper: rewrite of check_term_format()Pranit Bauva, May 4, 2016
  27. 1/2 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, May 4, 2016
  28. Pranit BauvaMay 4, 2016
  29. Eric SunshineMay 4, 2016
  30. Christian CouderMay 4, 2016
  31. Johannes SchindelinMay 4, 2016
  32. Pranit BauvaMay 4, 2016
  33. Christian CouderMay 4, 2016
  34. Johannes SchindelinMay 4, 2016
  35. Christian CouderMay 4, 2016
  36. Johannes SchindelinMay 4, 2016
  37. Christian CouderMay 4, 2016
  38. Johannes SchindelinMay 8, 2016
  39. Junio C HamanoMay 4, 2016
  40. Johannes SchindelinMay 4, 2016
  41. 2/2 bisect: rewrite `check_term_format` shell function in CPranit Bauva, May 4, 2016
  42. Eric SunshineMay 4, 2016
  43. Pranit BauvaMay 4, 2016
  44. Pranit BauvaMay 4, 2016
  45. Eric SunshineMay 4, 2016
  46. Christian CouderMay 4, 2016
  47. Pranit BauvaMay 4, 2016
  48. Eric SunshineMay 4, 2016
  49. Pranit BauvaMay 4, 2016
  50. Johannes SchindelinMay 4, 2016
  51. Pranit BauvaMay 4, 2016
  52. Christian CouderMay 4, 2016
  53. Junio C HamanoMay 4, 2016
  54. Christian CouderMay 4, 2016
  55. Pranit BauvaMay 4, 2016
  56. 0/2 bisect--helper: rewrite of check-term-format()Pranit Bauva, May 6, 2016
  57. 1/2 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, May 6, 2016
  58. Johannes SchindelinMay 8, 2016
  59. Pranit BauvaMay 8, 2016
  60. Christian CouderMay 8, 2016
  61. Pranit BauvaMay 8, 2016
  62. Johannes SchindelinMay 9, 2016
  63. Pranit BauvaMay 9, 2016
  64. 2/2 bisect: rewrite `check_term_format` shell function in CPranit Bauva, May 6, 2016
  65. Eric SunshineMay 7, 2016
  66. Junio C HamanoMay 6, 2016
  67. Pranit BauvaMay 7, 2016
  68. Junio C HamanoMay 8, 2016
  69. Pranit BauvaMay 8, 2016
  70. Pranit BauvaMay 8, 2016
  71. Eric SunshineMay 16, 2016
  72. Christian CouderMay 16, 2016
  73. Pranit BauvaMay 20, 2016
  74. 0/3 bisect--helper: check_term_format() & write_terms()Pranit Bauva, May 12, 2016
  75. 1/3 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, May 12, 2016
  76. Eric SunshineMay 16, 2016
  77. Pranit BauvaMay 20, 2016
  78. 2/3 bisect: rewrite `check_term_format` shell function in CPranit Bauva, May 12, 2016
  79. Junio C HamanoMay 12, 2016
  80. Pranit BauvaMay 13, 2016
  81. Junio C HamanoMay 13, 2016
  82. 3/3 bisect--helper: `write_terms` shell function in CPranit Bauva, May 12, 2016
  83. Eric SunshineMay 16, 2016
  84. Johannes SchindelinMay 16, 2016
  85. Eric SunshineMay 16, 2016
  86. Johannes SchindelinMay 16, 2016
  87. Eric SunshineMay 16, 2016
  88. Pranit BauvaMay 20, 2016
  89. Johannes SchindelinMay 23, 2016
  90. Christian CouderMay 23, 2016
  91. Johannes SchindelinMay 23, 2016
  92. Pranit BauvaMay 23, 2016
  93. Pranit BauvaMay 20, 2016
  94. 0/3 bisect--helper: check_term_format() & write_terms()Pranit Bauva, May 23, 2016
  95. 1/3 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, May 23, 2016
  96. 2/3 bisect: rewrite `check_term_format` shell function in CPranit Bauva, May 23, 2016
  97. 3/3 bisect--helper: `write_terms` shell function in CPranit Bauva, May 23, 2016
  98. Eric SunshineMay 23, 2016
  99. Pranit BauvaMay 23, 2016
  100. 0/3 bisect--helper: check-term-format() & write_terms()Pranit Bauva, May 24, 2016
  101. 1/3 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, May 24, 2016
  102. 2/3 bisect: rewrite `check_term_format` shell function in CPranit Bauva, May 24, 2016
  103. Johannes SchindelinMay 25, 2016
  104. Pranit BauvaMay 25, 2016
  105. Lars SchneiderJun 16, 2016
  106. Pranit BauvaJun 17, 2016
  107. 3/3 bisect--helper: `write_terms` shell function in CPranit Bauva, May 24, 2016
  108. Christian CouderMay 24, 2016
  109. Junio C HamanoMay 24, 2016
  110. Pranit BauvaMay 24, 2016

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.