forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-graph: add repo arg to graph readers
Add a struct repository argument to the functions in commit-graph.h that read the commit graph. (This commit does not affect functions that write commit graphs.) Because the commit graph functions can now read the commit graph of any repository, the global variable core_commit_graph has been removed. Instead, the config option core.commitGraph is now read on the first time in a repository that a commit is attempted to be parsed using its commit graph. This commit includes a test that exercises the functionality on an arbitrary repository that is not the_repository. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
1 parent
8527750
commit dade47c
Showing
13 changed files
with
162 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "test-tool.h" | ||
#include "cache.h" | ||
#include "commit-graph.h" | ||
#include "commit.h" | ||
#include "config.h" | ||
#include "object-store.h" | ||
#include "object.h" | ||
#include "repository.h" | ||
#include "tree.h" | ||
|
||
static void test_parse_commit_in_graph(const char *gitdir, const char *worktree, | ||
const struct object_id *commit_oid) | ||
{ | ||
struct repository r; | ||
struct commit *c; | ||
struct commit_list *parent; | ||
|
||
repo_init(&r, gitdir, worktree); | ||
|
||
c = lookup_commit(&r, commit_oid); | ||
|
||
if (!parse_commit_in_graph(&r, c)) | ||
die("Couldn't parse commit"); | ||
|
||
printf("%"PRItime, c->date); | ||
for (parent = c->parents; parent; parent = parent->next) | ||
printf(" %s", oid_to_hex(&parent->item->object.oid)); | ||
printf("\n"); | ||
|
||
repo_clear(&r); | ||
} | ||
|
||
static void test_get_commit_tree_in_graph(const char *gitdir, | ||
const char *worktree, | ||
const struct object_id *commit_oid) | ||
{ | ||
struct repository r; | ||
struct commit *c; | ||
struct tree *tree; | ||
|
||
repo_init(&r, gitdir, worktree); | ||
|
||
c = lookup_commit(&r, commit_oid); | ||
|
||
/* | ||
* get_commit_tree_in_graph does not automatically parse the commit, so | ||
* parse it first. | ||
*/ | ||
if (!parse_commit_in_graph(&r, c)) | ||
die("Couldn't parse commit"); | ||
tree = get_commit_tree_in_graph(&r, c); | ||
if (!tree) | ||
die("Couldn't get commit tree"); | ||
|
||
printf("%s\n", oid_to_hex(&tree->object.oid)); | ||
|
||
repo_clear(&r); | ||
} | ||
|
||
int cmd__repository(int argc, const char **argv) | ||
{ | ||
if (argc < 2) | ||
die("must have at least 2 arguments"); | ||
if (!strcmp(argv[1], "parse_commit_in_graph")) { | ||
struct object_id oid; | ||
if (argc < 5) | ||
die("not enough arguments"); | ||
if (parse_oid_hex(argv[4], &oid, &argv[4])) | ||
die("cannot parse oid '%s'", argv[4]); | ||
test_parse_commit_in_graph(argv[2], argv[3], &oid); | ||
} else if (!strcmp(argv[1], "get_commit_tree_in_graph")) { | ||
struct object_id oid; | ||
if (argc < 5) | ||
die("not enough arguments"); | ||
if (parse_oid_hex(argv[4], &oid, &argv[4])) | ||
die("cannot parse oid '%s'", argv[4]); | ||
test_get_commit_tree_in_graph(argv[2], argv[3], &oid); | ||
} else { | ||
die("unrecognized '%s'", argv[1]); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters