Skip to content

Commit b98c738

Browse files
committed
libgit2: Update git_fetch_options and git_remote_update_tips
1 parent d0422a7 commit b98c738

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

examples/fetch.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#![deny(warnings)]
1616

17-
use git2::{AutotagOption, FetchOptions, RemoteCallbacks, Repository};
17+
use git2::{AutotagOption, FetchOptions, RemoteCallbacks, RemoteUpdateFlags, Repository};
1818
use std::io::{self, Write};
1919
use std::str;
2020
use structopt::StructOpt;
@@ -113,7 +113,12 @@ fn run(args: &Args) -> Result<(), git2::Error> {
113113
// commits. This may be needed even if there was no packfile to download,
114114
// which can happen e.g. when the branches have been changed but all the
115115
// needed objects are available locally.
116-
remote.update_tips(None, true, AutotagOption::Unspecified, None)?;
116+
remote.update_tips(
117+
None,
118+
RemoteUpdateFlags::UPDATE_FETCHHEAD,
119+
AutotagOption::Unspecified,
120+
None,
121+
)?;
117122

118123
Ok(())
119124
}

libgit2-sys/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ pub struct git_indexer_options {
366366

367367
pub type git_remote_ready_cb = Option<extern "C" fn(*mut git_remote, c_int, *mut c_void) -> c_int>;
368368

369+
git_enum! {
370+
pub enum git_remote_update_flags {
371+
GIT_REMOTE_UPDATE_FETCHHEAD = 1 << 0,
372+
GIT_REMOTE_UPDATE_REPORT_UNCHANGED = 1 << 1,
373+
}
374+
}
375+
369376
#[repr(C)]
370377
pub struct git_remote_callbacks {
371378
pub version: c_uint,
@@ -391,7 +398,7 @@ pub struct git_fetch_options {
391398
pub version: c_int,
392399
pub callbacks: git_remote_callbacks,
393400
pub prune: git_fetch_prune_t,
394-
pub update_fetchhead: c_int,
401+
pub update_flags: c_uint,
395402
pub download_tags: git_remote_autotag_option_t,
396403
pub proxy_opts: git_proxy_options,
397404
pub depth: c_int,
@@ -2327,7 +2334,7 @@ extern "C" {
23272334
pub fn git_remote_update_tips(
23282335
remote: *mut git_remote,
23292336
callbacks: *const git_remote_callbacks,
2330-
update_fetchead: c_int,
2337+
update_flags: c_uint,
23312338
download_tags: git_remote_autotag_option_t,
23322339
reflog_message: *const c_char,
23332340
) -> c_int;

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,17 @@ bitflags! {
662662
}
663663
}
664664

665+
bitflags! {
666+
/// How to handle reference updates.
667+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
668+
pub struct RemoteUpdateFlags: u32 {
669+
/// Write the fetch results to FETCH_HEAD.
670+
const UPDATE_FETCHHEAD = raw::GIT_REMOTE_UPDATE_FETCHHEAD as u32;
671+
/// Report unchanged tips in the update_tips callback.
672+
const REPORT_UNCHANGED = raw::GIT_REMOTE_UPDATE_REPORT_UNCHANGED as u32;
673+
}
674+
}
675+
665676
#[cfg(test)]
666677
#[macro_use]
667678
mod test;

src/remote.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::iter::FusedIterator;
33
use std::marker;
44
use std::mem;
55
use std::ops::Range;
6+
use std::os::raw::c_uint;
67
use std::ptr;
78
use std::slice;
89
use std::str;
@@ -11,7 +12,7 @@ use std::{ffi::CString, os::raw::c_char};
1112
use crate::string_array::StringArray;
1213
use crate::util::Binding;
1314
use crate::{call, raw, Buf, Direction, Error, FetchPrune, Oid, ProxyOptions, Refspec};
14-
use crate::{AutotagOption, Progress, RemoteCallbacks, Repository};
15+
use crate::{AutotagOption, Progress, RemoteCallbacks, RemoteUpdateFlags, Repository};
1516

1617
/// A structure representing a [remote][1] of a git repository.
1718
///
@@ -43,7 +44,7 @@ pub struct FetchOptions<'cb> {
4344
depth: i32,
4445
proxy: Option<ProxyOptions<'cb>>,
4546
prune: FetchPrune,
46-
update_fetchhead: bool,
47+
update_flags: RemoteUpdateFlags,
4748
download_tags: AutotagOption,
4849
follow_redirects: RemoteRedirect,
4950
custom_headers: Vec<CString>,
@@ -320,7 +321,7 @@ impl<'repo> Remote<'repo> {
320321
pub fn update_tips(
321322
&mut self,
322323
callbacks: Option<&mut RemoteCallbacks<'_>>,
323-
update_fetchhead: bool,
324+
update_flags: RemoteUpdateFlags,
324325
download_tags: AutotagOption,
325326
msg: Option<&str>,
326327
) -> Result<(), Error> {
@@ -330,7 +331,7 @@ impl<'repo> Remote<'repo> {
330331
try_call!(raw::git_remote_update_tips(
331332
self.raw,
332333
cbs.as_ref(),
333-
update_fetchhead,
334+
update_flags.bits() as c_uint,
334335
download_tags,
335336
msg
336337
));
@@ -506,7 +507,7 @@ impl<'cb> FetchOptions<'cb> {
506507
callbacks: None,
507508
proxy: None,
508509
prune: FetchPrune::Unspecified,
509-
update_fetchhead: true,
510+
update_flags: RemoteUpdateFlags::UPDATE_FETCHHEAD,
510511
download_tags: AutotagOption::Unspecified,
511512
follow_redirects: RemoteRedirect::Initial,
512513
custom_headers: Vec::new(),
@@ -537,7 +538,17 @@ impl<'cb> FetchOptions<'cb> {
537538
///
538539
/// Defaults to `true`.
539540
pub fn update_fetchhead(&mut self, update: bool) -> &mut Self {
540-
self.update_fetchhead = update;
541+
self.update_flags
542+
.set(RemoteUpdateFlags::UPDATE_FETCHHEAD, update);
543+
self
544+
}
545+
546+
/// Set whether to report unchanged tips in the update_tips callback.
547+
///
548+
/// Defaults to `false`.
549+
pub fn report_unchanged(&mut self, update: bool) -> &mut Self {
550+
self.update_flags
551+
.set(RemoteUpdateFlags::REPORT_UNCHANGED, update);
541552
self
542553
}
543554

@@ -602,7 +613,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
602613
.map(|m| m.raw())
603614
.unwrap_or_else(|| ProxyOptions::new().raw()),
604615
prune: crate::call::convert(&self.prune),
605-
update_fetchhead: crate::call::convert(&self.update_fetchhead),
616+
update_flags: self.update_flags.bits() as c_uint,
606617
download_tags: crate::call::convert(&self.download_tags),
607618
depth: self.depth,
608619
follow_redirects: self.follow_redirects.raw(),
@@ -778,7 +789,7 @@ impl RemoteRedirect {
778789

779790
#[cfg(test)]
780791
mod tests {
781-
use crate::{AutotagOption, PushOptions};
792+
use crate::{AutotagOption, PushOptions, RemoteUpdateFlags};
782793
use crate::{Direction, FetchOptions, Remote, RemoteCallbacks, Repository};
783794
use std::cell::Cell;
784795
use tempfile::TempDir;
@@ -867,10 +878,20 @@ mod tests {
867878
origin.fetch(&[] as &[&str], None, None).unwrap();
868879
origin.fetch(&[] as &[&str], None, Some("foo")).unwrap();
869880
origin
870-
.update_tips(None, true, AutotagOption::Unspecified, None)
881+
.update_tips(
882+
None,
883+
RemoteUpdateFlags::UPDATE_FETCHHEAD,
884+
AutotagOption::Unspecified,
885+
None,
886+
)
871887
.unwrap();
872888
origin
873-
.update_tips(None, true, AutotagOption::All, Some("foo"))
889+
.update_tips(
890+
None,
891+
RemoteUpdateFlags::UPDATE_FETCHHEAD,
892+
AutotagOption::All,
893+
Some("foo"),
894+
)
874895
.unwrap();
875896

876897
t!(repo.remote_add_fetch("origin", "foo"));

0 commit comments

Comments
 (0)