Skip to content

git-object refactor #177

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

Merged
merged 18 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cargo-smart-release/src/command/release/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use cargo_metadata::{
camino::{Utf8Component, Utf8Path},
Package,
};
use git_repository::easy::object;
use git_repository::{easy::object, prelude::ReferenceAccessExt, refs};

use super::{tag_name_for, utils::will, Context, Oid, Options};
use git_repository::{prelude::ReferenceAccessExt, refs};

fn is_top_level_package(manifest_path: &Utf8Path, shared: &git_repository::Easy) -> bool {
manifest_path
Expand Down
6 changes: 3 additions & 3 deletions experiments/diffing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use git_repository::{
diff,
easy::object,
hash::{oid, ObjectId},
objs::{bstr::BStr, immutable},
objs::{bstr::BStr, TreeRefIter},
odb,
prelude::*,
refs::file::loose::reference::peel,
Expand Down Expand Up @@ -254,14 +254,14 @@ where
}
};

fn find_tree_iter<'b, L>(id: &oid, buf: &'b mut Vec<u8>, mut find: L) -> Option<immutable::TreeIter<'b>>
fn find_tree_iter<'b, L>(id: &oid, buf: &'b mut Vec<u8>, mut find: L) -> Option<TreeRefIter<'b>>
where
L: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<odb::data::Object<'a>>,
{
find(id, buf).and_then(|o| o.into_tree_iter())
}

fn tree_iter_by_commit<'b, L>(id: &oid, buf: &'b mut Vec<u8>, mut find: L) -> immutable::TreeIter<'b>
fn tree_iter_by_commit<'b, L>(id: &oid, buf: &'b mut Vec<u8>, mut find: L) -> TreeRefIter<'b>
where
L: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<odb::data::Object<'a>>,
{
Expand Down
10 changes: 5 additions & 5 deletions experiments/traversal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::anyhow;
use dashmap::DashSet;
use git_repository::{
hash::ObjectId,
objs::{bstr::BStr, immutable::tree::Entry},
objs::{bstr::BStr, tree::EntryRef},
odb,
prelude::*,
refs::file::loose::reference::peel,
Expand Down Expand Up @@ -186,7 +186,7 @@ where
fn push_back_tracked_path_component(&mut self, _component: &BStr) {}
fn push_path_component(&mut self, _component: &BStr) {}
fn pop_path_component(&mut self) {}
fn visit_tree(&mut self, entry: &Entry<'_>) -> Action {
fn visit_tree(&mut self, entry: &EntryRef<'_>) -> Action {
self.entries += 1;
let inserted = self.seen.insert(entry.oid.to_owned());
if !inserted {
Expand All @@ -195,7 +195,7 @@ where
tree::visit::Action::Continue
}
}
fn visit_nontree(&mut self, entry: &Entry<'_>) -> Action {
fn visit_nontree(&mut self, entry: &EntryRef<'_>) -> Action {
self.entries += 1;
self.seen.insert(entry.oid.to_owned());
tree::visit::Action::Continue
Expand Down Expand Up @@ -241,7 +241,7 @@ where
fn push_back_tracked_path_component(&mut self, _component: &BStr) {}
fn push_path_component(&mut self, _component: &BStr) {}
fn pop_path_component(&mut self) {}
fn visit_tree(&mut self, entry: &Entry<'_>) -> Action {
fn visit_tree(&mut self, entry: &EntryRef<'_>) -> Action {
self.entries += 1;
let inserted = self.seen.insert(entry.oid.to_owned());
if !inserted {
Expand All @@ -250,7 +250,7 @@ where
tree::visit::Action::Continue
}
}
fn visit_nontree(&mut self, entry: &Entry<'_>) -> Action {
fn visit_nontree(&mut self, entry: &EntryRef<'_>) -> Action {
self.entries += 1;
self.seen.insert(entry.oid.to_owned());
tree::visit::Action::Continue
Expand Down
2 changes: 1 addition & 1 deletion git-actor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This crate provides ways of identifying an actor within the git repository both in shared/signature_ref and mutable variants.
//! This crate provides ways of identifying an actor within the git repository both in shared/mutable and mutable variants.
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms, missing_docs)]
use bstr::{BStr, BString};
Expand Down
2 changes: 1 addition & 1 deletion git-actor/src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod convert {
}

impl Signature {
/// Borrow this instance as signature_ref
/// Borrow this instance as immutable
pub fn to_ref(&self) -> SignatureRef<'_> {
SignatureRef {
name: self.name.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion git-config/src/file/git_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'event> GitConfig<'event> {
.map_err(|_| GitConfigError::FailedConversion)
}

/// Returns an signature_ref section reference.
/// Returns an immutable section reference.
///
/// # Errors
///
Expand Down
2 changes: 1 addition & 1 deletion git-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doctest = false

[dependencies]
git-hash = { version = "^0.5.0", path = "../git-hash" }
git-object = { version ="0.12.0", path = "../git-object" }
git-object = { version ="^0.13.0", path = "../git-object" }
quick-error = "2.0.0"

[dev-dependencies]
Expand Down
27 changes: 13 additions & 14 deletions git-diff/src/tree/changes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{borrow::BorrowMut, collections::VecDeque};

use git_hash::{oid, ObjectId};
use git_object::immutable;
use quick_error::quick_error;

use crate::{
Expand All @@ -20,7 +19,7 @@ quick_error! {
Cancelled {
display("The delegate cancelled the operation")
}
EntriesDecode(err: immutable::object::decode::Error) {
EntriesDecode(err: git_object::decode::Error) {
display("tree entries could not be decoded.")
from()
source(err)
Expand Down Expand Up @@ -54,13 +53,13 @@ impl<'a> tree::Changes<'a> {
/// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/git-object/src/mutable/tree.rs#L52-L55
pub fn needed_to_obtain<FindFn, R, StateMut>(
mut self,
other: immutable::TreeIter<'_>,
other: git_object::TreeRefIter<'_>,
mut state: StateMut,
mut find: FindFn,
delegate: &mut R,
) -> Result<(), Error>
where
FindFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>,
FindFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<git_object::TreeRefIter<'b>>,
R: tree::Visit,
StateMut: BorrowMut<tree::State>,
{
Expand Down Expand Up @@ -120,7 +119,7 @@ impl<'a> tree::Changes<'a> {
}

fn delete_entry_schedule_recursion<R: tree::Visit>(
entry: immutable::tree::Entry<'_>,
entry: git_object::tree::EntryRef<'_>,
queue: &mut VecDeque<TreeInfoPair>,
delegate: &mut R,
) -> Result<(), Error> {
Expand All @@ -143,7 +142,7 @@ fn delete_entry_schedule_recursion<R: tree::Visit>(
}

fn add_entry_schedule_recursion<R: tree::Visit>(
entry: immutable::tree::Entry<'_>,
entry: git_object::tree::EntryRef<'_>,
queue: &mut VecDeque<TreeInfoPair>,
delegate: &mut R,
) -> Result<(), Error> {
Expand All @@ -165,9 +164,9 @@ fn add_entry_schedule_recursion<R: tree::Visit>(
Ok(())
}
fn catchup_rhs_with_lhs<R: tree::Visit>(
rhs_entries: &mut IteratorType<immutable::TreeIter<'_>>,
lhs: immutable::tree::Entry<'_>,
rhs: immutable::tree::Entry<'_>,
rhs_entries: &mut IteratorType<git_object::TreeRefIter<'_>>,
lhs: git_object::tree::EntryRef<'_>,
rhs: git_object::tree::EntryRef<'_>,
queue: &mut VecDeque<TreeInfoPair>,
delegate: &mut R,
) -> Result<(), Error> {
Expand Down Expand Up @@ -205,9 +204,9 @@ fn catchup_rhs_with_lhs<R: tree::Visit>(
}

fn catchup_lhs_with_rhs<R: tree::Visit>(
lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>,
lhs: immutable::tree::Entry<'_>,
rhs: immutable::tree::Entry<'_>,
lhs_entries: &mut IteratorType<git_object::TreeRefIter<'_>>,
lhs: git_object::tree::EntryRef<'_>,
rhs: git_object::tree::EntryRef<'_>,
queue: &mut VecDeque<TreeInfoPair>,
delegate: &mut R,
) -> Result<(), Error> {
Expand Down Expand Up @@ -245,8 +244,8 @@ fn catchup_lhs_with_rhs<R: tree::Visit>(
}

fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
lhs: immutable::tree::Entry<'_>,
rhs: immutable::tree::Entry<'_>,
lhs: git_object::tree::EntryRef<'_>,
rhs: git_object::tree::EntryRef<'_>,
queue: &mut VecDeque<TreeInfoPair>,
delegate: &mut R,
) -> Result<(), Error> {
Expand Down
6 changes: 3 additions & 3 deletions git-diff/src/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::VecDeque;

use git_hash::ObjectId;
use git_object::immutable;
use git_object::TreeRefIter;

/// The state required to visit [Changes] to be instantiated with `State::default()`.
#[derive(Default, Clone)]
Expand All @@ -22,11 +22,11 @@ impl State {
}

/// An iterator over changes of a tree, instantiated using `Changes::from(…)`.
pub struct Changes<'a>(Option<immutable::TreeIter<'a>>);
pub struct Changes<'a>(Option<TreeRefIter<'a>>);

impl<'a, T> From<T> for Changes<'a>
where
T: Into<Option<immutable::TreeIter<'a>>>,
T: Into<Option<TreeRefIter<'a>>>,
{
fn from(v: T) -> Self {
Changes(v.into())
Expand Down
4 changes: 2 additions & 2 deletions git-diff/tests/visit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod changes {
mod to_obtain_tree {
use git_diff::tree::{recorder, recorder::Change::*};
use git_hash::{oid, ObjectId};
use git_object::{bstr::ByteSlice, immutable, tree::EntryMode};
use git_object::{bstr::ByteSlice, tree::EntryMode, TreeRefIter};
use git_odb::{linked, pack, Find};

use crate::hex_to_id;
Expand All @@ -22,7 +22,7 @@ mod changes {
db: &linked::Store,
commit: &oid,
buf: &'a mut Vec<u8>,
) -> crate::Result<immutable::TreeIter<'a>> {
) -> crate::Result<TreeRefIter<'a>> {
let tree_id = db
.find(commit, buf, &mut pack::cache::Never)?
.ok_or_else(|| format!("start commit {:?} to be present", commit))?
Expand Down
2 changes: 1 addition & 1 deletion git-object/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-object"
version = "0.12.2"
version = "0.13.0"
description = "Immutable and mutable git objects with decoding and encoding support"
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
repository = "https://github.com/Byron/gitoxide"
Expand Down
17 changes: 17 additions & 0 deletions git-object/src/blob.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{convert::Infallible, io};

use crate::{Blob, BlobRef};

impl Blob {
/// Write the blobs data to `out` verbatim.
pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
out.write_all(&self.data)
}
}

impl<'a> BlobRef<'a> {
/// Instantiate a `Blob` from the given `data`, which is used as-is.
pub fn from_bytes(data: &[u8]) -> Result<BlobRef<'_>, Infallible> {
Ok(BlobRef { data })
}
}
41 changes: 0 additions & 41 deletions git-object/src/commit.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use nom::{
};
use smallvec::SmallVec;

use crate::{
immutable::{parse, parse::NL, Commit},
BStr, ByteSlice,
};
use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef};

pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
if i.is_empty() {
Expand All @@ -28,7 +25,9 @@ pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]
Ok((&[], i.as_bstr()))
}

pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], Commit<'_>, E> {
pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
i: &'a [u8],
) -> IResult<&'a [u8], CommitRef<'_>, E> {
let (i, tree) = context("tree <40 lowercase hex char>", |i| {
parse::header_field(i, b"tree", parse::hex_hash)
})(i)?;
Expand Down Expand Up @@ -59,7 +58,7 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8])

Ok((
i,
Commit {
CommitRef {
tree,
parents: SmallVec::from(parents),
author,
Expand Down
Loading