summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-03-20 21:06:23 +0100
committerVicent Marti <vicent@github.com>2014-03-20 21:06:23 +0100
commit36a80fdaedc4724b20fe3ee1b3c87ae4daf23ab1 (patch)
tree070dec889b8600c08fc374ba9b943d3108b5cd01
parent7d633572669fdc7d4a0b16984d7124c3e0e45b3d (diff)
parent704b55cce33aa8665c558347c104041d3ec6e2f3 (diff)
downloadlibgit2-36a80fdaedc4724b20fe3ee1b3c87ae4daf23ab1.tar.gz
Merge pull request #2195 from libgit2/cmn/revwalk-no-hide
revwalk: don't try to find merge bases when there can be none
-rw-r--r--src/merge.c6
-rw-r--r--src/revwalk.c18
-rw-r--r--src/revwalk.h3
3 files changed, 22 insertions, 5 deletions
diff --git a/src/merge.c b/src/merge.c
index 0b11c0da3..66952c074 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -205,6 +205,12 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l
git_commit_list *result = NULL, *tmp = NULL;
git_pqueue list;
+ /* If there's only the one commit, there can be no merge bases */
+ if (twos->length == 0) {
+ *out = NULL;
+ return 0;
+ }
+
/* if the commit is repeated, we have a our merge base already */
git_vector_foreach(twos, i, two) {
if (one == two)
diff --git a/src/revwalk.c b/src/revwalk.c
index 753911246..f037ee692 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -141,6 +141,9 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
if (commit == NULL)
return -1; /* error already reported by failed lookup */
+ if (uninteresting)
+ walk->did_hide = 1;
+
commit->uninteresting = uninteresting;
if (walk->one == NULL && !uninteresting) {
walk->one = commit;
@@ -390,11 +393,18 @@ static int prepare_walk(git_revwalk *walk)
return GIT_ITEROVER;
}
- /* first figure out what the merge bases are */
- if (git_merge__bases_many(&bases, walk, walk->one, &walk->twos) < 0)
- return -1;
+ /*
+ * If the user asked to hide commits, we need to figure out
+ * what the merge bases are so we can know when we can stop
+ * marking parents uninteresting.
+ */
+ if (walk->did_hide) {
+ if (git_merge__bases_many(&bases, walk, walk->one, &walk->twos) < 0)
+ return -1;
+
+ git_commit_list_free(&bases);
+ }
- git_commit_list_free(&bases);
if (process_commit(walk, walk->one, walk->one->uninteresting) < 0)
return -1;
diff --git a/src/revwalk.h b/src/revwalk.h
index 8c821d098..a0ce1ae86 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -32,7 +32,8 @@ struct git_revwalk {
int (*enqueue)(git_revwalk *, git_commit_list_node *);
unsigned walking:1,
- first_parent: 1;
+ first_parent: 1,
+ did_hide: 1;
unsigned int sorting;
/* merge base calculation */