11use anyhow:: bail;
22use gix:: worktree:: archive;
33use gix:: Progress ;
4- use std:: ops:: Add ;
54use std:: path:: Path ;
65
76pub fn stream (
87 repo : gix:: Repository ,
9- destination_path : Option < & Path > ,
8+ destination_path : & Path ,
109 rev_spec : Option < & str > ,
1110 mut progress : impl Progress ,
1211 format : Option < archive:: Format > ,
@@ -24,13 +23,7 @@ pub fn stream(
2423 bytes. init ( None , gix:: progress:: bytes ( ) ) ;
2524
2625 let mut file = gix:: progress:: Write {
27- inner : match destination_path {
28- Some ( path) => Box :: new ( std:: io:: BufWriter :: with_capacity (
29- 128 * 1024 ,
30- std:: fs:: File :: create ( path) ?,
31- ) ) as Box < dyn std:: io:: Write > ,
32- None => Box :: new ( std:: io:: sink ( ) ) ,
33- } ,
26+ inner : std:: io:: BufWriter :: with_capacity ( 128 * 1024 , std:: fs:: File :: create ( destination_path) ?) ,
3427 progress : & mut bytes,
3528 } ;
3629 repo. worktree_archive (
@@ -41,9 +34,12 @@ pub fn stream(
4134 gix:: worktree:: archive:: Options {
4235 format,
4336 tree_prefix : None ,
44- modification_time : modification_date
45- . map ( |t| std:: time:: UNIX_EPOCH . add ( std:: time:: Duration :: from_secs ( t as u64 ) ) )
46- . unwrap_or_else ( std:: time:: SystemTime :: now) ,
37+ modification_time : modification_date. unwrap_or_else ( || {
38+ std:: time:: SystemTime :: now ( )
39+ . duration_since ( std:: time:: UNIX_EPOCH )
40+ . map ( |d| d. as_secs ( ) )
41+ . unwrap_or_default ( ) as gix:: date:: SecondsSinceUnixEpoch
42+ } ) ,
4743 } ,
4844 ) ?;
4945
@@ -67,14 +63,15 @@ fn fetch_rev_info(
6763 } )
6864}
6965
70- fn format_from_ext ( path : Option < & Path > ) -> anyhow:: Result < archive:: Format > {
71- Ok ( match path {
72- Some ( path ) => match path . extension ( ) . and_then ( |ext| ext . to_str ( ) ) {
73- None => bail ! ( "Cannot derive archive format from a file without extension" ) ,
74- Some ( "tar " ) => archive:: Format :: Tar ,
75- Some ( "stream " ) => archive:: Format :: InternalTransientNonPersistable ,
76- Some ( ext ) => bail ! ( "Format for extendion '{ext}' is unsupported" ) ,
66+ fn format_from_ext ( path : & Path ) -> anyhow:: Result < archive:: Format > {
67+ Ok ( match path. extension ( ) . and_then ( std :: ffi :: OsStr :: to_str ) {
68+ None => bail ! ( "Cannot derive archive format from a file without extension" ) ,
69+ Some ( "tar" ) => archive:: Format :: Tar ,
70+ Some ( "gz " ) => archive:: Format :: TarGz ,
71+ Some ( "zip " ) => archive:: Format :: Zip {
72+ compression_level : None ,
7773 } ,
78- None => archive:: Format :: InternalTransientNonPersistable ,
74+ Some ( "stream" ) => archive:: Format :: InternalTransientNonPersistable ,
75+ Some ( ext) => bail ! ( "Format for extension '{ext}' is unsupported" ) ,
7976 } )
8077}
0 commit comments