Skip to content

Commit 6ba9e96

Browse files
author
K
committed
Improvements
1 parent 57766bc commit 6ba9e96

File tree

5 files changed

+83
-98
lines changed

5 files changed

+83
-98
lines changed

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
target
22
Cargo.lock
33
src/main.rs
4+
5+
.vscode/
6+
.history/
7+
.idea/

Diff for: libgit2-sys/lib.rs

+75-77
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,65 @@ git_enum! {
13061306
}
13071307
}
13081308

1309+
#[repr(C)]
1310+
pub struct git_merge_file_options {
1311+
pub version: c_uint,
1312+
1313+
/// Label for the ancestor file side of the conflict which will be prepended
1314+
/// to labels in diff3-format merge files.
1315+
pub ancestor_label: *const c_char,
1316+
1317+
/// Label for our file side of the conflict which will be prepended
1318+
/// to labels in merge files.
1319+
pub our_label: *const c_char,
1320+
1321+
/// Label for their file side of the conflict which will be prepended
1322+
/// to labels in merge files.
1323+
pub their_label: *const c_char,
1324+
1325+
/// The file to favor in region conflicts.
1326+
pub favor: git_merge_file_favor_t,
1327+
1328+
/// see `git_merge_file_flag_t`
1329+
pub flags: c_uint,
1330+
pub marker_size: c_ushort,
1331+
}
1332+
1333+
#[repr(C)]
1334+
#[derive(Copy, Clone)]
1335+
pub struct git_merge_file_input {
1336+
pub version: c_uint,
1337+
/// Pointer to the contents of the file.
1338+
pub ptr: *const c_char,
1339+
/// Size of the contents pointed to in `ptr`.
1340+
pub size: size_t,
1341+
/// File name of the conflicted file, or `NULL` to not merge the path.
1342+
pub path: *const c_char,
1343+
/// File mode of the conflicted file, or `0` to not merge the mode.
1344+
pub mode: c_uint,
1345+
}
1346+
1347+
#[repr(C)]
1348+
#[derive(Copy, Clone)]
1349+
pub struct git_merge_file_result {
1350+
/// True if the output was automerged, false if the output contains
1351+
/// conflict markers.
1352+
pub automergeable: c_uint,
1353+
1354+
/// The path that the resultant merge file should use, or NULL if a
1355+
/// filename conflict would occur.
1356+
pub path: *const c_char,
1357+
1358+
/// The mode that the resultant merge file should use.
1359+
pub mode: c_uint,
1360+
1361+
/// The contents of the merge.
1362+
pub ptr: *const c_char,
1363+
1364+
/// The length of the merge contents.
1365+
pub len: size_t,
1366+
}
1367+
13091368
pub type git_transport_cb = Option<
13101369
extern "C" fn(
13111370
out: *mut *mut git_transport,
@@ -3073,7 +3132,6 @@ extern "C" {
30733132
pub fn git_repository_state_cleanup(repo: *mut git_repository) -> c_int;
30743133

30753134
// merge analysis
3076-
30773135
pub fn git_merge_analysis(
30783136
analysis_out: *mut git_merge_analysis_t,
30793137
pref_out: *mut git_merge_preference_t,
@@ -3082,6 +3140,22 @@ extern "C" {
30823140
their_heads_len: usize,
30833141
) -> c_int;
30843142

3143+
// For git_merge_file
3144+
pub fn git_merge_file_options_init(opts: *mut git_merge_file_options, version: c_uint)
3145+
-> c_int;
3146+
pub fn git_merge_file_input_init(opts: *mut git_merge_file_input, version: c_uint) -> c_int;
3147+
3148+
pub fn git_merge_file(
3149+
out: *mut git_merge_file_result,
3150+
ancestor: *const git_merge_file_input,
3151+
ours: *const git_merge_file_input,
3152+
theirs: *const git_merge_file_input,
3153+
opts: *const git_merge_file_options,
3154+
) -> c_int;
3155+
3156+
// Not used?
3157+
pub fn git_merge_file_result_free(result: *mut git_merge_file_result);
3158+
30853159
// notes
30863160
pub fn git_note_author(note: *const git_note) -> *const git_signature;
30873161
pub fn git_note_committer(note: *const git_note) -> *const git_signature;
@@ -3855,82 +3929,6 @@ extern "C" {
38553929
) -> c_int;
38563930
}
38573931

3858-
#[repr(C)]
3859-
pub struct git_merge_file_options {
3860-
pub version: c_uint,
3861-
3862-
/// Label for the ancestor file side of the conflict which will be prepended
3863-
/// to labels in diff3-format merge files.
3864-
pub ancestor_label: *const c_char,
3865-
3866-
/// Label for our file side of the conflict which will be prepended
3867-
/// to labels in merge files.
3868-
pub our_label: *const c_char,
3869-
3870-
/// Label for their file side of the conflict which will be prepended
3871-
/// to labels in merge files.
3872-
pub their_label: *const c_char,
3873-
3874-
/// The file to favor in region conflicts.
3875-
pub favor: git_merge_file_favor_t,
3876-
3877-
/// see `git_merge_file_flag_t`
3878-
pub flags: c_uint,
3879-
pub marker_size: c_ushort,
3880-
}
3881-
3882-
#[repr(C)]
3883-
#[derive(Copy, Clone)]
3884-
pub struct git_merge_file_input {
3885-
pub version: c_uint,
3886-
/// Pointer to the contents of the file.
3887-
pub ptr: *const c_char,
3888-
/// Size of the contents pointed to in `ptr`.
3889-
pub size: size_t,
3890-
/// File name of the conflicted file, or `NULL` to not merge the path.
3891-
pub path: *const c_char,
3892-
/// File mode of the conflicted file, or `0` to not merge the mode.
3893-
pub mode: c_uint,
3894-
}
3895-
3896-
#[repr(C)]
3897-
#[derive(Copy, Clone)]
3898-
pub struct git_merge_file_result {
3899-
/// True if the output was automerged, false if the output contains
3900-
/// conflict markers.
3901-
pub automergeable: c_uint,
3902-
3903-
/// The path that the resultant merge file should use, or NULL if a
3904-
/// filename conflict would occur.
3905-
pub path: *const c_char,
3906-
3907-
/// The mode that the resultant merge file should use.
3908-
pub mode: c_uint,
3909-
3910-
/// The contents of the merge.
3911-
pub ptr: *const c_char,
3912-
3913-
/// The length of the merge contents.
3914-
pub len: size_t,
3915-
}
3916-
3917-
extern "C" {
3918-
pub fn git_merge_file_options_init(opts: *mut git_merge_file_options, version: c_uint)
3919-
-> c_int;
3920-
pub fn git_merge_file_input_init(opts: *mut git_merge_file_input, version: c_uint) -> c_int;
3921-
3922-
pub fn git_merge_file(
3923-
out: *mut git_merge_file_result,
3924-
ancestor: *const git_merge_file_input,
3925-
ours: *const git_merge_file_input,
3926-
theirs: *const git_merge_file_input,
3927-
opts: *const git_merge_file_options,
3928-
) -> c_int;
3929-
3930-
// Not used?
3931-
pub fn git_merge_file_result_free(result: *mut git_merge_file_result);
3932-
}
3933-
39343932
pub fn init() {
39353933
use std::sync::Once;
39363934

Diff for: src/lib.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ pub enum FileMode {
10511051
Commit,
10521052
}
10531053

1054-
impl From<u32> for FileMode {
1054+
impl FileMode {
10551055
fn from(mode: u32) -> Self {
10561056
match mode {
10571057
raw::GIT_FILEMODE_UNREADABLE => FileMode::Unreadable,
@@ -1065,20 +1065,6 @@ impl From<u32> for FileMode {
10651065
}
10661066
}
10671067

1068-
impl Into<u32> for FileMode {
1069-
fn into(self) -> u32 {
1070-
let ret = match self {
1071-
FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE,
1072-
FileMode::Tree => raw::GIT_FILEMODE_TREE,
1073-
FileMode::Blob => raw::GIT_FILEMODE_BLOB,
1074-
FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE,
1075-
FileMode::Link => raw::GIT_FILEMODE_LINK,
1076-
FileMode::Commit => raw::GIT_FILEMODE_COMMIT,
1077-
};
1078-
ret as u32
1079-
}
1080-
}
1081-
10821068
bitflags! {
10831069
/// Return codes for submodule status.
10841070
///

Diff for: src/merge.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl MergeFileInput {
351351
self.mode = mode;
352352

353353
if let Some(mode) = self.mode {
354-
self.raw.mode = mode.into();
354+
self.raw.mode = mode as u32;
355355
}
356356

357357
self
@@ -388,7 +388,7 @@ impl MergeFileInput {
388388
let mut input = MergeFileInput::new();
389389
input.content(Some(content));
390390
input.path(index_entry.path.clone());
391-
input.mode(Some(index_entry.mode.into()));
391+
input.mode(Some(FileMode::from(index_entry.mode)));
392392

393393
input
394394
}
@@ -453,7 +453,7 @@ impl MergeFileResult {
453453
MergeFileResult {
454454
automergeable: raw.automergeable > 0,
455455
path: Some(path),
456-
mode: raw.mode.into(),
456+
mode: FileMode::from(raw.mode),
457457
content: Some(content),
458458
}
459459
}

Diff for: src/repo.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1908,9 +1908,6 @@ impl Repository {
19081908

19091909
let result = MergeFileResult::from_raw(ret);
19101910

1911-
// FIXME: need to free????
1912-
raw::git_merge_file_result_free(&mut ret as *mut _);
1913-
19141911
Ok(result)
19151912
}
19161913
}

0 commit comments

Comments
 (0)