Skip to content

Commit 8082588

Browse files
committed
fix!: upgrade from git-repository to gix
This change renames the public re-export from `git` to `gix` as well for consistency.
1 parent 7ea9dda commit 8082588

File tree

12 files changed

+99
-97
lines changed

12 files changed

+99
-97
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ This release is v11.2, but correctly indicates the **breaking change** introduce
735735
- <csr-id-2d3a182819077a1fe068cb16fdfeceed2f6882da/> Use `gitoxide` `Repository` instead of `git2::Repository`
736736
This comes with plenty of changes to the API of the
737737
`last_seen_reference()` and to the lower-level methods that take
738-
object ids (now `git::hash::ObjectId`.
738+
object ids (now `gix::hash::ObjectId`.
739739

740740
Note that `git2` is still used internally for fetching and cloning.
741741
This change was made to assure that at no time there are two open

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ required-features = ["max-performance"]
2727
[features]
2828
default = ["http-curl"]
2929
## Configure `git-repository` to use maximum performance.
30-
max-performance = ["git-repository/max-performance"]
30+
max-performance = ["gix/max-performance"]
3131
## Use libcurl for all http/https interactions. Supports many git http settings, but needs a C toolchain to build.
32-
http-curl = ["git-repository/blocking-http-transport-curl"]
32+
http-curl = ["gix/blocking-http-transport-curl"]
3333
## Use reqwest along with pure-rust TLS implementations. Needs no C toolchain, but might not be parity in features compared to curl.
34-
http-reqwest = ["git-repository/blocking-http-transport-reqwest-rust-tls"]
34+
http-reqwest = ["gix/blocking-http-transport-reqwest-rust-tls"]
3535

3636

3737
[dependencies]
38-
git-repository = { version = "0.29.0", default-features = false, features = ["max-performance-safe", "blocking-network-client"] }
38+
gix = { version = "0.37.1", default-features = false, features = ["max-performance-safe", "blocking-network-client"] }
3939
serde = { version = "1", features = ["std", "derive"] }
4040
hex = { version = "0.4.3", features = ["serde"] }
4141
smartstring = { version = "1.0.1", features = ["serde"] }
@@ -46,6 +46,6 @@ ahash = "0.8.0"
4646
hashbrown = { version = "0.13.1", features = ["raw"] }
4747

4848
[dev-dependencies]
49-
git-testtools = "0.9.0"
49+
gix-testtools = "0.11.0"
5050
crates-index = "0.18.11"
5151
tempdir = "0.3.5"

src/index/diff/delegate.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::index::diff::Error;
22
use crate::{Change, CrateVersion};
33
use ahash::{AHashSet, RandomState};
44
use bstr::BStr;
5-
use git_repository as git;
65
use hashbrown::raw::RawTable;
76

87
#[derive(Default)]
@@ -14,15 +13,15 @@ pub(crate) struct Delegate {
1413
impl Delegate {
1514
pub fn handle(
1615
&mut self,
17-
change: git::object::tree::diff::Change<'_, '_, '_>,
18-
) -> Result<git::object::tree::diff::Action, Error> {
19-
use git::bstr::ByteSlice;
20-
use git::object::tree::diff::change::Event::*;
21-
use git::objs::tree::EntryMode::*;
16+
change: gix::object::tree::diff::Change<'_, '_, '_>,
17+
) -> Result<gix::object::tree::diff::Action, Error> {
18+
use gix::bstr::ByteSlice;
19+
use gix::object::tree::diff::change::Event::*;
20+
use gix::objs::tree::EntryMode::*;
2221
fn entry_data(
23-
entry: git::objs::tree::EntryMode,
24-
id: git::Id<'_>,
25-
) -> Result<Option<git::Object<'_>>, Error> {
22+
entry: gix::objs::tree::EntryMode,
23+
id: gix::Id<'_>,
24+
) -> Result<Option<gix::Object<'_>>, Error> {
2625
matches!(entry, Blob | BlobExecutable)
2726
.then(|| id.object())
2827
.transpose()
@@ -33,6 +32,9 @@ impl Delegate {
3332
}
3433

3534
match change.event {
35+
Rewrite { .. } => {
36+
unreachable!("BUG: this is disabled so shouldn't happen")
37+
}
3638
Addition { entry_mode, id } => {
3739
if let Some(obj) = entry_data(entry_mode, id)? {
3840
for line in obj.data.lines() {

src/index/diff/mod.rs

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{Change, Index};
2-
use git_repository as git;
3-
use git_repository::prelude::ObjectIdExt;
2+
use gix::prelude::ObjectIdExt;
43
use std::sync::atomic::AtomicBool;
54

65
mod delegate;
@@ -29,57 +28,59 @@ pub enum Order {
2928
#[allow(missing_docs)]
3029
pub enum Error {
3130
#[error("Couldn't update marker reference")]
32-
ReferenceEdit(#[from] git::reference::edit::Error),
31+
ReferenceEdit(#[from] gix::reference::edit::Error),
3332
#[error("Failed to parse rev-spec to determine which revisions to diff")]
34-
RevParse(#[from] git::revision::spec::parse::Error),
33+
RevParse(#[from] gix::revision::spec::parse::Error),
34+
#[error(transparent)]
35+
DiffRewrites(#[from] gix::object::tree::diff::rewrites::Error),
3536
#[error("Couldn't find blob that showed up when diffing trees")]
36-
FindObject(#[from] git::object::find::existing::Error),
37+
FindObject(#[from] gix::object::find::existing::Error),
3738
#[error("Couldn't get the tree of a commit for diffing purposes")]
38-
PeelToTree(#[from] git::object::peel::to_kind::Error),
39+
PeelToTree(#[from] gix::object::peel::to_kind::Error),
3940
#[error("Failed to diff two trees to find changed crates")]
40-
Diff(#[from] git::object::blob::diff::init::Error),
41+
Diff(#[from] gix::object::blob::diff::init::Error),
4142
#[error(transparent)]
42-
DiffForEach(#[from] git::object::tree::diff::for_each::Error),
43+
DiffForEach(#[from] gix::object::tree::diff::for_each::Error),
4344
#[error("Failed to decode {line:?} in file {file_name:?} as crate version")]
4445
VersionDecode {
4546
source: serde_json::Error,
4647
file_name: bstr::BString,
4748
line: bstr::BString,
4849
},
4950
#[error(transparent)]
50-
FindRemote(#[from] git::remote::find::existing::Error),
51+
FindRemote(#[from] gix::remote::find::existing::Error),
5152
#[error(transparent)]
52-
FindReference(#[from] git::reference::find::existing::Error),
53+
FindReference(#[from] gix::reference::find::existing::Error),
5354
#[error(transparent)]
54-
Connect(#[from] git::remote::connect::Error),
55+
Connect(#[from] gix::remote::connect::Error),
5556
#[error(transparent)]
56-
PrepareFetch(#[from] git::remote::fetch::prepare::Error),
57+
PrepareFetch(#[from] gix::remote::fetch::prepare::Error),
5758
#[error(transparent)]
58-
Fetch(#[from] git::remote::fetch::Error),
59+
Fetch(#[from] gix::remote::fetch::Error),
5960
#[error(transparent)]
60-
InitAnonymousRemote(#[from] git::remote::init::Error),
61+
InitAnonymousRemote(#[from] gix::remote::init::Error),
6162
#[error("Could not find local tracking branch for remote branch {name:?} in any of {} fetched refs", mappings.len())]
6263
NoMatchingBranch {
6364
name: String,
64-
mappings: Vec<git::remote::fetch::Mapping>,
65+
mappings: Vec<gix::remote::fetch::Mapping>,
6566
},
6667
}
6768

6869
/// Find changes without modifying the underling repository
6970
impl Index {
7071
/// As `peek_changes_with_options()`, but without the options.
71-
pub fn peek_changes(&self) -> Result<(Vec<Change>, git::hash::ObjectId), Error> {
72+
pub fn peek_changes(&self) -> Result<(Vec<Change>, gix::hash::ObjectId), Error> {
7273
self.peek_changes_with_options(
73-
git::progress::Discard,
74+
gix::progress::Discard,
7475
&AtomicBool::default(),
7576
Order::ImplementationDefined,
7677
)
7778
}
7879

7980
/// As `peek_changes()` but provides changes similar to those in the crates index.
80-
pub fn peek_changes_ordered(&self) -> Result<(Vec<Change>, git::hash::ObjectId), Error> {
81+
pub fn peek_changes_ordered(&self) -> Result<(Vec<Change>, gix::hash::ObjectId), Error> {
8182
self.peek_changes_with_options(
82-
git::progress::Discard,
83+
gix::progress::Discard,
8384
&AtomicBool::default(),
8485
Order::AsInCratesIndex,
8586
)
@@ -110,17 +111,17 @@ impl Index {
110111
progress: P,
111112
should_interrupt: &AtomicBool,
112113
order: Order,
113-
) -> Result<(Vec<Change>, git::hash::ObjectId), Error>
114+
) -> Result<(Vec<Change>, gix::hash::ObjectId), Error>
114115
where
115-
P: git::Progress,
116+
P: gix::Progress,
116117
P::SubProgress: 'static,
117118
{
118119
let repo = &self.repo;
119120
let from = repo
120121
.find_reference(self.seen_ref_name)
121122
.ok()
122123
.and_then(|r| r.try_id().map(|id| id.detach()))
123-
.unwrap_or_else(|| git::hash::ObjectId::empty_tree(repo.object_hash()));
124+
.unwrap_or_else(|| gix::hash::ObjectId::empty_tree(repo.object_hash()));
124125
let to = {
125126
let mut remote = self
126127
.remote_name
@@ -131,12 +132,12 @@ impl Index {
131132
.head()
132133
.ok()
133134
.and_then(|head| {
134-
head.into_remote(git::remote::Direction::Fetch)
135+
head.into_remote(gix::remote::Direction::Fetch)
135136
.and_then(|r| r.ok())
136137
})
137138
.or_else(|| {
138139
self.repo
139-
.find_default_remote(git::remote::Direction::Fetch)
140+
.find_default_remote(gix::remote::Direction::Fetch)
140141
.and_then(|r| r.ok())
141142
})
142143
})
@@ -145,11 +146,11 @@ impl Index {
145146
.unwrap_or_else(|| {
146147
self.repo
147148
.head()?
148-
.into_remote(git::remote::Direction::Fetch)
149+
.into_remote(gix::remote::Direction::Fetch)
149150
.map(|r| r.map_err(Error::from))
150151
.or_else(|| {
151152
self.repo
152-
.find_default_remote(git::remote::Direction::Fetch)
153+
.find_default_remote(gix::remote::Direction::Fetch)
153154
.map(|r| r.map_err(Error::from))
154155
})
155156
.unwrap_or_else(|| {
@@ -158,18 +159,18 @@ impl Index {
158159
.map_err(Into::into)
159160
})
160161
})?;
161-
if remote.refspecs(git::remote::Direction::Fetch).is_empty() {
162+
if remote.refspecs(gix::remote::Direction::Fetch).is_empty() {
162163
let spec = format!(
163164
"+refs/heads/{branch}:refs/remotes/{remote}/{branch}",
164165
remote = self.remote_name.as_deref().unwrap_or("origin"),
165166
branch = self.branch_name,
166167
);
167168
remote
168-
.replace_refspecs(Some(spec.as_str()), git::remote::Direction::Fetch)
169+
.replace_refspecs(Some(spec.as_str()), gix::remote::Direction::Fetch)
169170
.expect("valid statically known refspec");
170171
}
171-
let res: git::remote::fetch::Outcome = remote
172-
.connect(git::remote::Direction::Fetch, progress)?
172+
let res: gix::remote::fetch::Outcome = remote
173+
.connect(gix::remote::Direction::Fetch, progress)?
173174
.prepare_fetch(Default::default())?
174175
.receive(should_interrupt)?;
175176
let branch_name = format!("refs/heads/{}", self.branch_name);
@@ -178,7 +179,7 @@ impl Index {
178179
.mappings
179180
.iter()
180181
.find_map(|m| match &m.remote {
181-
git::remote::fetch::Source::Ref(r) => (r.unpack().0 == branch_name)
182+
gix::remote::fetch::Source::Ref(r) => (r.unpack().0 == branch_name)
182183
.then_some(m.local.as_ref())
183184
.flatten(),
184185
_ => None,
@@ -217,21 +218,22 @@ impl Index {
217218
/// If a specific order is required, the changes must be sorted by the caller.
218219
pub fn changes_between_commits(
219220
&self,
220-
from: impl Into<git::hash::ObjectId>,
221-
to: impl Into<git::hash::ObjectId>,
221+
from: impl Into<gix::hash::ObjectId>,
222+
to: impl Into<gix::hash::ObjectId>,
222223
) -> Result<Vec<Change>, Error> {
223-
let into_tree = |id: git::hash::ObjectId| -> Result<git::Tree<'_>, Error> {
224+
let into_tree = |id: gix::hash::ObjectId| -> Result<gix::Tree<'_>, Error> {
224225
Ok(id
225226
.attach(&self.repo)
226227
.object()?
227-
.peel_to_kind(git::object::Kind::Tree)?
228+
.peel_to_kind(gix::object::Kind::Tree)?
228229
.into_tree())
229230
};
230231
let from = into_tree(from.into())?;
231232
let to = into_tree(to.into())?;
232233
let mut delegate = Delegate::default();
233-
from.changes()
234+
from.changes()?
234235
.track_filename()
236+
.track_rewrites(None)
235237
.for_each_to_obtain_tree(&to, |change| delegate.handle(change))?;
236238
delegate.into_result()
237239
}
@@ -250,8 +252,8 @@ impl Index {
250252
/// that the changes are actually in in case one of the invariants wasn't met.
251253
pub fn changes_between_ancestor_commits(
252254
&self,
253-
ancestor_commit: impl Into<git::hash::ObjectId>,
254-
current_commit: impl Into<git::hash::ObjectId>,
255+
ancestor_commit: impl Into<gix::hash::ObjectId>,
256+
current_commit: impl Into<gix::hash::ObjectId>,
255257
) -> Result<(Vec<Change>, Order), Error> {
256258
let from_commit = ancestor_commit.into();
257259
let to_commit = current_commit.into();
@@ -274,9 +276,9 @@ impl Index {
274276
/// Return a list of commits like `from_commit..=to_commits`.
275277
fn commit_ancestry(
276278
&self,
277-
ancestor_commit: git::hash::ObjectId,
278-
current_commit: git::hash::ObjectId,
279-
) -> Option<Vec<git::hash::ObjectId>> {
279+
ancestor_commit: gix::hash::ObjectId,
280+
current_commit: gix::hash::ObjectId,
281+
) -> Option<Vec<gix::hash::ObjectId>> {
280282
let time_in_seconds_since_epoch = ancestor_commit
281283
.attach(&self.repo)
282284
.object()
@@ -291,7 +293,7 @@ impl Index {
291293
.attach(&self.repo)
292294
.ancestors()
293295
.sorting(
294-
git::traverse::commit::Sorting::ByCommitTimeNewestFirstCutoffOlderThan {
296+
gix::traverse::commit::Sorting::ByCommitTimeNewestFirstCutoffOlderThan {
295297
time_in_seconds_since_epoch,
296298
},
297299
)
@@ -322,7 +324,7 @@ impl Index {
322324
/// As `fetch_changes_with_options()`, but without the options.
323325
pub fn fetch_changes(&self) -> Result<Vec<Change>, Error> {
324326
self.fetch_changes_with_options(
325-
git::progress::Discard,
327+
gix::progress::Discard,
326328
&AtomicBool::default(),
327329
Order::ImplementationDefined,
328330
)
@@ -331,7 +333,7 @@ impl Index {
331333
/// As `fetch_changes()`, but returns an ordered result.
332334
pub fn fetch_changes_ordered(&self) -> Result<Vec<Change>, Error> {
333335
self.fetch_changes_with_options(
334-
git::progress::Discard,
336+
gix::progress::Discard,
335337
&AtomicBool::default(),
336338
Order::AsInCratesIndex,
337339
)
@@ -362,7 +364,7 @@ impl Index {
362364
order: Order,
363365
) -> Result<Vec<Change>, Error>
364366
where
365-
P: git::Progress,
367+
P: gix::Progress,
366368
P::SubProgress: 'static,
367369
{
368370
let (changes, to) = self.peek_changes_with_options(progress, should_interrupt, order)?;
@@ -371,12 +373,12 @@ impl Index {
371373
}
372374

373375
/// Set the last seen reference to the given Oid. It will be created if it does not yet exists.
374-
pub fn set_last_seen_reference(&self, to: git::hash::ObjectId) -> Result<(), Error> {
376+
pub fn set_last_seen_reference(&self, to: gix::hash::ObjectId) -> Result<(), Error> {
375377
let repo = self.repository();
376378
repo.reference(
377379
self.seen_ref_name,
378380
to,
379-
git::refs::transaction::PreviousValue::Any,
381+
gix::refs::transaction::PreviousValue::Any,
380382
"updating seen-ref head to latest fetched commit",
381383
)?;
382384
Ok(())

0 commit comments

Comments
 (0)