File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,13 +103,15 @@ impl<'repo> Tree<'repo> {
103103 {
104104 let mut iter = path. into_iter ( ) . peekable ( ) ;
105105 let mut data = gix_object:: Data :: new ( gix_object:: Kind :: Tree , & self . data ) ;
106+ let mut data_id = self . id ;
106107
107108 loop {
108109 data = match next_entry ( & mut iter, data) {
109110 ControlFlow :: Continue ( id) => {
110111 let res = self . repo . find ( & id, & mut self . data ) ?;
112+ data_id = id;
111113 if res. kind . is_tree ( ) {
112- self . id = id ;
114+ self . id = data_id ;
113115 }
114116 res
115117 }
@@ -120,9 +122,16 @@ impl<'repo> Tree<'repo> {
120122 } ) ;
121123 if let Some ( entry) = & mapped {
122124 if entry. mode ( ) . is_tree ( ) {
123- self . id = entry. object_id ( ) ;
125+ let id = entry. object_id ( ) ;
126+ self . repo . find ( & id, & mut self . data ) ?;
127+ data_id = id;
128+ self . id = data_id;
124129 }
125130 }
131+ if data_id != self . id {
132+ // Ensure that our data always matches our id, even if this means an extra lookup.
133+ self . repo . find ( & self . id , & mut self . data ) ?;
134+ }
126135 break Ok ( mapped) ;
127136 }
128137 }
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ mod peel_to_entry {
6262
6363 assert ! ( entry. mode( ) . is_tree( ) ) ;
6464 assert_eq ! ( tree. id( ) , dir_id) ;
65+ assert_eq ! (
66+ tree. find_entry( "c" ) . expect( "subtree entry" ) . filename( ) ,
67+ "c" ,
68+ "the data matches the id"
69+ ) ;
6570 Ok ( ( ) )
6671 }
6772
@@ -101,6 +106,11 @@ mod peel_to_entry {
101106
102107 assert ! ( entry. is_none( ) ) ;
103108 assert_eq ! ( tree. id( ) , root_id) ;
109+ assert_eq ! (
110+ tree. find_entry( "dir" ) . expect( "root tree entry" ) . filename( ) ,
111+ "dir" ,
112+ "the data matches the id"
113+ ) ;
104114 Ok ( ( ) )
105115 }
106116
@@ -114,6 +124,11 @@ mod peel_to_entry {
114124
115125 assert ! ( entry. is_none( ) ) ;
116126 assert_eq ! ( tree. id( ) , dir_id) ;
127+ assert_eq ! (
128+ tree. find_entry( "c" ) . expect( "nested tree entry" ) . filename( ) ,
129+ "c" ,
130+ "the data matches the id"
131+ ) ;
117132 Ok ( ( ) )
118133 }
119134
You can’t perform that action at this time.
0 commit comments