Skip to content

Commit a5b1d73

Browse files
committed
Merge branch 'pierrechevalier83/main'
2 parents c6a6902 + 0a6d888 commit a5b1d73

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

git-object/src/commit/write.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ impl crate::WriteTo for Commit {
2323
out.write_all(&self.message)
2424
}
2525

26+
fn kind(&self) -> Kind {
27+
Kind::Commit
28+
}
29+
2630
fn size(&self) -> usize {
2731
let hash_in_hex = self.tree.kind().len_in_hex();
2832
b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */
@@ -45,10 +49,6 @@ impl crate::WriteTo for Commit {
4549
+ 1 /* nl */
4650
+ self.message.len()
4751
}
48-
49-
fn kind(&self) -> Kind {
50-
Kind::Commit
51-
}
5252
}
5353

5454
impl<'a> crate::WriteTo for CommitRef<'a> {
@@ -70,6 +70,10 @@ impl<'a> crate::WriteTo for CommitRef<'a> {
7070
out.write_all(self.message)
7171
}
7272

73+
fn kind(&self) -> Kind {
74+
Kind::Commit
75+
}
76+
7377
fn size(&self) -> usize {
7478
let hash_in_hex = self.tree().kind().len_in_hex();
7579
b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */
@@ -92,8 +96,4 @@ impl<'a> crate::WriteTo for CommitRef<'a> {
9296
+ 1 /* nl */
9397
+ self.message.len()
9498
}
95-
96-
fn kind(&self) -> Kind {
97-
Kind::Commit
98-
}
9999
}

git-object/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct CommitRef<'a> {
7676
#[cfg_attr(feature = "serde1", serde(borrow))]
7777
pub tree: &'a BStr,
7878
/// HEX hash of each parent commit. Empty for first commit in repository.
79-
pub parents: SmallVec<[&'a BStr; 2]>,
79+
pub parents: SmallVec<[&'a BStr; 1]>,
8080
/// Who wrote this commit. Name and email might contain whitespace and are not trimmed to ensure round-tripping.
8181
///
8282
/// Use the [`author()`][CommitRef::author()] method to received a trimmed version of it.
@@ -136,7 +136,7 @@ pub struct TagRef<'a> {
136136
#[cfg_attr(feature = "serde1", serde(borrow))]
137137
pub target: &'a BStr,
138138
/// The kind of object that `target` points to.
139-
pub target_kind: crate::Kind,
139+
pub target_kind: Kind,
140140
/// The name of the tag, e.g. "v1.0".
141141
pub name: &'a BStr,
142142
/// The author of the tag.
@@ -162,7 +162,7 @@ pub struct Tag {
162162
/// The hash this tag is pointing to.
163163
pub target: git_hash::ObjectId,
164164
/// The kind of object this tag is pointing to.
165-
pub target_kind: crate::Kind,
165+
pub target_kind: Kind,
166166
/// The name of the tag, e.g. "v1.0".
167167
pub name: BString,
168168
/// The tags author.

git-object/src/object/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl From<TagRef<'_>> for Tag {
1313
pgp_signature,
1414
} = other;
1515
Tag {
16-
target: git_hash::ObjectId::from_hex(target).expect("40 bytes hex sha1"),
16+
target: git_hash::ObjectId::from_hex(target).expect("prior parser validation"),
1717
name: name.to_owned(),
1818
target_kind,
1919
message: message.to_owned(),
@@ -35,10 +35,10 @@ impl From<CommitRef<'_>> for Commit {
3535
extra_headers,
3636
} = other;
3737
Commit {
38-
tree: git_hash::ObjectId::from_hex(tree).expect("40 bytes hex sha1"),
38+
tree: git_hash::ObjectId::from_hex(tree).expect("prior parser validation"),
3939
parents: parents
4040
.iter()
41-
.map(|parent| git_hash::ObjectId::from_hex(parent).expect("40 bytes hex sha1"))
41+
.map(|parent| git_hash::ObjectId::from_hex(parent).expect("prior parser validation"))
4242
.collect(),
4343
author: author.into(),
4444
committer: committer.into(),

git-object/src/tag/write.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,36 @@ impl crate::WriteTo for Tag {
3131

3232
out.write_all(NL)?;
3333
if !self.message.is_empty() {
34-
out.write_all(&self.message)?;
34+
out.write_all(self.message.as_ref())?;
3535
}
36-
if let Some(ref message) = self.pgp_signature {
36+
if let Some(message) = &self.pgp_signature {
3737
out.write_all(NL)?;
38-
out.write_all(message)?;
38+
out.write_all(message.as_ref())?;
3939
}
4040
Ok(())
4141
}
4242

43+
fn kind(&self) -> Kind {
44+
Kind::Tag
45+
}
46+
4347
fn size(&self) -> usize {
4448
b"object".len() + 1 /* space */ + self.target.kind().len_in_hex() + 1 /* nl */
4549
+ b"type".len() + 1 /* space */ + self.target_kind.as_bytes().len() + 1 /* nl */
4650
+ b"tag".len() + 1 /* space */ + self.name.len() + 1 /* nl */
4751
+ self
48-
.tagger
49-
.as_ref()
50-
.map(|t| b"tagger".len() + 1 /* space */ + t.size() + 1 /* nl */)
51-
.unwrap_or(0)
52+
.tagger
53+
.as_ref()
54+
.map(|t| b"tagger".len() + 1 /* space */ + t.size() + 1 /* nl */)
55+
.unwrap_or(0)
5256
+ 1 /* nl */ + self.message.len()
53-
+ self.pgp_signature.as_ref().map(|m| 1 /* nl */ + m.len() ).unwrap_or(0)
54-
}
55-
56-
fn kind(&self) -> Kind {
57-
Kind::Tag
57+
+ self.pgp_signature.as_ref().map(|m| 1 /* nl */ + m.len()).unwrap_or(0)
5858
}
5959
}
6060

6161
impl<'a> crate::WriteTo for TagRef<'a> {
6262
fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
63-
encode::trusted_header_id(b"object", &self.target(), &mut out)?;
63+
encode::trusted_header_field(b"object", self.target, &mut out)?;
6464
encode::trusted_header_field(b"type", self.target_kind.as_bytes(), &mut out)?;
6565
encode::header_field(b"tag", validated_name(self.name)?, &mut out)?;
6666
if let Some(tagger) = &self.tagger {
@@ -78,6 +78,10 @@ impl<'a> crate::WriteTo for TagRef<'a> {
7878
Ok(())
7979
}
8080

81+
fn kind(&self) -> Kind {
82+
Kind::Tag
83+
}
84+
8185
fn size(&self) -> usize {
8286
b"object".len() + 1 /* space */ + self.target().kind().len_in_hex() + 1 /* nl */
8387
+ b"type".len() + 1 /* space */ + self.target_kind.as_bytes().len() + 1 /* nl */
@@ -90,10 +94,6 @@ impl<'a> crate::WriteTo for TagRef<'a> {
9094
+ 1 /* nl */ + self.message.len()
9195
+ self.pgp_signature.as_ref().map(|m| 1 /* nl */ + m.len()).unwrap_or(0)
9296
}
93-
94-
fn kind(&self) -> Kind {
95-
Kind::Tag
96-
}
9797
}
9898

9999
fn validated_name(name: &BStr) -> Result<&BStr, Error> {

git-repository/src/repository/object.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::TryInto;
22

3-
use git_hash::{oid, ObjectId};
3+
use git_hash::ObjectId;
44
use git_odb::{Find, FindExt, Write};
55
use git_ref::{
66
transaction::{LogChange, PreviousValue, RefLog},
@@ -106,13 +106,12 @@ impl crate::Repository {
106106
pub fn tag(
107107
&self,
108108
name: impl AsRef<str>,
109-
target: impl AsRef<oid>,
109+
target: impl AsRef<git_hash::oid>,
110110
target_kind: git_object::Kind,
111111
tagger: Option<git_actor::SignatureRef<'_>>,
112112
message: impl AsRef<str>,
113113
constraint: PreviousValue,
114114
) -> Result<Reference<'_>, tag::Error> {
115-
// NOTE: This could be more efficient if we use a TagRef instead.
116115
let tag = git_object::Tag {
117116
target: target.as_ref().into(),
118117
target_kind,

0 commit comments

Comments
 (0)