/*
* Recursive Merge algorithm stolen from git-merge-recursive.py by
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
#include "cache.h"
#include "cache-tree.h"
#include "commit.h"
#include "blob.h"
#include "tree-walk.h"
#include "diff.h"
#include "diffcore.h"
#include "run-command.h"
#include "tag.h"
#include "unpack-trees.h"
#include "path-list.h"
#include "xdiff-interface.h"
/*
* A virtual commit has
* - (const char *)commit->util set to the name, and
* - *(int *)commit->object.sha1 set to the virtual id.
*/
static unsigned commit_list_count(const struct commit_list *l)
{
unsigned c = 0;
for (; l; l = l->next )
c++;
return c;
}
static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
{
struct commit *commit = xcalloc(1, sizeof(struct commit));
static unsigned virtual_id = 1;
commit->tree = tree;
commit->util = (void*)comment;
*(int*)commit->object.sha1 = virtual_id++;
/* avoid warnings */
commit->object.parsed = 1;
return commit;
}
/*
* Since we use get_tree_entry(), which does not put the read object into
* the object pool, we cannot rely on a == b.
*/
static int sha_eq(const unsigned char *a, const unsigned char *b)
{
if (!a && !b)
return 2;
return a && b && hashcmp(a, b) == 0;
}
/*
* Since we want to write the index eventually, we cannot reuse the index
* for these (temporary) data.
*/
struct stage_data
{
struct
{
unsigned mode;
unsigned char sha[20];
} stages[4];
unsigned processed:1;
};
struct output_buffer
{
struct output_buffer *next;
char *str;
};
static struct path_list current_file_set = {NULL, 0, 0, 1};
static struct path_list current_directory_set = {NULL, 0, 0, 1};
static int call_depth = 0;
static int verbosity = 2;
static int buffer_output = 1;
static int do_progress = 1;
static unsigned last_percent;
static unsigned merged_cnt;
static unsigned total_cnt;
static volatile sig_atomic_t progress_update;
static struct output_buffer *output_list, *output_end;
static int show (int v)
{
return (!call_depth && verbosity >= v) || verbosity >= 5;
}
static void output(int v, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if (buffer_output && show(v)) {
struct output_buffer *b = xmalloc(sizeof(*b));
nfvasprintf(&b->str, fmt, args);
|