summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4eb5b64)
raw | patch | inline | side by side (parent: 4eb5b64)
author | Christian Couder <chriscool@tuxfamily.org> | |
Thu, 26 Mar 2009 04:55:54 +0000 (05:55 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 5 Apr 2009 08:29:44 +0000 (01:29 -0700) |
This patch implements a new "git bisect--helper" builtin plumbing
command that will be used to migrate "git-bisect.sh" to C.
We start by implementing only the "--next-vars" option that will
read bisect refs from "refs/bisect/", and then compute the next
bisect step, and output shell variables ready to be eval'ed by
the shell.
At this step, "git bisect--helper" ignores the paths that may
have been put in "$GIT_DIR/BISECT_NAMES". This will be fixed in a
later patch.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
command that will be used to migrate "git-bisect.sh" to C.
We start by implementing only the "--next-vars" option that will
read bisect refs from "refs/bisect/", and then compute the next
bisect step, and output shell variables ready to be eval'ed by
the shell.
At this step, "git bisect--helper" ignores the paths that may
have been put in "$GIT_DIR/BISECT_NAMES". This will be fixed in a
later patch.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile | patch | blob | history | |
bisect.c | patch | blob | history | |
bisect.h | patch | blob | history | |
builtin-bisect--helper.c | [new file with mode: 0644] | patch | blob |
builtin.h | patch | blob | history | |
git.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index 42cabe81620e017d522ae377874e6b1bd1f10b6f..a2bfad43bc9f695f707d2d69472eb7d1af09ca5e 100644 (file)
--- a/Makefile
+++ b/Makefile
BUILTIN_OBJS += builtin-annotate.o
BUILTIN_OBJS += builtin-apply.o
BUILTIN_OBJS += builtin-archive.o
+BUILTIN_OBJS += builtin-bisect--helper.o
BUILTIN_OBJS += builtin-blame.o
BUILTIN_OBJS += builtin-branch.o
BUILTIN_OBJS += builtin-bundle.o
diff --git a/bisect.c b/bisect.c
index 47120c1cd87c1df97d28c7d687bedbc69338806a..94ec011786cdff03fd143926aea7835dc2839a30 100644 (file)
--- a/bisect.c
+++ b/bisect.c
#include "commit.h"
#include "diff.h"
#include "revision.h"
+#include "refs.h"
+#include "list-objects.h"
#include "sha1-lookup.h"
#include "bisect.h"
static unsigned char (*skipped_sha1)[20];
static int skipped_sha1_nr;
+static int skipped_sha1_alloc;
+
+static const char **rev_argv;
+static int rev_argv_nr;
+static int rev_argv_alloc;
/* bits #0-15 in revision.h */
return best;
}
+static int register_ref(const char *refname, const unsigned char *sha1,
+ int flags, void *cb_data)
+{
+ if (!strcmp(refname, "bad")) {
+ ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
+ rev_argv[rev_argv_nr++] = xstrdup(sha1_to_hex(sha1));
+ } else if (!prefixcmp(refname, "good-")) {
+ const char *hex = sha1_to_hex(sha1);
+ char *good = xmalloc(strlen(hex) + 2);
+ *good = '^';
+ memcpy(good + 1, hex, strlen(hex) + 1);
+ ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
+ rev_argv[rev_argv_nr++] = good;
+ } else if (!prefixcmp(refname, "skip-")) {
+ ALLOC_GROW(skipped_sha1, skipped_sha1_nr + 1,
+ skipped_sha1_alloc);
+ hashcpy(skipped_sha1[skipped_sha1_nr++], sha1);
+ }
+
+ return 0;
+}
+
+static int read_bisect_refs(void)
+{
+ return for_each_ref_in("refs/bisect/", register_ref, NULL);
+}
+
static int skipcmp(const void *a, const void *b)
{
return hashcmp(a, b);
return filtered;
}
+
+int bisect_next_vars(const char *prefix)
+{
+ struct rev_info revs;
+ int reaches = 0, all = 0;
+
+ init_revisions(&revs, prefix);
+ revs.abbrev = 0;
+ revs.commit_format = CMIT_FMT_UNSPECIFIED;
+
+ /* argv[0] will be ignored by setup_revisions */
+ ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
+ rev_argv[rev_argv_nr++] = xstrdup("bisect_rev_setup");
+
+ if (read_bisect_refs())
+ die("reading bisect refs failed");
+
+ ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
+ rev_argv[rev_argv_nr++] = xstrdup("--");
+
+ setup_revisions(rev_argv_nr, rev_argv, &revs, NULL);
+
+ revs.limited = 1;
+
+ if (prepare_revision_walk(&revs))
+ die("revision walk setup failed");
+ if (revs.tree_objects)
+ mark_edges_uninteresting(revs.commits, &revs, NULL);
+
+ revs.commits = find_bisection(revs.commits, &reaches, &all,
+ !!skipped_sha1_nr);
+
+ return show_bisect_vars(&revs, reaches, all, 0, 1);
+}
diff --git a/bisect.h b/bisect.h
index 2489630da07bb82596de69aa0893e0e522ff8f06..05eea175f792ad3944b6e6584c4380318e4b2489 100644 (file)
--- a/bisect.h
+++ b/bisect.h
struct commit_list **tried,
int show_all);
+/*
+ * The "show_all" parameter should be 0 if this function is called
+ * from outside "builtin-rev-list.c" as otherwise it would use
+ * static "revs" from this file.
+ */
extern int show_bisect_vars(struct rev_info *revs, int reaches, int all,
int show_all, int show_tried);
+extern int bisect_next_vars(const char *prefix);
+
#endif
diff --git a/builtin-bisect--helper.c b/builtin-bisect--helper.c
--- /dev/null
+++ b/builtin-bisect--helper.c
@@ -0,0 +1,27 @@
+#include "builtin.h"
+#include "cache.h"
+#include "parse-options.h"
+#include "bisect.h"
+
+static const char * const git_bisect_helper_usage[] = {
+ "git bisect--helper --next-vars",
+ NULL
+};
+
+int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
+{
+ int next_vars = 0;
+ struct option options[] = {
+ OPT_BOOLEAN(0, "next-vars", &next_vars,
+ "output next bisect step variables"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0);
+
+ if (!next_vars)
+ usage_with_options(git_bisect_helper_usage, options);
+
+ /* next-vars */
+ return bisect_next_vars(prefix);
+}
diff --git a/builtin.h b/builtin.h
index 1495cf6a20128ccffb981c3ac4d1da5469da1940..425ff8e89b361c34b3336cda58794682c66b57f3 100644 (file)
--- a/builtin.h
+++ b/builtin.h
extern int cmd_annotate(int argc, const char **argv, const char *prefix);
extern int cmd_apply(int argc, const char **argv, const char *prefix);
extern int cmd_archive(int argc, const char **argv, const char *prefix);
+extern int cmd_bisect__helper(int argc, const char **argv, const char *prefix);
extern int cmd_blame(int argc, const char **argv, const char *prefix);
extern int cmd_branch(int argc, const char **argv, const char *prefix);
extern int cmd_bundle(int argc, const char **argv, const char *prefix);
index c2b181ed78daa4510f5cfb7bbff5b78f449f872a..a553926b68f06bc9b1bd3169f6719b79ec0fd624 100644 (file)
--- a/git.c
+++ b/git.c
{ "annotate", cmd_annotate, RUN_SETUP },
{ "apply", cmd_apply },
{ "archive", cmd_archive },
+ { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
{ "blame", cmd_blame, RUN_SETUP },
{ "branch", cmd_branch, RUN_SETUP },
{ "bundle", cmd_bundle },