Skip to content

Commit c4b14c1

Browse files
committed
[commitgraph] refactor
1 parent 6f90bee commit c4b14c1

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

git-commitgraph/src/file/access.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
/// Access
1010
impl File {
11-
/// Returns the commit data for the commit located at the given lex position.
11+
/// Returns the commit data for the commit located at the given lexigraphical position.
1212
///
1313
/// `pos` must range from 0 to self.num_commits().
1414
///
@@ -23,13 +23,13 @@ impl File {
2323
HashKind::Sha1
2424
}
2525

26-
// copied from git-odb/src/pack/index/access.rs
2726
/// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes.
2827
/// The position ranges from 0 to self.num_commits()
28+
// copied from git-odb/src/pack/index/access.rs
2929
pub fn id_at(&self, pos: file::Position) -> borrowed::Id<'_> {
3030
assert!(
3131
pos.0 < self.num_commits(),
32-
"expected lex position less than {}, got {}",
32+
"expected lexigraphical position less than {}, got {}",
3333
self.num_commits(),
3434
pos.0
3535
);
@@ -85,7 +85,7 @@ impl File {
8585

8686
/// Returns the number of commits in this graph file.
8787
///
88-
/// The maximum valid `Lexfile::Position` that can be used with this file is one less than
88+
/// The maximum valid `file::Position` that can be used with this file is one less than
8989
/// `num_commits()`.
9090
pub fn num_commits(&self) -> u32 {
9191
self.fan[255]
@@ -101,7 +101,7 @@ impl File {
101101
pub(crate) fn commit_data_bytes(&self, pos: file::Position) -> &[u8] {
102102
assert!(
103103
pos.0 < self.num_commits(),
104-
"expected lex position less than {}, got {}",
104+
"expected lexigraphical position less than {}, got {}",
105105
self.num_commits(),
106106
pos.0
107107
);

git-commitgraph/src/file/commit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
4545

4646
pub struct Commit<'a> {
4747
file: &'a File,
48-
lex_pos: file::Position,
48+
pos: file::Position,
4949
// We can parse the below fields lazily if needed.
5050
commit_timestamp: u64,
5151
generation: u32,
@@ -59,7 +59,7 @@ impl<'a> Commit<'a> {
5959
let bytes = file.commit_data_bytes(pos);
6060
Commit {
6161
file,
62-
lex_pos: pos,
62+
pos,
6363
root_tree_id: borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"),
6464
parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])),
6565
parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])),
@@ -94,7 +94,7 @@ impl<'a> Commit<'a> {
9494
}
9595

9696
pub fn id(&self) -> borrowed::Id<'_> {
97-
self.file.id_at(self.lex_pos)
97+
self.file.id_at(self.pos)
9898
}
9999

100100
pub fn parent1(&self) -> Result<Option<graph::Position>, Error> {
@@ -112,7 +112,7 @@ impl<'a> Debug for Commit<'a> {
112112
f,
113113
"Commit {{ id: {}, lex_pos: {}, generation: {}, root_tree_id: {}, parent1: {:?}, parent2: {:?} }}",
114114
self.id(),
115-
self.lex_pos,
115+
self.pos,
116116
self.generation(),
117117
self.root_tree_id(),
118118
self.parent1,
@@ -125,7 +125,7 @@ impl<'a> Eq for Commit<'a> {}
125125

126126
impl<'a> PartialEq for Commit<'a> {
127127
fn eq(&self, other: &Self) -> bool {
128-
self.file as *const File == other.file as *const File && self.lex_pos == other.lex_pos
128+
self.file as *const File == other.file as *const File && self.pos == other.pos
129129
}
130130
}
131131

git-commitgraph/src/graph/access.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ use git_object::borrowed;
88
impl Graph {
99
pub fn commit_at(&self, pos: graph::Position) -> Commit<'_> {
1010
let r = self.lookup_by_pos(pos);
11-
r.file.commit_at(r.lex_pos)
11+
r.file.commit_at(r.pos)
1212
}
1313

1414
pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> {
1515
let r = self.lookup_by_id(id)?;
16-
Some(r.file.commit_at(r.lex_pos))
16+
Some(r.file.commit_at(r.file_pos))
1717
}
1818

1919
pub fn id_at(&self, pos: graph::Position) -> borrowed::Id<'_> {
2020
let r = self.lookup_by_pos(pos);
21-
r.file.id_at(r.lex_pos)
21+
r.file.id_at(r.pos)
2222
}
2323

2424
/// Iterate over commits in unsorted order.
@@ -48,7 +48,7 @@ impl Graph {
4848
if let Some(lex_pos) = file.lookup(id) {
4949
return Some(LookupByIdResult {
5050
file,
51-
lex_pos,
51+
file_pos: lex_pos,
5252
graph_pos: graph::Position(current_file_start + lex_pos.0),
5353
});
5454
}
@@ -65,7 +65,7 @@ impl Graph {
6565
None => {
6666
return LookupByPositionResult {
6767
file,
68-
lex_pos: file::Position(remaining),
68+
pos: file::Position(remaining),
6969
}
7070
}
7171
}
@@ -78,11 +78,11 @@ impl Graph {
7878
struct LookupByIdResult<'a> {
7979
pub file: &'a File,
8080
pub graph_pos: graph::Position,
81-
pub lex_pos: file::Position,
81+
pub file_pos: file::Position,
8282
}
8383

8484
#[derive(Clone)]
8585
struct LookupByPositionResult<'a> {
8686
pub file: &'a File,
87-
pub lex_pos: file::Position,
87+
pub pos: file::Position,
8888
}

tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* **Questions**
2929
* ~~How can `Commit` return Graph positions? It doesn't seem to learn about an offset.~~
3030
* Parent IDs are indeed specified as graph positions, not file positions, as they may be in previous commit graph files.
31-
* **Still to be done**
31+
* **Future Work**
3232
* A plumbing command to extract some value from the current implementation, maybe statistics, or verification
3333
* Application of the command above in a stress test
3434
* **git-config**

0 commit comments

Comments
 (0)