| 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,9 @@ | |||
| 35 | 35 | rev_parse, | |
| 36 | 36 | is_git_dir, | |
| 37 | 37 | find_git_dir, | |
| 38 | - touch | ||
| 39 | - ) | ||
| 38 | + read_gitfile, | ||
| 39 | + touch, | ||
| 40 | + ) | ||
| 40 | 41 | ||
| 41 | 42 | import os | |
| 42 | 43 | import sys | |
@@ -52,7 +53,6 @@ | |||
| 52 | 53 | ||
| 53 | 54 | ||
| 54 | 55 | class Repo(object): | |
| 55 | - | ||
| 56 | 56 | """Represents a git repository and allows you to query references, | |
| 57 | 57 | gather commit information, generate diffs, create and clone repositories query | |
| 58 | 58 | the log. | |
@@ -117,6 +117,11 @@ 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(curpath) | ||
| 121 | + if gitpath: | ||
| 122 | + self.git_dir = gitpath | ||
| 123 | + self._working_tree_dir = curpath | ||
| 124 | + break | ||
| 120 | 125 | curpath, dummy = os.path.split(curpath) | |
| 121 | 126 | if not dummy: | |
| 122 | 127 | break | |
| 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): | |
@@ -45,6 +46,21 @@ def find_git_dir(d): | |||
| 45 | 46 | return find_git_dir(d) | |
| 46 | 47 | return None | |
| 47 | 48 | ||
| 49 | + def read_gitfile(f): | ||
| 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 | ||
| 48 | 64 | ||
| 49 | 65 | def short_to_long(odb, hexsha): | |
| 50 | 66 | """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha | |
| Back | FazBrowse Home | New Git URL |
0 commit comments