3
3
#![ forbid( unsafe_code) ]
4
4
5
5
use std:: {
6
- collections:: BTreeMap ,
7
6
ops:: { Add , AddAssign , Range , SubAssign } ,
8
7
path:: PathBuf ,
9
8
} ;
@@ -223,30 +222,6 @@ impl UnblamedHunk {
223
222
}
224
223
}
225
224
226
- struct UnblamedHunkRecorder {
227
- hunks : BTreeMap < ObjectId , Vec < UnblamedHunk > > ,
228
- }
229
-
230
- impl UnblamedHunkRecorder {
231
- fn new ( ) -> Self {
232
- Self { hunks : BTreeMap :: new ( ) }
233
- }
234
-
235
- fn add_hunk ( & mut self , object_id : ObjectId , unblamed_hunk : UnblamedHunk ) {
236
- self . hunks
237
- . entry ( object_id)
238
- . and_modify ( |unblamed_hunks| unblamed_hunks. push ( unblamed_hunk. clone ( ) ) )
239
- . or_insert_with ( || vec ! [ unblamed_hunk. clone( ) ] ) ;
240
- }
241
-
242
- fn add_hunks ( & mut self , object_id : ObjectId , new_unblamed_hunks : Vec < UnblamedHunk > ) {
243
- self . hunks
244
- . entry ( object_id)
245
- . and_modify ( |unblamed_hunks| unblamed_hunks. extend ( new_unblamed_hunks. clone ( ) ) )
246
- . or_insert_with ( || new_unblamed_hunks) ;
247
- }
248
- }
249
-
250
225
#[ derive( Clone , Debug , PartialEq ) ]
251
226
pub enum Change {
252
227
Unchanged ( Range < u32 > ) ,
@@ -767,7 +742,6 @@ pub fn blame_file<E>(
767
742
traverse : impl IntoIterator < Item = Result < gix_traverse:: commit:: Info , E > > ,
768
743
resource_cache : & mut gix_diff:: blob:: Platform ,
769
744
worktree_path : PathBuf ,
770
- start_id : ObjectId ,
771
745
file_path : & BStr ,
772
746
) -> Result < Vec < BlameEntry > , E > {
773
747
// TODO
@@ -796,33 +770,24 @@ pub fn blame_file<E>(
796
770
// TODO Verify that `imara-diff` tokenizes lines the same way `lines` does.
797
771
let number_of_lines = std:: fs:: read_to_string ( absolute_path) . unwrap ( ) . lines ( ) . count ( ) ;
798
772
799
- let mut unblamed_hunk_recorder = UnblamedHunkRecorder :: new ( ) ;
800
- unblamed_hunk_recorder. add_hunk (
801
- start_id,
802
- UnblamedHunk :: new ( 0 ..number_of_lines. try_into ( ) . unwrap ( ) , Offset :: Added ( 0 ) ) ,
803
- ) ;
773
+ let mut lines_to_blame: Vec < UnblamedHunk > = vec ! [ UnblamedHunk :: new(
774
+ 0 ..number_of_lines. try_into( ) . unwrap( ) ,
775
+ Offset :: Added ( 0 ) ,
776
+ ) ] ;
804
777
let mut out: Vec < BlameEntry > = vec ! [ ] ;
805
778
806
779
for item in traverse {
807
780
let item = item?;
808
781
let suspect = item. id ;
809
782
810
- // TODO
811
- // When we call `.remove(&suspect)`, we need to make sure that all commits that have
812
- // `suspect` as their parent have already been processed. `git` accomplishes that by
813
- // keeping unprocessed commits in a priority queue sorted by commit date.
814
- let Some ( hunks_to_blame) = unblamed_hunk_recorder. hunks . remove ( & suspect) else {
815
- continue ;
816
- } ;
817
-
818
783
let parent_ids = item. parent_ids ;
819
784
if parent_ids. is_empty ( ) {
820
785
// I’m not entirely sure if this is correct yet. `suspect`, at this point, is the `id` of
821
786
// the last `item` that was yielded by `traverse`, so it makes sense to assign the
822
787
// remaining lines to it, even though we don’t explicitly check whether that is true
823
788
// here. We could perhaps use `needed_to_obtain` to compare `suspect` against an empty
824
789
// tree to validate this assumption.
825
- out. extend ( hunks_to_blame . iter ( ) . map ( |hunk| {
790
+ out. extend ( lines_to_blame . iter ( ) . map ( |hunk| {
826
791
BlameEntry :: new (
827
792
hunk. range_in_blamed_file . clone ( ) ,
828
793
// TODO
@@ -833,6 +798,8 @@ pub fn blame_file<E>(
833
798
)
834
799
} ) ) ;
835
800
801
+ lines_to_blame = vec ! [ ] ;
802
+
836
803
break ;
837
804
}
838
805
@@ -846,16 +813,14 @@ pub fn blame_file<E>(
846
813
847
814
let [ ref modification] : [ gix_diff:: tree:: recorder:: Change ] = changes_for_file_path[ ..] else {
848
815
// None of the changes affected the file we’re currently blaming.
849
- unblamed_hunk_recorder. add_hunks ( last_parent_id, hunks_to_blame) ;
850
-
851
816
continue ;
852
817
} ;
853
818
854
819
match modification {
855
820
gix_diff:: tree:: recorder:: Change :: Addition { .. } => {
856
821
// Every line that has not been blamed yet on a commit, is expected to have been
857
822
// added when the file was added to the repository.
858
- out. extend ( hunks_to_blame . iter ( ) . map ( |hunk| {
823
+ out. extend ( lines_to_blame . iter ( ) . map ( |hunk| {
859
824
BlameEntry :: new (
860
825
hunk. range_in_blamed_file . clone ( ) ,
861
826
// TODO
@@ -866,20 +831,20 @@ pub fn blame_file<E>(
866
831
)
867
832
} ) ) ;
868
833
834
+ lines_to_blame = vec ! [ ] ;
835
+
869
836
break ;
870
837
}
871
838
gix_diff:: tree:: recorder:: Change :: Deletion { .. } => todo ! ( ) ,
872
839
gix_diff:: tree:: recorder:: Change :: Modification { previous_oid, oid, .. } => {
873
840
let changes = get_changes ( & odb, resource_cache, * oid, * previous_oid, file_path) ;
874
841
875
- let new_hunks_to_blame = process_changes ( & mut out, & hunks_to_blame, & changes, suspect) ;
876
-
877
- unblamed_hunk_recorder. add_hunks ( last_parent_id, new_hunks_to_blame. clone ( ) ) ;
842
+ lines_to_blame = process_changes ( & mut out, & lines_to_blame, & changes, suspect) ;
878
843
}
879
844
}
880
845
}
881
846
882
- assert ! ( unblamed_hunk_recorder . hunks . is_empty ( ) ) ;
847
+ assert_eq ! ( lines_to_blame , vec! [ ] ) ;
883
848
884
849
// I don’t know yet whether it would make sense to use a data structure instead that preserves
885
850
// order on insertion.
0 commit comments