1
1
use gix:: bstr:: { BString , ByteSlice } ;
2
+ use gix:: objs:: tree:: EntryMode ;
3
+ use gix:: prelude:: ObjectIdExt ;
2
4
3
5
pub fn tree (
4
- repo : gix:: Repository ,
6
+ mut repo : gix:: Repository ,
5
7
out : & mut dyn std:: io:: Write ,
6
8
old_treeish : BString ,
7
9
new_treeish : BString ,
8
10
) -> anyhow:: Result < ( ) > {
11
+ repo. object_cache_size_if_unset ( repo. compute_object_cache_size_for_tree_diffs ( & * * repo. index_or_empty ( ) ?) ) ;
12
+
9
13
let old_tree_id = repo. rev_parse_single ( old_treeish. as_bstr ( ) ) ?;
10
14
let new_tree_id = repo. rev_parse_single ( new_treeish. as_bstr ( ) ) ?;
11
15
12
- let old_tree = old_tree_id. object ( ) ?. peel_to_kind ( gix :: object :: Kind :: Tree ) ? . into_tree ( ) ;
13
- let new_tree = new_tree_id. object ( ) ?. peel_to_kind ( gix :: object :: Kind :: Tree ) ? . into_tree ( ) ;
16
+ let old_tree = old_tree_id. object ( ) ?. peel_to_tree ( ) ? ;
17
+ let new_tree = new_tree_id. object ( ) ?. peel_to_tree ( ) ? ;
14
18
15
19
let changes = repo. diff_tree_to_tree ( & old_tree, & new_tree, None ) ?;
16
20
17
21
writeln ! (
18
22
out,
19
- "Diffing trees `{old_treeish}` ({old_tree_id}) -> `{new_treeish}` ({new_tree_id})"
23
+ "Diffing trees `{old_treeish}` ({old_tree_id}) -> `{new_treeish}` ({new_tree_id})\n "
20
24
) ?;
21
- writeln ! ( out) ?;
22
-
23
- write_changes ( out, changes) ?;
25
+ write_changes ( & repo, out, changes) ?;
24
26
25
27
Ok ( ( ) )
26
28
}
27
29
28
30
fn write_changes (
31
+ repo : & gix:: Repository ,
29
32
mut out : impl std:: io:: Write ,
30
33
changes : Vec < gix:: diff:: tree_with_rewrites:: Change > ,
31
34
) -> Result < ( ) , std:: io:: Error > {
@@ -37,8 +40,8 @@ fn write_changes(
37
40
entry_mode,
38
41
..
39
42
} => {
40
- writeln ! ( out, "A: {location}" ) ?;
41
- writeln ! ( out, " {id}" ) ?;
43
+ writeln ! ( out, "A: {}" , typed_location ( location , entry_mode ) ) ?;
44
+ writeln ! ( out, " {}" , id . attach ( repo ) . shorten_or_id ( ) ) ?;
42
45
writeln ! ( out, " -> {:o}" , entry_mode. 0 ) ?;
43
46
}
44
47
gix:: diff:: tree_with_rewrites:: Change :: Deletion {
@@ -47,8 +50,8 @@ fn write_changes(
47
50
entry_mode,
48
51
..
49
52
} => {
50
- writeln ! ( out, "D: {location}" ) ?;
51
- writeln ! ( out, " {id}" ) ?;
53
+ writeln ! ( out, "D: {}" , typed_location ( location , entry_mode ) ) ?;
54
+ writeln ! ( out, " {}" , id . attach ( repo ) . shorten_or_id ( ) ) ?;
52
55
writeln ! ( out, " {:o} ->" , entry_mode. 0 ) ?;
53
56
}
54
57
gix:: diff:: tree_with_rewrites:: Change :: Modification {
@@ -58,9 +61,16 @@ fn write_changes(
58
61
previous_entry_mode,
59
62
entry_mode,
60
63
} => {
61
- writeln ! ( out, "M: {location}" ) ?;
62
- writeln ! ( out, " {previous_id} -> {id}" ) ?;
63
- writeln ! ( out, " {:o} -> {:o}" , previous_entry_mode. 0 , entry_mode. 0 ) ?;
64
+ writeln ! ( out, "M: {}" , typed_location( location, entry_mode) ) ?;
65
+ writeln ! (
66
+ out,
67
+ " {previous_id} -> {id}" ,
68
+ previous_id = previous_id. attach( repo) . shorten_or_id( ) ,
69
+ id = id. attach( repo) . shorten_or_id( )
70
+ ) ?;
71
+ if previous_entry_mode != entry_mode {
72
+ writeln ! ( out, " {:o} -> {:o}" , previous_entry_mode. 0 , entry_mode. 0 ) ?;
73
+ }
64
74
}
65
75
gix:: diff:: tree_with_rewrites:: Change :: Rewrite {
66
76
source_location,
@@ -71,12 +81,31 @@ fn write_changes(
71
81
entry_mode,
72
82
..
73
83
} => {
74
- writeln ! ( out, "R: {source_location} -> {location}" ) ?;
75
- writeln ! ( out, " {source_id} -> {id}" ) ?;
76
- writeln ! ( out, " {:o} -> {:o}" , source_entry_mode. 0 , entry_mode. 0 ) ?;
84
+ writeln ! (
85
+ out,
86
+ "R: {source} -> {dest}" ,
87
+ source = typed_location( source_location, source_entry_mode) ,
88
+ dest = typed_location( location, entry_mode)
89
+ ) ?;
90
+ writeln ! (
91
+ out,
92
+ " {source_id} -> {id}" ,
93
+ source_id = source_id. attach( repo) . shorten_or_id( ) ,
94
+ id = id. attach( repo) . shorten_or_id( )
95
+ ) ?;
96
+ if source_entry_mode != entry_mode {
97
+ writeln ! ( out, " {:o} -> {:o}" , source_entry_mode. 0 , entry_mode. 0 ) ?;
98
+ }
77
99
}
78
100
} ;
79
101
}
80
102
81
103
Ok ( ( ) )
82
104
}
105
+
106
+ fn typed_location ( mut location : BString , mode : EntryMode ) -> BString {
107
+ if mode. is_tree ( ) {
108
+ location. push ( b'/' ) ;
109
+ }
110
+ location
111
+ }
0 commit comments