forked from AndreyG/libgit2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.cpp
More file actions
98 lines (82 loc) · 2.1 KB
/
Copy pathdiff.cpp
File metadata and controls
98 lines (82 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <git2.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include "git2cpp/initializer.h"
#include "git2cpp/repo.h"
#include "git2cpp/diff.h"
using namespace git;
Tree resolve_to_tree(Repository const & repo, const char *identifier)
{
Object obj = revparse_single(repo, identifier);
switch (obj.type())
{
case GIT_OBJ_TREE:
return obj.to_tree();
break;
case GIT_OBJ_COMMIT:
return obj.to_commit().tree();
break;
}
std::ostringstream ss;
ss
<< "object corresponding to identifier "
<< identifier
<< " is neither commit or tree";
throw std::logic_error(ss.str());
}
const char *colors[] = {
"\033[m", /* reset */
"\033[1m", /* bold */
"\033[31m", /* red */
"\033[32m", /* green */
"\033[36m" /* cyan */
};
int diff_output(const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
static int check_str_param(const char *arg, const char *pattern, const char **val)
{
size_t len = strlen(pattern);
if (strncmp(arg, pattern, len))
return 0;
*val = (const char *)(arg + len);
return 1;
}
static void usage(const char *message, const char *arg)
{
if (message && arg)
fprintf(stderr, "%s: %s\n", message, arg);
else if (message)
fprintf(stderr, "%s\n", message);
fprintf(stderr, "usage: diff [<tree-oid> [<tree-oid>]]\n");
exit(1);
}
enum {
FORMAT_PATCH = 0,
FORMAT_COMPACT = 1,
FORMAT_RAW = 2
};
/* <sha1> <sha2> */
/* <sha1> --cached */
/* <sha1> */
/* --cached */
/* nothing */
Diff calc_diff(Repository & repo, Tree & t1, Tree & t2, bool cached, git_diff_options const & opts)
{
if (t1 && t2)
return git::diff(repo, t1, t2, opts);
else if (t1 && cached)
return diff_to_index(repo, t1, opts);
else if (t1)
return std::move(diff_to_index(repo, t1, opts).merge(diff_index_to_workdir(repo, opts)));
else if (cached)
{
auto tree = resolve_to_tree(repo, "HEAD");
return diff_to_index(repo, tree, opts);
}
else
return diff_index_to_workdir(repo, opts);
}
int main(int argc, char *argv[])
{
}