1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 12:26:12 +02:00
git/merge-ort-wrappers.c
Elijah Newren d1cbe1e6d8 hash-ll.h: split out of hash.h to remove dependency on repository.h
hash.h depends upon and includes repository.h, due to the definition and
use of the_hash_algo (defined as the_repository->hash_algo).  However,
most headers trying to include hash.h are only interested in the layout
of the structs like object_id.  Move the parts of hash.h that do not
depend upon repository.h into a new file hash-ll.h (the "low level"
parts of hash.h), and adjust other files to use this new header where
the convenience inline functions aren't needed.

This allows hash.h and object.h to be fairly small, minimal headers.  It
also exposes a lot of hidden dependencies on both path.h (which was
brought in by repository.h) and repository.h (which was previously
implicitly brought in by object.h), so also adjust other files to be
more explicit about what they depend upon.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-04-24 12:47:32 -07:00

65 lines
1.5 KiB
C

#include "cache.h"
#include "gettext.h"
#include "hash.h"
#include "merge-ort.h"
#include "merge-ort-wrappers.h"
#include "commit.h"
static int unclean(struct merge_options *opt, struct tree *head)
{
/* Sanity check on repo state; index must match head */
struct strbuf sb = STRBUF_INIT;
if (head && repo_index_has_changes(opt->repo, head, &sb)) {
error(_("Your local changes to the following files would be overwritten by merge:\n %s"),
sb.buf);
strbuf_release(&sb);
return -1;
}
return 0;
}
int merge_ort_nonrecursive(struct merge_options *opt,
struct tree *head,
struct tree *merge,
struct tree *merge_base)
{
struct merge_result result;
if (unclean(opt, head))
return -1;
if (oideq(&merge_base->object.oid, &merge->object.oid)) {
printf_ln(_("Already up to date."));
return 1;
}
memset(&result, 0, sizeof(result));
merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
merge_switch_to_result(opt, head, &result, 1, 1);
return result.clean;
}
int merge_ort_recursive(struct merge_options *opt,
struct commit *side1,
struct commit *side2,
struct commit_list *merge_bases,
struct commit **result)
{
struct tree *head = repo_get_commit_tree(opt->repo, side1);
struct merge_result tmp;
if (unclean(opt, head))
return -1;
memset(&tmp, 0, sizeof(tmp));
merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
merge_switch_to_result(opt, head, &tmp, 1, 1);
*result = NULL;
return tmp.clean;
}