| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,8 +35,8 @@ | |||
| 35 | 35 | rev_parse, | |
| 36 | 36 | is_git_dir, | |
| 37 | 37 | find_git_dir, | |
| 38 | - touch | ||
| 39 | - read_gitfile, | ||
| 38 | + read_gitfile, | ||
| 39 | + touch, | ||
| 40 | 40 | ) | |
| 41 | 41 | ||
| 42 | 42 | import os | |
@@ -117,7 +117,7 @@ def __init__(self, path=None, odbt=DefaultDBType): | |||
| 117 | 117 | self.git_dir = gitpath | |
| 118 | 118 | self._working_tree_dir = curpath | |
| 119 | 119 | break | |
| 120 | - gitpath = read_gitfile(gitpath) | ||
| 120 | + gitpath = read_gitfile(curpath) | ||
| 121 | 121 | if gitpath: | |
| 122 | 122 | self.git_dir = gitpath | |
| 123 | 123 | self._working_tree_dir = curpath | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,8 @@ | |||
| 13 | 13 | ) | |
| 14 | 14 | from string import digits | |
| 15 | 15 | ||
| 16 | - __all__ = ('rev_parse', 'is_git_dir', 'touch') | ||
| 16 | + __all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object', | ||
| 17 | + 'short_to_long', 'deref_tag', 'to_commit') | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | def touch(filename): | |
@@ -46,16 +47,20 @@ def find_git_dir(d): | |||
| 46 | 47 | return None | |
| 47 | 48 | ||
| 48 | 49 | def read_gitfile(f): | |
| 49 | - """ This is taken from the git setup.c:read_gitfile function. | ||
| 50 | - :return gitdir path or None if gitfile is invalid.""" | ||
| 51 | - | ||
| 52 | - if not isfile(f): | ||
| 53 | - return None | ||
| 54 | - line = open(f, 'r').readline().rstrip() | ||
| 55 | - if line[0:8] != 'gitdir: ': | ||
| 56 | - return None | ||
| 57 | - path = os.path.realpath(line[8:]) | ||
| 58 | - return path if is_git_dir(path) else None | ||
| 50 | + """ This is taken from the git setup.c:read_gitfile function. | ||
| 51 | + :return gitdir path or None if gitfile is invalid.""" | ||
| 52 | + if f is None: | ||
| 53 | + return None | ||
| 54 | + try: | ||
| 55 | + line = open(f, 'r').readline().rstrip() | ||
| 56 | + except (OSError, IOError): | ||
| 57 | + # File might not exist or is unreadable - ignore | ||
| 58 | + return None | ||
| 59 | + # end handle file access | ||
| 60 | + if line[0:8] != 'gitdir: ': | ||
| 61 | + return None | ||
| 62 | + path = os.path.realpath(line[8:]) | ||
| 63 | + return path if is_git_dir(path) else None | ||
| 59 | 64 | ||
| 60 | 65 | def short_to_long(odb, hexsha): | |
| 61 | 66 | """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha | |
| Back | FazBrowse Home | New Git URL |
0 commit comments