11//! Functions for getting infos about files in commits
22
3- use super :: {
4- diff:: DiffOptions , stash:: is_stash_commit, CommitId , RepoPath ,
5- } ;
3+ use super :: { diff:: DiffOptions , CommitId , RepoPath } ;
64use crate :: {
7- error:: Result , sync:: repository:: repo, StatusItem , StatusItemType ,
5+ error:: Result ,
6+ sync:: { get_stashes, repository:: repo} ,
7+ StatusItem , StatusItemType ,
88} ;
99use git2:: { Diff , Repository } ;
1010use scopetime:: scope_time;
11- use std:: cmp:: Ordering ;
11+ use std:: { cmp:: Ordering , collections :: HashSet } ;
1212
1313/// get all files that are part of a commit
1414pub fn get_commit_files (
@@ -23,7 +23,13 @@ pub fn get_commit_files(
2323 let diff = if let Some ( other) = other {
2424 get_compare_commits_diff ( & repo, ( id, other) , None , None ) ?
2525 } else {
26- get_commit_diff ( repo_path, & repo, id, None , None ) ?
26+ get_commit_diff (
27+ & repo,
28+ id,
29+ None ,
30+ None ,
31+ Some ( & get_stashes ( repo_path) ?. into_iter ( ) . collect ( ) ) ,
32+ ) ?
2733 } ;
2834
2935 let res = diff
@@ -91,12 +97,12 @@ pub fn get_compare_commits_diff(
9197}
9298
9399/// get diff of a commit to its first parent
94- pub fn get_commit_diff < ' a > (
95- repo_path : & RepoPath ,
100+ pub ( crate ) fn get_commit_diff < ' a > (
96101 repo : & ' a Repository ,
97102 id : CommitId ,
98103 pathspec : Option < String > ,
99104 options : Option < DiffOptions > ,
105+ stashes : Option < & HashSet < CommitId > > ,
100106) -> Result < Diff < ' a > > {
101107 // scope_time!("get_commit_diff");
102108
@@ -128,14 +134,17 @@ pub fn get_commit_diff<'a>(
128134 Some ( & mut opts) ,
129135 ) ?;
130136
131- if is_stash_commit ( repo_path, & id) ? {
137+ if stashes
138+ . map ( |stashes| stashes. contains ( & id) )
139+ . unwrap_or_default ( )
140+ {
132141 if let Ok ( untracked_commit) = commit. parent_id ( 2 ) {
133142 let untracked_diff = get_commit_diff (
134- repo_path,
135143 repo,
136144 CommitId :: new ( untracked_commit) ,
137145 pathspec,
138146 options,
147+ stashes,
139148 ) ?;
140149
141150 diff. merge ( & untracked_diff) ?;
0 commit comments