Skip to content

Instantly share code, notes, and snippets.

@pclouds
Created May 9, 2018 17:17
Show Gist options
  • Save pclouds/86a2df6c28043f1b6fa3d4e72e7a1276 to your computer and use it in GitHub Desktop.
Save pclouds/86a2df6c28043f1b6fa3d4e72e7a1276 to your computer and use it in GitHub Desktop.
diff --git a/Makefile b/Makefile
index f181687250..a1b955fbd6 100644
--- a/Makefile
+++ b/Makefile
@@ -695,6 +695,7 @@ TEST_BUILTINS_OBJS += test-subprocess.o
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
TEST_BUILTINS_OBJS += test-wildmatch.o
TEST_BUILTINS_OBJS += test-write-cache.o
+TEST_BUILTINS_OBJS += test-abc.o
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
diff --git a/repository.c b/repository.c
index c23404677e..7006f7991a 100644
--- a/repository.c
+++ b/repository.c
@@ -245,7 +245,8 @@ void repo_clear(struct repository *repo)
if (repo->index) {
discard_index(repo->index);
- FREE_AND_NULL(repo->index);
+ if (repo->index != &the_index)
+ FREE_AND_NULL(repo->index);
}
}
diff --git a/t/helper/test-abc.c b/t/helper/test-abc.c
index e69de29bb2..83cd4a0120 100644
--- a/t/helper/test-abc.c
+++ b/t/helper/test-abc.c
@@ -0,0 +1,36 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "commit.h"
+#include "tag.h"
+#include "tree.h"
+#include "revision.h"
+#include "alloc.h"
+#include "list-objects.h"
+
+static void show_commit(struct commit *commit, void *data)
+{
+ parse_commit_gently(commit, 0);
+}
+static void show_object(struct object *obj, const char *name, void *cb_data)
+{
+ if (obj->type == OBJ_TREE)
+ parse_tree_gently((struct tree *)obj, 0);
+ else if (obj->type == OBJ_TAG)
+ parse_tag((struct tag *)obj);
+}
+
+int cmd__abc(int argc, const char **argv)
+{
+ struct rev_info revs = {0};
+ const char *av[] = {"", "--all", "--objects", "--not", "HEAD~1000", NULL };
+
+ setup_git_directory();
+ init_revisions(&revs, "");
+ setup_revisions(5, av, &revs, NULL);
+ if (prepare_revision_walk(&revs))
+ die("revision walk setup failed");
+ traverse_commit_list(&revs, show_commit, show_object, NULL);
+ repo_clear(the_repository);
+
+ return 0;
+}
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 87066ced62..893f0dc5fd 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -7,6 +7,7 @@ struct test_cmd {
};
static struct test_cmd cmds[] = {
+ { "abc", cmd__abc },
{ "chmtime", cmd__chmtime },
{ "config", cmd__config },
{ "ctype", cmd__ctype },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 7116ddfb94..84eeca345a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -1,6 +1,7 @@
#ifndef __TEST_TOOL_H__
#define __TEST_TOOL_H__
+int cmd__abc(int argc, const char **argv);
int cmd__chmtime(int argc, const char **argv);
int cmd__config(int argc, const char **argv);
int cmd__ctype(int argc, const char **argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment