Skip to content

Commit bab5860

Browse files
committed
change!: rename fetch::Ref::path to fetch::Ref::full_ref_name. (#450)
Previously it was inaccurately named and described due to an insufficient understanding of the ref database.
1 parent 21420da commit bab5860

File tree

6 files changed

+59
-37
lines changed

6 files changed

+59
-37
lines changed

git-protocol/src/fetch/refs/mod.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ pub mod parse {
5050
pub enum Ref {
5151
/// A ref pointing to a `tag` object, which in turns points to an `object`, usually a commit
5252
Peeled {
53-
/// The path at which the ref is located, like `/refs/heads/main`.
54-
path: BString,
53+
/// The name at which the ref is located, like `refs/heads/main`.
54+
full_ref_name: BString,
5555
/// The hash of the tag the ref points to.
5656
tag: git_hash::ObjectId,
5757
/// The hash of the object the `tag` points to.
5858
object: git_hash::ObjectId,
5959
},
6060
/// A ref pointing to a commit object
6161
Direct {
62-
/// The path at which the ref is located, like `/refs/heads/main`.
63-
path: BString,
62+
/// The name at which the ref is located, like `refs/heads/main`.
63+
full_ref_name: BString,
6464
/// The hash of the object the ref points to.
6565
object: git_hash::ObjectId,
6666
},
6767
/// A symbolic ref pointing to `target` ref, which in turn points to an `object`
6868
Symbolic {
69-
/// The path at which the symbolic ref is located, like `/refs/heads/main`.
70-
path: BString,
69+
/// The name at which the symbolic ref is located, like `refs/heads/main`.
70+
full_ref_name: BString,
7171
/// The path of the ref the symbolic ref points to, see issue [#205] for details
7272
///
7373
/// [#205]: https://github.com/Byron/gitoxide/issues/205
@@ -78,13 +78,21 @@ pub enum Ref {
7878
}
7979

8080
impl Ref {
81-
/// Provide shared fields referring to the ref itself, namely `(path, object id)`.
82-
/// In case of peeled refs, the tag object itself is returned as it is what the path refers to.
83-
pub fn unpack(&self) -> (&BString, &git_hash::ObjectId) {
81+
/// Provide shared fields referring to the ref itself, namely `(name, target)`.
82+
/// In case of peeled refs, the tag object itself is returned as it is what the ref directly refers to.
83+
pub fn unpack(&self) -> (&BString, &git_hash::oid) {
8484
match self {
85-
Ref::Direct { path, object, .. }
86-
| Ref::Peeled { path, tag: object, .. } // the tag acts as reference
87-
| Ref::Symbolic { path, object, .. } => (path, object),
85+
Ref::Direct {
86+
full_ref_name, object, ..
87+
}
88+
| Ref::Peeled {
89+
full_ref_name,
90+
tag: object,
91+
..
92+
}
93+
| Ref::Symbolic {
94+
full_ref_name, object, ..
95+
} => (full_ref_name, object),
8896
}
8997
}
9098
}

git-protocol/src/fetch/refs/shared.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,28 @@ impl From<InternalRef> for Ref {
99
path,
1010
target: Some(target),
1111
object,
12-
} => Ref::Symbolic { path, target, object },
12+
} => Ref::Symbolic {
13+
full_ref_name: path,
14+
target,
15+
object,
16+
},
1317
InternalRef::Symbolic {
1418
path,
1519
target: None,
1620
object,
17-
} => Ref::Direct { path, object },
18-
InternalRef::Peeled { path, tag, object } => Ref::Peeled { path, tag, object },
19-
InternalRef::Direct { path, object } => Ref::Direct { path, object },
21+
} => Ref::Direct {
22+
full_ref_name: path,
23+
object,
24+
},
25+
InternalRef::Peeled { path, tag, object } => Ref::Peeled {
26+
full_ref_name: path,
27+
tag,
28+
object,
29+
},
30+
InternalRef::Direct { path, object } => Ref::Direct {
31+
full_ref_name: path,
32+
object,
33+
},
2034
InternalRef::SymbolicForLookup { .. } => {
2135
unreachable!("this case should have been removed during processing")
2236
}
@@ -170,17 +184,17 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
170184
}
171185
match attribute {
172186
"peeled" => Ref::Peeled {
173-
path: path.into(),
187+
full_ref_name: path.into(),
174188
object: git_hash::ObjectId::from_hex(value.as_bytes())?,
175189
tag: id,
176190
},
177191
"symref-target" => match value {
178192
"(null)" => Ref::Direct {
179-
path: path.into(),
193+
full_ref_name: path.into(),
180194
object: id,
181195
},
182196
name => Ref::Symbolic {
183-
path: path.into(),
197+
full_ref_name: path.into(),
184198
object: id,
185199
target: name.into(),
186200
},
@@ -198,7 +212,7 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
198212
} else {
199213
Ref::Direct {
200214
object: id,
201-
path: path.into(),
215+
full_ref_name: path.into(),
202216
}
203217
})
204218
}

git-protocol/src/fetch/tests/refs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ async fn extract_references_from_v2_refs() {
1919
out,
2020
vec![
2121
Ref::Symbolic {
22-
path: "HEAD".into(),
22+
full_ref_name: "HEAD".into(),
2323
target: "refs/heads/main".into(),
2424
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
2525
},
2626
Ref::Direct {
27-
path: "MISSING_NAMESPACE_TARGET".into(),
27+
full_ref_name: "MISSING_NAMESPACE_TARGET".into(),
2828
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
2929
},
3030
Ref::Direct {
31-
path: "refs/heads/main".into(),
31+
full_ref_name: "refs/heads/main".into(),
3232
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
3333
},
3434
Ref::Peeled {
35-
path: "refs/tags/foo".into(),
35+
full_ref_name: "refs/tags/foo".into(),
3636
tag: oid("7fe1b98b39423b71e14217aa299a03b7c937d656"),
3737
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
3838
},
3939
Ref::Direct {
40-
path: "refs/tags/blaz".into(),
40+
full_ref_name: "refs/tags/blaz".into(),
4141
object: oid("7fe1b98b39423b71e14217aa299a03b7c937d6ff")
4242
},
4343
]
@@ -66,24 +66,24 @@ dce0ea858eef7ff61ad345cc5cdac62203fb3c10 refs/tags/git-commitgraph-v0.0.0
6666
out,
6767
vec![
6868
Ref::Symbolic {
69-
path: "HEAD".into(),
69+
full_ref_name: "HEAD".into(),
7070
target: "refs/heads/main".into(),
7171
object: oid("73a6868963993a3328e7d8fe94e5a6ac5078a944")
7272
},
7373
Ref::Direct {
74-
path: "MISSING_NAMESPACE_TARGET".into(),
74+
full_ref_name: "MISSING_NAMESPACE_TARGET".into(),
7575
object: oid("21c9b7500cb144b3169a6537961ec2b9e865be81")
7676
},
7777
Ref::Direct {
78-
path: "refs/heads/main".into(),
78+
full_ref_name: "refs/heads/main".into(),
7979
object: oid("73a6868963993a3328e7d8fe94e5a6ac5078a944")
8080
},
8181
Ref::Direct {
82-
path: "refs/pull/13/head".into(),
82+
full_ref_name: "refs/pull/13/head".into(),
8383
object: oid("8e472f9ccc7d745927426cbb2d9d077de545aa4e")
8484
},
8585
Ref::Peeled {
86-
path: "refs/tags/git-commitgraph-v0.0.0".into(),
86+
full_ref_name: "refs/tags/git-commitgraph-v0.0.0".into(),
8787
tag: oid("dce0ea858eef7ff61ad345cc5cdac62203fb3c10"),
8888
object: oid("21c9b7500cb144b3169a6537961ec2b9e865be81")
8989
},

git-protocol/tests/fetch/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod blocking_io {
169169
) -> io::Result<()> {
170170
for wanted in response.wanted_refs() {
171171
self.wanted_refs.push(fetch::Ref::Direct {
172-
path: wanted.path.clone(),
172+
full_ref_name: wanted.path.clone(),
173173
object: wanted.id,
174174
});
175175
}
@@ -230,7 +230,7 @@ mod async_io {
230230
) -> io::Result<()> {
231231
for wanted in response.wanted_refs() {
232232
self.wanted_refs.push(fetch::Ref::Direct {
233-
path: wanted.path.clone(),
233+
full_ref_name: wanted.path.clone(),
234234
object: wanted.id,
235235
});
236236
}

git-protocol/tests/fetch/v1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ async fn ls_remote() -> crate::Result {
4949
delegate.refs,
5050
vec![
5151
fetch::Ref::Symbolic {
52-
path: "HEAD".into(),
52+
full_ref_name: "HEAD".into(),
5353
object: oid("808e50d724f604f69ab93c6da2919c014667bedb"),
5454
target: "refs/heads/master".into()
5555
},
5656
fetch::Ref::Direct {
57-
path: "refs/heads/master".into(),
57+
full_ref_name: "refs/heads/master".into(),
5858
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
5959
}
6060
]

git-protocol/tests/fetch/v2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ async fn ls_remote() -> crate::Result {
7575
delegate.refs,
7676
vec![
7777
fetch::Ref::Symbolic {
78-
path: "HEAD".into(),
78+
full_ref_name: "HEAD".into(),
7979
object: oid("808e50d724f604f69ab93c6da2919c014667bedb"),
8080
target: "refs/heads/master".into()
8181
},
8282
fetch::Ref::Direct {
83-
path: "refs/heads/master".into(),
83+
full_ref_name: "refs/heads/master".into(),
8484
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
8585
}
8686
]
@@ -167,7 +167,7 @@ async fn ref_in_want() -> crate::Result {
167167
assert_eq!(
168168
delegate.wanted_refs,
169169
vec![fetch::Ref::Direct {
170-
path: "refs/heads/main".into(),
170+
full_ref_name: "refs/heads/main".into(),
171171
object: oid("9e320b9180e0b5580af68fa3255b7f3d9ecd5af0"),
172172
}]
173173
);

0 commit comments

Comments
 (0)