1
1
import os
2
2
import subprocess
3
3
import tarfile
4
-
4
+ import logging
5
5
from .file_finder import scm_find_files
6
+ from .utils import trace
7
+
8
+ log = logging .getLogger (__name__ )
6
9
7
10
8
11
def _git_toplevel (path ):
@@ -14,6 +17,7 @@ def _git_toplevel(path):
14
17
universal_newlines = True ,
15
18
stderr = devnull ,
16
19
)
20
+ trace ("find files toplevel" , out )
17
21
return os .path .normcase (os .path .realpath (out .strip ()))
18
22
except subprocess .CalledProcessError :
19
23
# git returned error, we are not in a git repo
@@ -23,12 +27,8 @@ def _git_toplevel(path):
23
27
return None
24
28
25
29
26
- def _git_ls_files_and_dirs (toplevel ):
27
- # use git archive instead of git ls-file to honor
28
- # export-ignore git attribute
29
- cmd = ["git" , "archive" , "--prefix" , toplevel + os .path .sep , "HEAD" ]
30
- proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , cwd = toplevel )
31
- tf = tarfile .open (fileobj = proc .stdout , mode = "r|*" )
30
+ def _git_interpret_archive (fd , toplevel ):
31
+ tf = tarfile .open (fileobj = fd , mode = "r|*" )
32
32
git_files = set ()
33
33
git_dirs = {toplevel }
34
34
for member in tf .getmembers ():
@@ -40,6 +40,19 @@ def _git_ls_files_and_dirs(toplevel):
40
40
return git_files , git_dirs
41
41
42
42
43
+ def _git_ls_files_and_dirs (toplevel ):
44
+ # use git archive instead of git ls-file to honor
45
+ # export-ignore git attribute
46
+ cmd = ["git" , "archive" , "--prefix" , toplevel + os .path .sep , "HEAD" ]
47
+ proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , cwd = toplevel )
48
+ try :
49
+ return _git_interpret_archive (proc .stdout , toplevel )
50
+ except Exception :
51
+ if proc .wait () != 0 :
52
+ log .exception ("listing git files failed - pretending there aren't any" )
53
+ return (), ()
54
+
55
+
43
56
def git_find_files (path = "" ):
44
57
toplevel = _git_toplevel (path )
45
58
if not toplevel :
0 commit comments