def _cache_key(): # Try /etc/gitconfig as a fallback for the system config paths = ("/etc/gitconfig", _USER_XDG_CONFIG, _USER_CONFIG, git.instance().git_path("config")) mtimes = [] for path in paths: try: mtimes.append(core.stat(path).st_mtime) except OSError: continue return mtimes
def _cache_key(): # Try /etc/gitconfig as a fallback for the system config paths = ('/etc/gitconfig', _USER_XDG_CONFIG, _USER_CONFIG, git.instance().git_path('config')) mtimes = [] for path in paths: try: mtimes.append(core.stat(path).st_mtime) except OSError: continue return mtimes
def _stat_info(): # Try /etc/gitconfig as a fallback for the system config paths = (('system', '/etc/gitconfig'), ('user', _USER_XDG_CONFIG), ('user', _USER_CONFIG), ('repo', git.instance().git_path('config'))) statinfo = [] for category, path in paths: try: statinfo.append((category, path, core.stat(path).st_mtime)) except OSError: continue return statinfo
def _stat_info(): # Try /etc/gitconfig as a fallback for the system config paths = ( ("system", "/etc/gitconfig"), ("user", _USER_XDG_CONFIG), ("user", _USER_CONFIG), ("repo", git.instance().git_path("config")), ) statinfo = [] for category, path in paths: try: statinfo.append((category, path, core.stat(path).st_mtime)) except OSError: continue return statinfo
def _cache_key(): # Try /etc/gitconfig as a fallback for the system config paths = ['/etc/gitconfig', _USER_XDG_CONFIG, _USER_CONFIG] config = git.current().git_path('config') if config: paths.append(config) mtimes = [] for path in paths: try: mtimes.append(core.stat(path).st_mtime) except OSError: continue return mtimes
def date(self): """ Returns a relative date for a file path. This is typically used for new entries that do not have 'git log' information. """ st = core.stat(self.path) elapsed = time.time() - st.st_mtime minutes = int(elapsed / 60.) if minutes < 60: return N_('%d minutes ago') % minutes hours = int(elapsed / 60. / 60.) if hours < 24: return N_('%d hours ago') % hours return N_('%d days ago') % int(elapsed / 60. / 60. / 24.)
def date(self): """ Returns a relative date for a file path. This is typically used for new entries that do not have 'git log' information. """ st = core.stat(self.path) elapsed = time.time() - st.st_mtime minutes = int(elapsed / 60) if minutes < 60: return N_('%d minutes ago') % minutes hours = int(elapsed / 60 / 60) if hours < 24: return N_('%d hours ago') % hours return N_('%d days ago') % int(elapsed / 60 / 60 / 24)
def current_branch(): """Return the current branch""" head = git.git_path('HEAD') try: key = core.stat(head).st_mtime if _current_branch.key == key: return _current_branch.value except OSError: pass status, data, err = git.rev_parse('HEAD', symbolic_full_name=True) if status != 0: # git init -- read .git/HEAD. We could do this unconditionally... data = _read_git_head(head) for refs_prefix in ('refs/heads/', 'refs/remotes/', 'refs/tags/'): if data.startswith(refs_prefix): value = data[len(refs_prefix):] _current_branch.key = key _current_branch.value = value return value # Detached head return data
def current_branch(): """Return the current branch""" head = git.git_path("HEAD") try: key = core.stat(head).st_mtime if _current_branch.key == key: return _current_branch.value except OSError: pass status, data, err = git.rev_parse("HEAD", symbolic_full_name=True) if status != 0: # git init -- read .git/HEAD. We could do this unconditionally... data = _read_git_head(head) for refs_prefix in ("refs/heads/", "refs/remotes/", "refs/tags/"): if data.startswith(refs_prefix): value = data[len(refs_prefix) :] _current_branch.key = key _current_branch.value = value return value # Detached head return data