8000 Expose git_merge_file function from libgit2 to repo.rs of git2-rs by kvzn · Pull Request #635 · rust-lang/git2-rs · GitHub
[go: up one dir, main page]

Skip to content

Expose git_merge_file function from libgit2 to repo.rs of git2-rs #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improvements
  • Loading branch information
K committed Nov 24, 2020
commit 6ba9e9652c9c51ff7bf303a9a28f4b25341ac3fc
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
target
Cargo.lock
src/main.rs

.vscode/
.history/
.idea/
152 changes: 75 additions & 77 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,65 @@ git_enum! {
}
}

#[repr(C)]
pub struct git_merge_file_options {
pub version: c_uint,

/// Label for the ancestor file side of the conflict which will be prepended
/// to labels in diff3-format merge files.
pub ancestor_label: *const c_char,

/// Label for our file side of the conflict which will be prepended
/// to labels in merge files.
pub our_label: *const c_char,

/// Label for their file side of the conflict which will be prepended
/// to labels in merge files.
pub their_label: *const c_char,

/// The file to favor in region conflicts.
pub favor: git_merge_file_favor_t,

/// see `git_merge_file_flag_t`
pub flags: c_uint,
pub marker_size: c_ushort,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct git_merge_file_input {
pub version: c_uint,
/// Pointer to the contents of the file.
pub ptr: *const c_char,
/// Size of the contents pointed to in `ptr`.
pub size: size_t,
/// File name of the conflicted file, or `NULL` to not merge the path.
pub path: *const c_char,
/// File mode of the conflicted file, or `0` to not merge the mode.
pub mode: c_uint,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct git_merge_file_result {
/// True if the output was automerged, false if the output contains
/// conflict markers.
pub automergeable: c_uint,

/// The path that the resultant merge file should use, or NULL if a
/// filename conflict would occur.
pub path: *const c_char,

/// The mode that the resultant merge file should use.
pub mode: c_uint,

/// The contents of the merge.
pub ptr: *const c_char,

/// The length of the merge contents.
pub len: size_t,
}

pub type git_transport_cb = Option<
extern "C" fn(
out: *mut *mut git_transport,
Expand Down Expand Up @@ -3073,7 +3132,6 @@ extern "C" {
pub fn git_repository_state_cleanup(repo: *mut git_repository) -> c_int;

// merge analysis

pub fn git_merge_analysis(
analysis_out: *mut git_merge_analysis_t,
pref_out: *mut git_merge_preference_t,
Expand All @@ -3082,6 +3140,22 @@ extern "C" {
their_heads_len: usize,
) -> c_int;

// For git_merge_file
pub fn git_merge_file_options_init(opts: *mut git_merge_file_options, version: c_uint)
-> c_int;
pub fn git_merge_file_input_init(opts: *mut git_merge_file_input, version: c_uint) -> c_int;

pub fn git_merge_file(
out: *mut git_merge_file_result,
ancestor: *const git_merge_file_input,
ours: *const git_merge_file_input,
theirs: *const git_merge_file_input,
opts: *const git_merge_file_options,
) -> c_int;

// Not used?
pub fn git_merge_file_result_free(result: *mut git_merge_file_result);

// notes
pub fn git_note_author(note: *const git_note) -> *const git_signature;
pub fn git_note_committer(note: *const git_note) -> *const git_signature;
Expand Down Expand Up @@ -3855,82 +3929,6 @@ extern "C" {
) -> c_int;
}

#[repr(C)]
pub struct git_merge_file_options {
pub version: c_uint,

/// Label for the ancestor file side of the conflict which will be prepended
/// to labels in diff3-format merge files.
pub ancestor_label: *const c_char,

/// Label for our file side of the conflict which will be prepended
/// to labels in merge files.
pub our_label: *const c_char,

/// Label for their file side of the conflict which will be prepended
/// to labels in merge files.
pub their_label: *const c_char,

/// The file to favor in region conflicts.
pub favor: git_merge_file_favor_t,

/// see `git_merge_file_flag_t`
pub flags: c_uint,
pub marker_size: c_ushort,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct git_merge_file_input {
pub version: c_uint,
/// Pointer to the contents of the file.
pub ptr: *const c_char,
/// Size of the contents pointed to in `ptr`.
pub size: size_t,
/// File name of the conflicted file, or `NULL` to not merge the path.
pub path: *const c_char,
/// File mode of the conflicted file, or `0` to not merge the mode.
pub mode: c_uint,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct git_merge_file_result {
/// True if the output was automerged, false if the output contains
/// conflict markers.
pub automergeable: c_uint,

/// The path that the resultant merge file should use, or NULL if a
/// filename conflict would occur.
pub path: *const c_char,

/// The mode that the resultant merge file should use.
pub mode: c_uint,

/// The contents of the merge.
pub ptr: *const c_char,

/// The length of the merge contents.
pub len: size_t,
}

extern "C" {
pub fn git_merge_file_options_init(opts: *mut git_merge_file_options, version: c_uint)
-> c_int;
pub fn git_merge_file_input_init(opts: *mut git_merge_file_input, version: c_uint) -> c_int;

pub fn git_merge_file(
out: *mut git_merge_file_result,
ancestor: *const git_merge_file_input,
ours: *const git_merge_file_input,
theirs: *const git_merge_file_input,
opts: *const git_merge_file_options,
) -> c_int;

// Not used?
pub fn git_merge_file_result_free(result: *mut git_merge_file_result);
}

pub fn init() {
use std::sync::Once;

Expand Down
16 changes: 1 addition & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ pub enum FileMode {
Commit,
}

impl From<u32> for FileMode {
impl FileMode {
fn from(mode: u32) -> Self {
match mode {
raw::GIT_FILEMODE_UNREADABLE => FileMode::Unreadable,
Expand All @@ -1065,20 +1065,6 @@ impl From<u32> for FileMode {
}
}

impl Into<u32> for FileMode {
fn into(self) -> u32 {
let ret = match self {
FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE,
FileMode::Tree => raw::GIT_FILEMODE_TREE,
FileMode::Blob => raw::GIT_FILEMODE_BLOB,
FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE,
FileMode::Link => raw::GIT_FILEMODE_LINK,
FileMode::Commit => raw::GIT_FILEMODE_COMMIT,
};
ret as u32
}
}

bitflags! {
/// Return codes for submodule status.
///
Expand Down
6 changes: 3 additions & 3 deletions src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl MergeFileInput {
self.mode = mode;

if let Some(mode) = self.mode {
self.raw.mode = mode.into();
self.raw.mode = mode as u32;
}

self
Expand Down Expand Up @@ -388,7 +388,7 @@ impl MergeFileInput {
let mut input = MergeFileInput::new();
input.content(Some(content));
input.path(index_entry.path.clone());
input.mode(Some(index_entry.mode.into()));
input.mode(Some(FileMode::from(index_entry.mode)));

input
}
Expand Down Expand Up @@ -453,7 +453,7 @@ impl MergeFileResult {
MergeFileResult {
automergeable: raw.automergeable > 0,
path: Some(path),
mode: raw.mode.into(),
mode: FileMode::from(raw.mode),
content: Some(content),
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,9 +1908,6 @@ impl Repository {

let result = MergeFileResult::from_raw(ret);

// FIXME: need to free????
raw::git_merge_file_result_free(&mut ret as *mut _);

Ok(result)
}
}
Expand Down
0