33#![ forbid( unsafe_code) ]
44
55use std:: {
6- collections:: BTreeMap ,
76 ops:: { Add , AddAssign , Range , SubAssign } ,
87 path:: PathBuf ,
98} ;
@@ -223,30 +222,6 @@ impl UnblamedHunk {
223222 }
224223}
225224
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-
250225#[ derive( Clone , Debug , PartialEq ) ]
251226pub enum Change {
252227 Unchanged ( Range < u32 > ) ,
@@ -767,7 +742,6 @@ pub fn blame_file<E>(
767742 traverse : impl IntoIterator < Item = Result < gix_traverse:: commit:: Info , E > > ,
768743 resource_cache : & mut gix_diff:: blob:: Platform ,
769744 worktree_path : PathBuf ,
770- start_id : ObjectId ,
771745 file_path : & BStr ,
772746) -> Result < Vec < BlameEntry > , E > {
773747 // TODO
@@ -796,33 +770,24 @@ pub fn blame_file<E>(
796770 // TODO Verify that `imara-diff` tokenizes lines the same way `lines` does.
797771 let number_of_lines = std:: fs:: read_to_string ( absolute_path) . unwrap ( ) . lines ( ) . count ( ) ;
798772
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+ ) ] ;
804777 let mut out: Vec < BlameEntry > = vec ! [ ] ;
805778
806779 for item in traverse {
807780 let item = item?;
808781 let suspect = item. id ;
809782
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-
818783 let parent_ids = item. parent_ids ;
819784 if parent_ids. is_empty ( ) {
820785 // I’m not entirely sure if this is correct yet. `suspect`, at this point, is the `id` of
821786 // the last `item` that was yielded by `traverse`, so it makes sense to assign the
822787 // remaining lines to it, even though we don’t explicitly check whether that is true
823788 // here. We could perhaps use `needed_to_obtain` to compare `suspect` against an empty
824789 // tree to validate this assumption.
825- out. extend ( hunks_to_blame . iter ( ) . map ( |hunk| {
790+ out. extend ( lines_to_blame . iter ( ) . map ( |hunk| {
826791 BlameEntry :: new (
827792 hunk. range_in_blamed_file . clone ( ) ,
828793 // TODO
@@ -833,6 +798,8 @@ pub fn blame_file<E>(
833798 )
834799 } ) ) ;
835800
801+ lines_to_blame = vec ! [ ] ;
802+
836803 break ;
837804 }
838805
@@ -846,16 +813,14 @@ pub fn blame_file<E>(
846813
847814 let [ ref modification] : [ gix_diff:: tree:: recorder:: Change ] = changes_for_file_path[ ..] else {
848815 // None of the changes affected the file we’re currently blaming.
849- unblamed_hunk_recorder. add_hunks ( last_parent_id, hunks_to_blame) ;
850-
851816 continue ;
852817 } ;
853818
854819 match modification {
855820 gix_diff:: tree:: recorder:: Change :: Addition { .. } => {
856821 // Every line that has not been blamed yet on a commit, is expected to have been
857822 // 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| {
859824 BlameEntry :: new (
860825 hunk. range_in_blamed_file . clone ( ) ,
861826 // TODO
@@ -866,20 +831,20 @@ pub fn blame_file<E>(
866831 )
867832 } ) ) ;
868833
834+ lines_to_blame = vec ! [ ] ;
835+
869836 break ;
870837 }
871838 gix_diff:: tree:: recorder:: Change :: Deletion { .. } => todo ! ( ) ,
872839 gix_diff:: tree:: recorder:: Change :: Modification { previous_oid, oid, .. } => {
873840 let changes = get_changes ( & odb, resource_cache, * oid, * previous_oid, file_path) ;
874841
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) ;
878843 }
879844 }
880845 }
881846
882- assert ! ( unblamed_hunk_recorder . hunks . is_empty ( ) ) ;
847+ assert_eq ! ( lines_to_blame , vec! [ ] ) ;
883848
884849 // I don’t know yet whether it would make sense to use a data structure instead that preserves
885850 // order on insertion.
0 commit comments