@@ -30,34 +30,26 @@ impl<'options> CommitDiffLoader<'options> {
30
30
Self { config, repo }
31
31
}
32
32
33
- pub ( crate ) fn load_from_hash ( & self , oid : Oid ) -> Result < Vec < CommitDiff > , git2:: Error > {
33
+ pub ( crate ) fn load_from_hash ( & self , oid : Oid ) -> Result < CommitDiff , git2:: Error > {
34
34
let repo = self . repo . lock ( ) ;
35
35
let commit = repo. find_commit ( oid) ?;
36
- let no_parents = commit. parent_ids ( ) . count ( ) == 0 ;
36
+ // only the first parent matter for the diff, the second parent, if it exists, was only used
37
+ // for conflict resolution
38
+ let parent = commit. parents ( ) . next ( ) ;
37
39
38
- // some commits do not have parents, and can't have file stats
39
- let diffs = if no_parents {
40
- vec ! [ self . load_diff( & repo, None , & commit) ?]
41
- }
42
- else {
43
- //
44
- let mut diffs = vec ! [ ] ;
45
- for parent in commit. parents ( ) {
46
- diffs. push ( self . load_diff ( & repo, Some ( & parent) , & commit) ?) ;
47
- }
48
- diffs
49
- } ;
50
- Ok ( diffs)
40
+ self . load_diff ( & repo, parent, & commit)
51
41
}
52
42
53
43
#[ expect( clippy:: as_conversions, reason = "Mostly safe difference between APIs." ) ]
54
44
#[ expect( clippy:: unwrap_in_result, reason = "Unwrap usage failure considered a bug." ) ]
55
45
fn load_diff (
56
46
& self ,
57
47
repo : & MutexGuard < ' _ , Repository > ,
58
- parent : Option < & git2:: Commit < ' _ > > ,
48
+ parent : Option < git2:: Commit < ' _ > > ,
59
49
commit : & git2:: Commit < ' _ > ,
60
50
) -> Result < CommitDiff , git2:: Error > {
51
+ let parent_commit = parent. as_ref ( ) . map ( Commit :: from) ;
52
+
61
53
let mut diff_options = DiffOptions :: new ( ) ;
62
54
// include_unmodified added to find copies from unmodified files
63
55
_ = diff_options
@@ -148,7 +140,7 @@ impl<'options> CommitDiffLoader<'options> {
148
140
149
141
Ok ( CommitDiff :: new (
150
142
Commit :: from ( commit) ,
151
- parent . map ( Commit :: from ) ,
143
+ parent_commit ,
152
144
fsb. build ( ) ,
153
145
number_files_changed,
154
146
number_insertions,
@@ -316,7 +308,7 @@ mod tests {
316
308
fn diff_from_head ( repository : & crate :: git:: Repository , options : & CommitDiffLoaderOptions ) -> CommitDiff {
317
309
let id = repository. commit_id_from_ref ( "refs/heads/main" ) . unwrap ( ) ;
318
310
let loader = CommitDiffLoader :: new ( repository. repository ( ) , options) ;
319
- loader. load_from_hash ( id) . unwrap ( ) . remove ( 0 )
311
+ loader. load_from_hash ( id) . unwrap ( )
320
312
}
321
313
322
314
#[ test]
0 commit comments