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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use libc::c_uint;
use std::marker;
use std::mem;
use std::str;
use crate::call::Convert;
use crate::util::Binding;
use crate::{raw, Commit, FileFavor, Oid};
pub struct AnnotatedCommit<'repo> {
raw: *mut raw::git_annotated_commit,
_marker: marker::PhantomData<Commit<'repo>>,
}
pub struct MergeOptions {
raw: raw::git_merge_options,
}
impl<'repo> AnnotatedCommit<'repo> {
pub fn id(&self) -> Oid {
unsafe { Binding::from_raw(raw::git_annotated_commit_id(self.raw)) }
}
pub fn refname(&self) -> Option<&str> {
str::from_utf8(self.refname_bytes()).ok()
}
pub fn refname_bytes(&self) -> &[u8] {
unsafe { crate::opt_bytes(self, raw::git_annotated_commit_ref(&*self.raw)).unwrap() }
}
}
impl Default for MergeOptions {
fn default() -> Self {
Self::new()
}
}
impl MergeOptions {
pub fn new() -> MergeOptions {
let mut opts = MergeOptions {
raw: unsafe { mem::zeroed() },
};
assert_eq!(unsafe { raw::git_merge_init_options(&mut opts.raw, 1) }, 0);
opts
}
fn flag(&mut self, opt: u32, val: bool) -> &mut MergeOptions {
if val {
self.raw.flags |= opt;
} else {
self.raw.flags &= !opt;
}
self
}
pub fn find_renames(&mut self, find: bool) -> &mut MergeOptions {
self.flag(raw::GIT_MERGE_FIND_RENAMES as u32, find)
}
pub fn fail_on_conflict(&mut self, fail: bool) -> &mut MergeOptions {
self.flag(raw::GIT_MERGE_FAIL_ON_CONFLICT as u32, fail)
}
pub fn skip_reuc(&mut self, skip: bool) -> &mut MergeOptions {
self.flag(raw::GIT_MERGE_FAIL_ON_CONFLICT as u32, skip)
}
pub fn no_recursive(&mut self, disable: bool) -> &mut MergeOptions {
self.flag(raw::GIT_MERGE_NO_RECURSIVE as u32, disable)
}
pub fn rename_threshold(&mut self, thresh: u32) -> &mut MergeOptions {
self.raw.rename_threshold = thresh;
self
}
pub fn target_limit(&mut self, limit: u32) -> &mut MergeOptions {
self.raw.target_limit = limit as c_uint;
self
}
pub fn recursion_limit(&mut self, limit: u32) -> &mut MergeOptions {
self.raw.recursion_limit = limit as c_uint;
self
}
pub fn file_favor(&mut self, favor: FileFavor) -> &mut MergeOptions {
self.raw.file_favor = favor.convert();
self
}
fn file_flag(&mut self, opt: u32, val: bool) -> &mut MergeOptions {
if val {
self.raw.file_flags |= opt;
} else {
self.raw.file_flags &= !opt;
}
self
}
pub fn standard_style(&mut self, standard: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_STYLE_MERGE as u32, standard)
}
pub fn diff3_style(&mut self, diff3: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_STYLE_DIFF3 as u32, diff3)
}
pub fn simplify_alnum(&mut self, simplify: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_SIMPLIFY_ALNUM as u32, simplify)
}
pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE as u32, ignore)
}
pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE as u32, ignore)
}
pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL as u32, ignore)
}
pub fn patience(&mut self, patience: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_DIFF_PATIENCE as u32, patience)
}
pub fn minimal(&mut self, minimal: bool) -> &mut MergeOptions {
self.file_flag(raw::GIT_MERGE_FILE_DIFF_MINIMAL as u32, minimal)
}
pub unsafe fn raw(&self) -> *const raw::git_merge_options {
&self.raw as *const _
}
}
impl<'repo> Binding for AnnotatedCommit<'repo> {
type Raw = *mut raw::git_annotated_commit;
unsafe fn from_raw(raw: *mut raw::git_annotated_commit) -> AnnotatedCommit<'repo> {
AnnotatedCommit {
raw: raw,
_marker: marker::PhantomData,
}
}
fn raw(&self) -> *mut raw::git_annotated_commit {
self.raw
}
}
impl<'repo> Drop for AnnotatedCommit<'repo> {
fn drop(&mut self) {
unsafe { raw::git_annotated_commit_free(self.raw) }
}
}