@@ -31,32 +31,39 @@ class RevInfo(NamedTuple):
3131 rev : str
3232 frozen : Optional [str ]
3333
34- @classmethod
35- def from_config (cls , config : Dict [str , Any ]) -> 'RevInfo' :
36- return cls (config ['repo' ], config ['rev' ], None )
3734
38- def update (self , tags_only : bool , freeze : bool ) -> 'RevInfo' :
39- if tags_only :
40- tag_cmd = ('git' , 'describe' , 'FETCH_HEAD' , '--tags' , '--abbrev=0' )
41- else :
42- tag_cmd = ('git' , 'describe' , 'FETCH_HEAD' , '--tags' , '--exact' )
43-
44- with tmpdir () as tmp :
45- git .init_repo (tmp , self .repo )
46- cmd_output_b ('git' , 'fetch' , 'origin' , 'HEAD' , '--tags' , cwd = tmp )
47-
48- try :
49- rev = cmd_output (* tag_cmd , cwd = tmp )[1 ].strip ()
50- except CalledProcessError :
51- cmd = ('git' , 'rev-parse' , 'FETCH_HEAD' )
52- rev = cmd_output (* cmd , cwd = tmp )[1 ].strip ()
53-
54- frozen = None
55- if freeze :
56- exact = cmd_output ('git' , 'rev-parse' , rev , cwd = tmp )[1 ].strip ()
57- if exact != rev :
58- rev , frozen = exact , rev
59- return self ._replace (rev = rev , frozen = frozen )
35+ @classmethod
36+ def RevInfo_from_config (cls , config : Dict [str , Any ]) -> 'RevInfo' :
37+ return cls (config ['repo' ], config ['rev' ], None )
38+
39+
40+ def RevInfo_update (self , tags_only : bool , freeze : bool ) -> 'RevInfo' :
41+ if tags_only :
42+ tag_cmd = ('git' , 'describe' , 'FETCH_HEAD' , '--tags' , '--abbrev=0' )
43+ else :
44+ tag_cmd = ('git' , 'describe' , 'FETCH_HEAD' , '--tags' , '--exact' )
45+
46+ with tmpdir () as tmp :
47+ git .init_repo (tmp , self .repo )
48+ cmd_output_b ('git' , 'fetch' , 'origin' , 'HEAD' , '--tags' , cwd = tmp )
49+
50+ try :
51+ rev = cmd_output (* tag_cmd , cwd = tmp )[1 ].strip ()
52+ except CalledProcessError :
53+ cmd = ('git' , 'rev-parse' , 'FETCH_HEAD' )
54+ rev = cmd_output (* cmd , cwd = tmp )[1 ].strip ()
55+
56+ frozen = None
57+ if freeze :
58+ exact = cmd_output ('git' , 'rev-parse' , rev , cwd = tmp )[1 ].strip ()
59+ if exact != rev :
60+ rev , frozen = exact , rev
61+ return self ._replace (rev = rev , frozen = frozen )
62+
63+
64+ # python 3.6.0 does not support methods on `typing.NamedTuple`
65+ RevInfo .from_config = RevInfo_from_config
66+ RevInfo .update = RevInfo_update
6067
6168
6269class RepositoryCannotBeUpdatedError (RuntimeError ):
0 commit comments