[PATCH v7 3/5] bisect: simplify the addition of new bisect terms

2015-06-23 Thread Matthieu Moy
From: Antoine Delaite antoine.dela...@ensimag.grenoble-inp.fr

We create a file BISECT_TERMS in the repository .git to be read during a
bisection. The fonctions to be changed if we add new terms are quite
few.
In git-bisect.sh :
check_and_set_terms
bisect_voc

Co-authored-by: Louis Stuber stub...@ensimag.grenoble-inp.fr
Tweaked-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Antoine Delaite antoine.dela...@ensimag.grenoble-inp.fr
Signed-off-by: Louis Stuber stub...@ensimag.grenoble-inp.fr
Signed-off-by: Valentin Duperray valentin.duper...@ensimag.imag.fr
Signed-off-by: Franck Jonas franck.jo...@ensimag.imag.fr
Signed-off-by: Lucien Kong lucien.k...@ensimag.imag.fr
Signed-off-by: Thomas Nguy thomas.n...@ensimag.imag.fr
Signed-off-by: Huynh Khoi Nguyen Nguyen 
huynh-khoi-nguyen.ngu...@ensimag.imag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Matthieu Moy matthieu@imag.fr
---
 bisect.c  | 38 +---
 git-bisect.sh | 70 +--
 revision.c| 26 --
 3 files changed, 122 insertions(+), 12 deletions(-)

diff --git a/bisect.c b/bisect.c
index 2d3dbdc..08be634 100644
--- a/bisect.c
+++ b/bisect.c
@@ -747,7 +747,10 @@ static void handle_bad_merge_base(void)
between %s and [%s].\n,
bad_hex, bad_hex, good_hex);
} else {
-   die(BUG: terms %s/%s not managed, name_bad, 
name_good);
+   fprintf(stderr, The merge base %s is %s.\n
+   This means the first commit marked %s is 
+   between %s and [%s].\n,
+   bad_hex, name_bad, name_bad, bad_hex, good_hex);
}
exit(3);
}
@@ -902,6 +905,36 @@ static void show_diff_tree(const char *prefix, struct 
commit *commit)
 }
 
 /*
+ * The terms used for this bisect session are stored in BISECT_TERMS.
+ * We read them and store them to adapt the messages accordingly.
+ * Default is bad/good.
+ */
+void read_bisect_terms(const char **read_bad, const char **read_good)
+{
+   struct strbuf str = STRBUF_INIT;
+   const char *filename = git_path(BISECT_TERMS);
+   FILE *fp = fopen(filename, r);
+
+   if (!fp) {
+   if (errno == ENOENT) {
+   *read_bad = bad;
+   *read_good = good;
+   return;
+   } else {
+   die(could not read file '%s': %s, filename,
+   strerror(errno));
+   }
+   } else {
+   strbuf_getline(str, fp, '\n');
+   *read_bad = strbuf_detach(str, NULL);
+   strbuf_getline(str, fp, '\n');
+   *read_good = strbuf_detach(str, NULL);
+   }
+   strbuf_release(str);
+   fclose(fp);
+}
+
+/*
  * We use the convention that exiting with an exit code 10 means that
  * the bisection process finished successfully.
  * In this case the calling shell script should exit 0.
@@ -917,8 +950,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
const unsigned char *bisect_rev;
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
 
-   name_bad = bad;
-   name_good = good;
+   read_bisect_terms(name_bad, name_good);
if (read_bisect_refs())
die(reading bisect refs failed);
 
diff --git a/git-bisect.sh b/git-bisect.sh
index ce6412f..7bb18db 100644
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -77,6 +77,9 @@ bisect_start() {
orig_args=$(git rev-parse --sq-quote $@)
bad_seen=0
eval=''
+   # revision_seen is true if a git bisect start
+   # has revision as arguments
+   revision_seen=0
if test z$(git rev-parse --is-bare-repository) != zfalse
then
mode=--no-checkout
@@ -101,6 +104,9 @@ bisect_start() {
die $(eval_gettext '\$arg' does not appear to 
be a valid revision)
break
}
+
+   revision_seen=1
+
case $bad_seen in
0) state=$NAME_BAD ; bad_seen=1 ;;
*) state=$NAME_GOOD ;;
@@ -172,6 +178,11 @@ bisect_start() {
} 
git rev-parse --sq-quote $@ $GIT_DIR/BISECT_NAMES 
eval $eval true 
+   if test $revision_seen -eq 1  test ! -s $GIT_DIR/BISECT_TERMS
+   then
+   echo $NAME_BAD $GIT_DIR/BISECT_TERMS 
+   echo $NAME_GOOD $GIT_DIR/BISECT_TERMS
+   fi 
echo git bisect start$orig_args $GIT_DIR/BISECT_LOG || exit
#
# Check if we can proceed to the next bisect state.
@@ -232,6 +243,7 @@ bisect_skip() {
 bisect_state() {
bisect_autostart
state=$1
+   check_and_set_terms $state
case $#,$state 

Re: [PATCH v7 3/5] bisect: simplify the addition of new bisect terms

2015-06-23 Thread Eric Sunshine
On Tue, Jun 23, 2015 at 8:54 AM, Matthieu Moy matthieu@imag.fr wrote:
 diff --git a/revision.c b/revision.c
 index 3ff8723..f22923f 100644
 --- a/revision.c
 +++ b/revision.c
 @@ -2076,14 +2079,32 @@ void parse_revision_opt(struct rev_info *revs, struct 
 parse_opt_ctx_t *ctx,
 ctx-argc -= n;
  }

 +extern void read_bisect_terms(const char **bad, const char **good);
 +
  static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, 
 void *cb_data)
  {
 -   return for_each_ref_in_submodule(submodule, refs/bisect/bad, fn, 
 cb_data);
 +   struct strbuf bisect_refs_buf = STRBUF_INIT;
 +   const char *bisect_refs_str;
 +   int status;
 +   strbuf_addstr(bisect_refs_buf, refs/bisect/);
 +   strbuf_addstr(bisect_refs_buf, name_bad);

A single strbuf_addf() rather than two strbuf_addstr()s?

 +   bisect_refs_str = strbuf_detach(bisect_refs_buf, NULL);
 +   status = for_each_ref_in_submodule(submodule, bisect_refs_str, fn, 
 cb_data);
 +   free((char *)bisect_refs_str);

Why the above rather than the simpler?

strbuf_addstr(bisect_refs, ...);
status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
strbuf_release(bisect_refs);

What am I missing?

 +   return status;
  }

  static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, 
 void *cb_data)
  {
 -   return for_each_ref_in_submodule(submodule, refs/bisect/good, fn, 
 cb_data);
 +   struct strbuf bisect_refs_buf = STRBUF_INIT;
 +   const char *bisect_refs_str;
 +   int status;
 +   strbuf_addstr(bisect_refs_buf, refs/bisect/);
 +   strbuf_addstr(bisect_refs_buf, name_bad);
 +   bisect_refs_str = strbuf_detach(bisect_refs_buf, NULL);
 +   status = for_each_ref_in_submodule(submodule, bisect_refs_str, fn, 
 cb_data);
 +   free((char *)bisect_refs_str);

Ditto.

 +   return status;
  }
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 3/5] bisect: simplify the addition of new bisect terms

2015-06-23 Thread Matthieu Moy
Eric Sunshine sunsh...@sunshineco.com writes:

 On Tue, Jun 23, 2015 at 8:54 AM, Matthieu Moy matthieu@imag.fr wrote:

 +   strbuf_addstr(bisect_refs_buf, refs/bisect/);
 +   strbuf_addstr(bisect_refs_buf, name_bad);

 A single strbuf_addf() rather than two strbuf_addstr()s?

 +   bisect_refs_str = strbuf_detach(bisect_refs_buf, NULL);
 +   status = for_each_ref_in_submodule(submodule, bisect_refs_str, fn, 
 cb_data);
 +   free((char *)bisect_refs_str);

 Why the above rather than the simpler?

 strbuf_addstr(bisect_refs, ...);
 status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, 
 cb_data);
 strbuf_release(bisect_refs);

 What am I missing?

Indeed, your version is much better.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html