11use anyhow:: bail;
22use gix:: bstr:: { BStr , BString , ByteSlice } ;
3- use gix:: status:: index_worktree:: Item ;
3+ use gix:: status:: { self , index_worktree} ;
44use gix_status:: index_as_worktree:: { Change , Conflict , EntryStatus } ;
55use std:: path:: Path ;
66
@@ -109,21 +109,54 @@ pub fn show(
109109 }
110110 None => gix:: status:: Submodule :: AsConfigured { check_dirty : false } ,
111111 } )
112- . into_index_worktree_iter ( pathspecs) ?;
112+ . into_iter ( pathspecs) ?;
113113
114114 for item in iter. by_ref ( ) {
115115 let item = item?;
116116 match item {
117- Item :: Modification {
117+ status:: Item :: TreeIndex ( change) => {
118+ let ( location, _, _, _) = change. fields ( ) ;
119+ let status = match change {
120+ gix:: diff:: index:: Change :: Addition { .. } => "A" ,
121+ gix:: diff:: index:: Change :: Deletion { .. } => "D" ,
122+ gix:: diff:: index:: Change :: Modification { .. } => "M" ,
123+ gix:: diff:: index:: Change :: Rewrite {
124+ ref source_location, ..
125+ } => {
126+ let source_location = gix:: path:: from_bstr ( source_location. as_ref ( ) ) ;
127+ let source_location = gix:: path:: relativize_with_prefix ( & source_location, prefix) ;
128+ writeln ! (
129+ out,
130+ "{status: >2} {source_rela_path} → {dest_rela_path}" ,
131+ status = "R" ,
132+ source_rela_path = source_location. display( ) ,
133+ dest_rela_path =
134+ gix:: path:: relativize_with_prefix( & gix:: path:: from_bstr( location) , prefix) . display( ) ,
135+ ) ?;
136+ continue ;
137+ }
138+ gix:: diff:: index:: Change :: Unmerged { .. } => {
139+ // Unmerged entries from the worktree-index are displayed as part of the index-worktree comparison.
140+ // Here we have nothing to do with them and can ignore.
141+ continue ;
142+ }
143+ } ;
144+ writeln ! (
145+ out,
146+ "{status: >2} {rela_path}" ,
147+ rela_path = gix:: path:: relativize_with_prefix( & gix:: path:: from_bstr( location) , prefix) . display( ) ,
148+ ) ?;
149+ }
150+ status:: Item :: IndexWorktree ( index_worktree:: Item :: Modification {
118151 entry : _,
119152 entry_index : _,
120153 rela_path,
121154 status,
122- } => print_index_entry_status ( & mut out, prefix, rela_path. as_ref ( ) , status) ?,
123- Item :: DirectoryContents {
155+ } ) => print_index_entry_status ( & mut out, prefix, rela_path. as_ref ( ) , status) ?,
156+ status :: Item :: IndexWorktree ( index_worktree :: Item :: DirectoryContents {
124157 entry,
125158 collapsed_directory_status,
126- } => {
159+ } ) => {
127160 if collapsed_directory_status. is_none ( ) {
128161 writeln ! (
129162 out,
@@ -139,12 +172,12 @@ pub fn show(
139172 ) ?;
140173 }
141174 }
142- Item :: Rewrite {
175+ status :: Item :: IndexWorktree ( index_worktree :: Item :: Rewrite {
143176 source,
144177 dirwalk_entry,
145178 copy : _, // TODO: how to visualize copies?
146179 ..
147- } => {
180+ } ) => {
148181 // TODO: handle multi-status characters, there can also be modifications at the same time as determined by their ID and potentially diffstats.
149182 writeln ! (
150183 out,
@@ -175,9 +208,8 @@ pub fn show(
175208 writeln ! ( err, "{outcome:#?}" , outcome = out. index_worktree) . ok ( ) ;
176209 }
177210
178- writeln ! ( err, "\n head -> index isn't implemented yet" ) ?;
179- progress. init ( Some ( out. index . entries ( ) . len ( ) ) , gix:: progress:: count ( "files" ) ) ;
180- progress. set ( out. index . entries ( ) . len ( ) ) ;
211+ progress. init ( Some ( out. worktree_index . entries ( ) . len ( ) ) , gix:: progress:: count ( "files" ) ) ;
212+ progress. set ( out. worktree_index . entries ( ) . len ( ) ) ;
181213 progress. show_throughput ( start) ;
182214 Ok ( ( ) )
183215}
0 commit comments