@@ -30,11 +30,11 @@ pub async fn git_status(Query(query): Query<GitPathQuery>) -> AppResult<Json<Git
3030 let mut conflicts = vec ! [ ] ;
3131
3232 for line in stdout. lines ( ) {
33- if line. starts_with ( "# branch.head " ) {
34- branch = Some ( line [ 14 .. ] . to_string ( ) ) ;
35- } else if line. starts_with ( "# branch.ab " ) {
33+ if let Some ( stripped ) = line. strip_prefix ( "# branch.head " ) {
34+ branch = Some ( stripped . to_string ( ) ) ;
35+ } else if let Some ( stripped ) = line. strip_prefix ( "# branch.ab " ) {
3636 // Parse ahead/behind: # branch.ab +1 -2
37- let parts: Vec < & str > = line [ 12 .. ] . split_whitespace ( ) . collect ( ) ;
37+ let parts: Vec < & str > = stripped . split_whitespace ( ) . collect ( ) ;
3838 if parts. len ( ) >= 2 {
3939 ahead = parts[ 0 ] . trim_start_matches ( '+' ) . parse ( ) . ok ( ) ;
4040 behind = parts[ 1 ] . trim_start_matches ( '-' ) . parse ( ) . ok ( ) ;
@@ -66,9 +66,9 @@ pub async fn git_status(Query(query): Query<GitPathQuery>) -> AppResult<Json<Git
6666 } ) ;
6767 }
6868 }
69- } else if line. starts_with ( "? " ) {
69+ } else if let Some ( stripped ) = line. strip_prefix ( "? " ) {
7070 // Untracked: ? path
71- let path = line [ 2 .. ] . to_string ( ) ;
71+ let path = stripped . to_string ( ) ;
7272 unstaged. push ( GitStatusFile {
7373 path,
7474 status : "untracked" . to_string ( ) ,
@@ -255,10 +255,10 @@ fn parse_tracking_info(track: &str) -> (Option<u32>, Option<u32>) {
255255
256256 for part in track. split ( ',' ) {
257257 let part = part. trim ( ) ;
258- if part. starts_with ( "ahead " ) {
259- ahead = part [ 6 .. ] . trim ( ) . parse ( ) . ok ( ) ;
260- } else if part. starts_with ( "behind " ) {
261- behind = part [ 7 .. ] . trim ( ) . parse ( ) . ok ( ) ;
258+ if let Some ( stripped ) = part. strip_prefix ( "ahead " ) {
259+ ahead = stripped . trim ( ) . parse ( ) . ok ( ) ;
260+ } else if let Some ( stripped ) = part. strip_prefix ( "behind " ) {
261+ behind = stripped . trim ( ) . parse ( ) . ok ( ) ;
262262 }
263263 }
264264
@@ -333,14 +333,14 @@ fn parse_diff_with_stats(diff: &str) -> (Vec<serde_json::Value>, usize, usize) {
333333 }
334334 }
335335 } else if current_hunk. is_some ( ) {
336- let ( line_type, content) = if line. starts_with ( '+' ) {
336+ let ( line_type, content) = if let Some ( stripped ) = line. strip_prefix ( '+' ) {
337337 total_additions += 1 ;
338- ( "addition" , & line [ 1 .. ] )
339- } else if line. starts_with ( '-' ) {
338+ ( "addition" , stripped )
339+ } else if let Some ( stripped ) = line. strip_prefix ( '-' ) {
340340 total_deletions += 1 ;
341- ( "deletion" , & line [ 1 .. ] )
342- } else if line. starts_with ( ' ' ) {
343- ( "context" , & line [ 1 .. ] )
341+ ( "deletion" , stripped )
342+ } else if let Some ( stripped ) = line. strip_prefix ( ' ' ) {
343+ ( "context" , stripped )
344344 } else {
345345 ( "context" , line)
346346 } ;
@@ -425,30 +425,30 @@ fn parse_blame(blame: &str) -> Vec<serde_json::Value> {
425425 "message" : "" ,
426426 } ) ) ;
427427 } else if let Some ( ref mut commit) = current_commit {
428- if line. starts_with ( "author " ) {
429- commit[ "author" ] = serde_json:: json!( line [ 7 .. ] . to_string( ) ) ;
430- } else if line. starts_with ( "author-mail " ) {
428+ if let Some ( stripped ) = line. strip_prefix ( "author " ) {
429+ commit[ "author" ] = serde_json:: json!( stripped . to_string( ) ) ;
430+ } else if let Some ( stripped ) = line. strip_prefix ( "author-mail " ) {
431431 commit[ "email" ] = serde_json:: json!(
432- line [ 12 .. ]
432+ stripped
433433 . trim_matches( |c| c == '<' || c == '>' )
434434 . to_string( )
435435 ) ;
436- } else if line. starts_with ( "author-time " ) {
437- if let Ok ( timestamp) = line [ 12 .. ] . parse :: < i64 > ( ) {
436+ } else if let Some ( stripped ) = line. strip_prefix ( "author-time " ) {
437+ if let Ok ( timestamp) = stripped . parse :: < i64 > ( ) {
438438 commit[ "date" ] = serde_json:: json!(
439439 chrono:: DateTime :: from_timestamp( timestamp, 0 )
440440 . map( |dt| dt. to_rfc3339( ) )
441441 . unwrap_or_default( )
442442 ) ;
443443 }
444- } else if line. starts_with ( "summary " ) {
445- commit[ "message" ] = serde_json:: json!( line [ 8 .. ] . to_string( ) ) ;
446- } else if line. starts_with ( '\t' ) {
444+ } else if let Some ( stripped ) = line. strip_prefix ( "summary " ) {
445+ commit[ "message" ] = serde_json:: json!( stripped . to_string( ) ) ;
446+ } else if let Some ( stripped ) = line. strip_prefix ( '\t' ) {
447447 // This is the actual code line
448448 if let Some ( commit) = current_commit. take ( ) {
449449 result. push ( serde_json:: json!( {
450450 "lineNumber" : line_number,
451- "content" : & line [ 1 .. ] ,
451+ "content" : stripped ,
452452 "commit" : commit,
453453 } ) ) ;
454454 }
0 commit comments