File tree Expand file tree Collapse file tree 5 files changed +26
-6
lines changed Expand file tree Collapse file tree 5 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ license = "Apache-2.0"
5
5
name = " ilc"
6
6
repository = " https://github.com/tilpner/ilc"
7
7
version = " 0.3.0"
8
+ build = " build.rs"
8
9
exclude = [" .cargo/**" ]
9
10
10
11
[[bin ]]
Original file line number Diff line number Diff line change
1
+ use std:: fs:: { self , File } ;
2
+ use std:: path:: Path ;
3
+
4
+ fn main ( ) {
5
+ let path = Path :: new ( ".git" ) . join ( "refs" ) . join ( "heads" ) . join ( "master" ) ;
6
+ if !path. exists ( ) {
7
+ let _ = fs:: create_dir_all ( path. parent ( ) . unwrap ( ) ) ;
8
+ let _ = File :: create ( & path) ;
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ mod stats;
35
35
36
36
pub struct Cli {
37
37
pub version : String ,
38
- pub master_hash : String ,
38
+ pub master_hash : Option < String > ,
39
39
}
40
40
41
41
pub fn main ( cli : Cli ) {
@@ -44,7 +44,10 @@ pub fn main(cli: Cli) {
44
44
info ! ( "Compiled with FUSEs" )
45
45
}
46
46
47
- let version = format ! ( "{} ({})" , cli. version, cli. master_hash) ;
47
+ let version = match cli. master_hash {
48
+ Some ( ref h) => format ! ( "{} ({})" , cli. version, h) ,
49
+ None => cli. version . clone ( ) ,
50
+ } ;
48
51
let args = App :: new ( "ilc" )
49
52
. version ( & version[ ..] )
50
53
. setting ( AppSettings :: GlobalVersion )
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use error;
13
13
14
14
struct StatFormat {
15
15
version : String ,
16
- master_hash : String ,
16
+ master_hash : Option < String > ,
17
17
time : String ,
18
18
stats : Stats ,
19
19
}
@@ -28,7 +28,9 @@ impl Serialize for StatFormat {
28
28
where S : Serializer
29
29
{
30
30
try!( s. serialize_struct_elt ( "version" , & self . 0 . version ) ) ;
31
- try!( s. serialize_struct_elt ( "master_hash" , & self . 0 . master_hash ) ) ;
31
+ if let & Some ( ref h) = & self . 0 . master_hash {
32
+ try!( s. serialize_struct_elt ( "master_hash" , h) ) ;
33
+ }
32
34
try!( s. serialize_struct_elt ( "time" , & self . 0 . time ) ) ;
33
35
try!( s. serialize_struct_elt ( "stats" , & self . 0 . stats ) ) ;
34
36
Ok ( None )
Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ extern crate ilc_cli;
2
2
3
3
use ilc_cli:: Cli ;
4
4
5
- static MASTER : & ' static str = include_str ! ( "../.git/refs/heads/master" ) ;
5
+ static MASTER_HASH : & ' static str = include_str ! ( "../.git/refs/heads/master" ) ;
6
6
7
7
fn main ( ) {
8
8
ilc_cli:: main ( Cli {
9
9
version : env ! ( "CARGO_PKG_VERSION" ) . into ( ) ,
10
- master_hash : MASTER . trim_right ( ) . into ( ) ,
10
+ master_hash : if MASTER_HASH . is_empty ( ) {
11
+ None
12
+ } else {
13
+ Some ( MASTER_HASH . trim_right ( ) . to_owned ( ) )
14
+ } ,
11
15
} ) ;
12
16
}
You can’t perform that action at this time.
0 commit comments