Commit d1f33156 by Vicent Martí

Merge remote-tracking branch 'carlosmn/revwalk-merge-base' into new-error-handling

parents fcb2164f eb8117b8
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/revwalk.h" #include "git2/revwalk.h"
#include "git2/merge.h"
#include "git2/refs.h" #include "git2/refs.h"
#include "git2/reflog.h" #include "git2/reflog.h"
......
/*
* Copyright (C) 2009-2012 the libgit2 contributors
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_merge_h__
#define INCLUDE_git_merge_h__
#include "common.h"
#include "types.h"
#include "oid.h"
/**
* @file git2/merge.h
* @brief Git merge-base routines
* @defgroup git_revwalk Git merge-base routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Find a merge base between two commits
*
* @param out the OID of a merge base between 'one' and 'two'
* @param repo the repository where the commits exist
* @param one one of the commits
* @param two the other commit
*/
GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, git_oid *one, git_oid *two);
/** @} */
GIT_END_DECL
#endif
...@@ -164,6 +164,28 @@ GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob); ...@@ -164,6 +164,28 @@ GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk); GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
/** /**
* Push the OID pointed to by a reference
*
* The reference must point to a commit.
*
* @param walk the walker being used for the traversal
* @param refname the referece to push
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
/**
* Hide the OID pointed to by a reference
*
* The reference must point to a commit.
*
* @param walk the walker being used for the traversal
* @param refname the referece to hide
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
/**
* Get the next commit from the revision walk. * Get the next commit from the revision walk.
* *
* The initial call to this method is *not* blocking when * The initial call to this method is *not* blocking when
......
...@@ -148,14 +148,13 @@ void test_revwalk_basic__push_head(void) ...@@ -148,14 +148,13 @@ void test_revwalk_basic__push_head(void)
cl_assert(i == 7); cl_assert(i == 7);
} }
void test_revwalk_basic__push_head_hide_glob(void) void test_revwalk_basic__push_head_hide_ref(void)
{ {
int i = 0; int i = 0;
git_oid oid; git_oid oid;
cl_git_pass(git_revwalk_push_head(_walk)); cl_git_pass(git_revwalk_push_head(_walk));
/* This is a hack, as we know this will only match the packed-test branch */ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
cl_git_pass(git_revwalk_hide_glob(_walk, "heads/packed-test*"));
while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) { while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
i++; i++;
...@@ -164,3 +163,19 @@ void test_revwalk_basic__push_head_hide_glob(void) ...@@ -164,3 +163,19 @@ void test_revwalk_basic__push_head_hide_glob(void)
/* git log HEAD --oneline --not refs/heads/packed-test | wc -l => 4 */ /* git log HEAD --oneline --not refs/heads/packed-test | wc -l => 4 */
cl_assert(i == 4); cl_assert(i == 4);
} }
void test_revwalk_basic__push_head_hide_ref_nobase(void)
{
int i = 0;
git_oid oid;
cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed"));
while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
i++;
}
/* git log HEAD --oneline --not refs/heads/packed | wc -l => 7 */
cl_assert(i == 7);
}
#include "clar_libgit2.h"
static git_repository *_repo;
void test_revwalk_mergebase__initialize(void)
{
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
}
void test_revwalk_mergebase__cleanup(void)
{
git_repository_free(_repo);
}
void test_revwalk_mergebase__single1(void)
{
git_oid result, one, two, expected;
git_oid_fromstr(&one, "c47800c7266a2be04c571c04d5a6614691ea99bd ");
git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a");
git_oid_fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
}
void test_revwalk_mergebase__single2(void)
{
git_oid result, one, two, expected;
git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af");
git_oid_fromstr(&two, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd");
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment