Browse Source

git-protocol uses `oid` type (#63)

pull/68/head
Sebastian Thiel 1 month ago
parent
commit
3930a6ff50
No known key found for this signature in database GPG Key ID: 9CB5EE7895E8268B
  1. 2
      DEVELOPMENT.md
  2. 2
      git-features/src/hash.rs
  3. 2
      git-odb/src/loose/db/iter.rs
  4. 2
      git-odb/src/pack/index/access.rs
  5. 14
      git-protocol/src/fetch/arguments.rs
  6. 30
      git-protocol/src/fetch/tests/arguments.rs
  7. 2
      git-protocol/tests/fetch/mod.rs
  8. 4
      gitoxide-core/src/pack/receive.rs

2
DEVELOPMENT.md

@ -51,7 +51,7 @@
* **this is optional but desirable if…**
* …there is no leakage otherwise to support user interfaces. They background long-running operations and need them to be cancellable.
* **prepare for SHA256 support by using `git_hash::Id` and `git_hash::borrowed::Id`**
* **prepare for SHA256 support by using `git_hash::ObjectId` and `git_hash::oid`**
* eventually there will be the need to support both Sha1 and Sha256. We anticipate it by using the `Id` type instead
of slices or arrays of 20 bytes. This way, eventually we can support multiple hash digest sizes.
* Right now it's unclear how Sha256 is going to work in git, so we only support Sha1 for now. It might be an avenue to proactively

2
git-features/src/hash.rs

@ -72,7 +72,7 @@ pub use crc::crc32::checksum_ieee as crc32;
/// # Note
///
/// * Only available with the `git-object` feature enabled due to usage of the [`git_hash::Kind`] enum and the
/// [`git_hash::owned::Digest`] return value.
/// [`git_hash::ObjectId`] return value.
/// * [Interrupts][crate::interrupt] are supported.
pub fn bytes_of_file(
path: impl AsRef<std::path::Path>,

2
git-odb/src/loose/db/iter.rs

@ -13,7 +13,7 @@ pub enum Error {
impl Db {
/// Return an iterator over all objects contained in the database.
///
/// The [`Id`][git_hash::Id]s returned by the iterator can typically be used in the [`locate(…)`][Db::locate()] method.
/// The [`Id`][git_hash::ObjectId]s returned by the iterator can typically be used in the [`locate(…)`][Db::locate()] method.
/// _Note_ that the result is not sorted or stable, thus ordering can change between runs.
pub fn iter(&self) -> impl Iterator<Item = Result<git_hash::ObjectId, Error>> {
use std::path::Component::Normal;

2
git-odb/src/pack/index/access.rs

@ -11,7 +11,7 @@ const N32_HIGH_BIT: u32 = 1 << 31;
pub(crate) type PackOffset = u64;
/// Represents an entry within a pack index file, effectively mapping object [`IDs`][git_hash::Id] to pack data file locations.
/// Represents an entry within a pack index file, effectively mapping object [`IDs`][git_hash::ObjectId] to pack data file locations.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Entry {

14
git-protocol/src/fetch/arguments.rs

@ -64,22 +64,22 @@ impl Arguments {
/// Add the given `id` pointing to a commit to the 'want' list.
///
/// As such it should be included in the server response as it's not present on the client.
pub fn want(&mut self, id: git_hash::borrowed::Id<'_>) {
pub fn want(&mut self, id: impl AsRef<git_hash::oid>) {
match self.features_for_first_want.take() {
Some(features) => self.prefixed("want ", format!("{} {}", id, features.join(" "))),
None => self.prefixed("want ", id),
Some(features) => self.prefixed("want ", format!("{} {}", id.as_ref(), features.join(" "))),
None => self.prefixed("want ", id.as_ref()),
}
}
/// Add the given `id` pointing to a commit to the 'have' list.
///
/// As such it should _not_ be included in the server response as it's already present on the client.
pub fn have(&mut self, id: git_hash::borrowed::Id<'_>) {
self.haves.push(format!("have {}", id).into());
pub fn have(&mut self, id: impl AsRef<git_hash::oid>) {
self.haves.push(format!("have {}", id.as_ref()).into());
}
/// Add the given `id` pointing to a commit to the 'shallow' list.
pub fn shallow(&mut self, id: git_hash::borrowed::Id<'_>) {
pub fn shallow(&mut self, id: impl AsRef<git_hash::oid>) {
assert!(self.shallow, "'shallow' feature required for 'shallow <id>'");
self.prefixed("shallow ", id);
self.prefixed("shallow ", id.as_ref());
}
/// Deepen the commit history by `depth` amount of commits.
pub fn deepen(&mut self, depth: usize) {

30
git-protocol/src/fetch/tests/arguments.rs

@ -81,8 +81,8 @@ mod v1 {
let mut t = transport(&mut out, true);
let mut arguments = arguments_v1(["feature-a", "feature-b"].iter().cloned());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907").to_borrowed());
arguments.want(id("ff333369de1221f9bfbbe03a3a13e9a09bc1ffff").to_borrowed());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
arguments.want(id("ff333369de1221f9bfbbe03a3a13e9a09bc1ffff"));
arguments.send(&mut t, true).expect("sending to buffer to work");
assert_eq!(
out.as_bstr(),
@ -101,14 +101,14 @@ mod v1 {
let mut arguments = arguments_v1(["feature-a", "shallow", "deepen-since", "deepen-not"].iter().copied());
arguments.deepen(1);
arguments.shallow(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff").to_borrowed());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907").to_borrowed());
arguments.shallow(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff"));
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
arguments.deepen_since(12345);
arguments.deepen_not("refs/heads/main".into());
arguments.have(id("0000000000000000000000000000000000000000").to_borrowed());
arguments.have(id("0000000000000000000000000000000000000000"));
arguments.send(&mut t, false).expect("sending to buffer to work");
arguments.have(id("1111111111111111111111111111111111111111").to_borrowed());
arguments.have(id("1111111111111111111111111111111111111111"));
arguments.send(&mut t, true).expect("sending to buffer to work");
assert_eq!(
out.as_bstr(),
@ -137,11 +137,11 @@ mod v1 {
let mut arguments = arguments_v1(["feature-a", "shallow"].iter().copied());
arguments.deepen(1);
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907").to_borrowed());
arguments.have(id("0000000000000000000000000000000000000000").to_borrowed());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
arguments.have(id("0000000000000000000000000000000000000000"));
arguments.send(&mut t, false).expect("sending to buffer to work");
arguments.have(id("1111111111111111111111111111111111111111").to_borrowed());
arguments.have(id("1111111111111111111111111111111111111111"));
arguments.send(&mut t, true).expect("sending to buffer to work");
assert_eq!(
out.as_bstr(),
@ -168,8 +168,8 @@ mod v2 {
arguments.deepen(1);
arguments.deepen_relative();
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907").to_borrowed());
arguments.want(id("ff333369de1221f9bfbbe03a3a13e9a09bc1ffff").to_borrowed());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
arguments.want(id("ff333369de1221f9bfbbe03a3a13e9a09bc1ffff"));
arguments.send(&mut t, true).expect("sending to buffer to work");
assert_eq!(
out.as_bstr(),
@ -196,13 +196,13 @@ mod v2 {
arguments.deepen(1);
arguments.deepen_since(12345);
arguments.shallow(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff").to_borrowed());
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907").to_borrowed());
arguments.shallow(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff"));
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
arguments.deepen_not("refs/heads/main".into());
arguments.have(id("0000000000000000000000000000000000000000").to_borrowed());
arguments.have(id("0000000000000000000000000000000000000000"));
arguments.send(&mut t, false).expect("sending to buffer to work");
arguments.have(id("1111111111111111111111111111111111111111").to_borrowed());
arguments.have(id("1111111111111111111111111111111111111111"));
arguments.send(&mut t, true).expect("sending to buffer to work");
assert_eq!(
out.as_bstr(),

2
git-protocol/tests/fetch/mod.rs

@ -15,7 +15,7 @@ struct CloneDelegate {
impl fetch::Delegate for CloneDelegate {
fn negotiate(&mut self, refs: &[Ref], arguments: &mut Arguments, _previous_result: Option<&Response>) -> Action {
for r in refs {
arguments.want(r.unpack().1.to_borrowed());
arguments.want(r.unpack().1);
}
Action::Close
}

4
gitoxide-core/src/pack/receive.rs

@ -58,10 +58,10 @@ impl<W: io::Write> git_protocol::fetch::Delegate for CloneDelegate<W> {
match self.ref_filter {
Some(ref_prefixes) => {
if ref_prefixes.iter().any(|prefix| path.starts_with_str(prefix)) {
arguments.want(id.to_borrowed());
arguments.want(id);
}
}
None => arguments.want(id.to_borrowed()),
None => arguments.want(id),
}
}
Action::Close

Loading…
Cancel
Save