Find the gitmit cached commit_times and return them if they are the right shape.

    This means the file is a list of dictionaries.

    If they aren't, issue a warning and return an empty list, it is just a cache
    after all!
547744
def get_all_cached_commit_times(root_folder):
    
    result = []
    location = cache_location(root_folder)

    if os.path.exists(location):
        try:
            result = json.load(open(location))
        except (TypeError, ValueError) as error:
            log.warning("Failed to open gitmit cached commit_times\tlocation=%s\terror=%s", location, error)
        else:
            if type(result) is not list or not all(type(item) is dict for item in result):
                log.warning("Gitmit cached commit_times needs to be a list of dictionaries\tlocation=%s\tgot=%s", location, type(result))
                result = []

    return result
55138
def get_changed_files(self) -> List[str]:
        
        out = shell_tools.output_of(
            'git',
            'diff',
            '--name-only',
            self.compare_commit_id,
            self.actual_commit_id,
            '--',
            cwd=self.destination_directory)
        return [e for e in out.split('\n') if e.strip()]
1081776
def diff_objects(self, latest_commit_sha):
        
        base = ['git', '--bare', '--git-dir', self.git_path]

        object_shas = []
        summary = {'commits': [], 'trees': [], 'files': []}

        def read_parents_and_tree_from(commit):
            if commit in self.synced_object_shas or commit in object_shas:
                # this commit has already been synced or read
                return None, None

            self.synced_object_shas[commit] = True
            summary['commits'].append(commit)
            object_shas.append(commit)

            object_content = subprocess.check_output(base + ['cat-file', '-p', commit]).decode('utf-8').strip()
            parents = []
            tree = ''
            for line in object_content.splitlines():
                if line.startswith('tree '):
                    tree = line[len('tree '):]
                if line.startswith('parent '):
                    parents.append(line[len('parent '):])

            return parents, tree

        def collect_files_from_tree(tree):
            if tree in self.synced_object_shas or tree in object_shas:
                # we have exactly this tree already synced or read, meaning all its objects as well
                return

            self.synced_object_shas[tree] = True
            summary['trees'].append(tree)
            object_shas.append(tree)

            object_content = subprocess.check_output(base + ['ls-tree', '-r', '-t', tree]).decode('utf-8').strip()

            for line in object_content.splitlines():
                exploded = line.split(' ')

                if len(exploded) < 3:
                    sys.stderr.write("Error: Wrong line format of ls-tree for %s: %s\n" % (tree, line,))
                    sys.exit(1)

                object_to_add = str(exploded[2][:40])
                path = str(exploded[2][41:])

                if object_to_add in self.synced_object_shas or object_to_add in object_shas:
                    # have it already in the list or already synced
                    continue

                object_shas.append(object_to_add)
                self.synced_object_shas[object_to_add] = True
                summary['files'].append([object_to_add, path])

        commits_to_check = [latest_commit_sha]

        while len(commits_to_check):
            sha = commits_to_check.pop(0)
            parents, tree = read_parents_and_tree_from(sha)

            if parents:
                for parent in parents:
                    if parent not in commits_to_check:
                        commits_to_check.append(parent)

            if tree:
                collect_files_from_tree(tree)

        is_debug2() and self.logger.debug("shas_to_check %d: %s " % (len(object_shas), str(object_shas),))

        if not object_shas:
            return [], summary

        try:
            is_debug2() and self.logger.debug("Do git-cat-file-check.sh")

            ssh_stream = create_ssh_stream(read_home_config(), exit_on_failure=False)
            channel = ssh_stream.get_transport().open_session()
            channel.exec_command('git-cat-file-check.sh "%s"' % (self.model_name + '.git',))
            channel.sendall('\n'.join(object_shas))
            channel.shutdown_write()

            def readall(c):
                content = b''
                while True:
                    try:
                        chunk = c.recv(1024)
                        if chunk == b'':
                            break
                        content += chunk
                    except (KeyboardInterrupt, SystemExit):
                        return

                return content

            missing_objects = readall(channel).decode('utf-8').splitlines()
            channel.close()
            ssh_stream.close()

            # make sure we have in summary only SHAs we actually will sync
            for stype in six.iterkeys(summary):
                ids = summary[stype][:]
                for sha in ids:
                    if stype == 'files':
                        if sha[0] not in missing_objects:
                            summary[stype].remove(sha)
                    else:
                        if sha not in missing_objects:
                            summary[stype].remove(sha)

            return missing_objects, summary
        except (KeyboardInterrupt, SystemExit):
            raise
        except Exception as e:
            self.logger.error("Failed to generate diff_objects: %s" % (str(e),))
            for sha in object_shas:
                if sha in self.synced_object_shas:
                    del self.synced_object_shas[sha]
            return None, None
519180
def per_file_type_data(self):
        
        ret = {}
        for cache_date in self.cache_dates:
            data = self._cache_get(cache_date)
            if len(data['by_file_type']) == 0:
                data['by_file_type'] = {'other': 0}
            ret[cache_date] = data['by_file_type']
        return ret
912300
def git_commit(self, sha):
        
        json = {}
        if sha:
            url = self._build_url('git', 'commits', sha, base_url=self._api)
            json = self._json(self._get(url), 200)
        return Commit(json, self) if json else None
35872
def get_commit_log(name, vendor='pypi', functions={}, _depth=0):
    
    if "find_changelogs" not in functions:
        from .finder import find_git_repo
        functions["find_changelogs"] = find_git_repo
    if "get_content" not in functions:
        functions["get_content"] = clone_repo
    if "parse" not in functions:
        from .parser import parse_commit_log
        functions["parse"] = parse_commit_log
    return get(
        name=name,
        vendor=vendor,
        functions=functions
    )
1092460
def parse_commit_log(commit_log: dict) -> str:
    
    rv = 'pat'

    cc_patterns = patterns()

    for value in commit_log.values():
        if re.search(cc_patterns['feat'], value):
            rv = 'min'
        if re.search(cc_patterns['BREAKING CHANGE'], value):
            rv = 'maj'

    return rv
1182078
def _commitData(self, commit):
		
		return {
			"hexsha": commit['hash'],
			"adate": time.mktime(time.strptime(commit['date'][:19], '%Y-%m-%dT%H:%M:%S')),
			"cdate": time.mktime(time.strptime(commit['date'][:19], '%Y-%m-%dT%H:%M:%S')),
			"author": commit['author']['raw'],
			"message": commit['message']
		}
528764
def get_commit_from_gitpython(self, commit: GitCommit) -> Commit:
        
        return Commit(commit, self.path, self.main_branch)
292004
def is_commit_id_equal(self, dest, name):
        
        if not name:
            # Then avoid an unnecessary subprocess call.
            return False

        return self.get_revision(dest) == name
1036441
def lint(commit = nil)
      files = pronto(commit)
      return if files.empty?

      markdown offenses_message(files)
    end
1246189
def find(self):
        
        mtimes = {}

        git = Repo(self.root_folder)
        all_files = git.all_files()
        use_files = set(self.find_files_for_use(all_files))

        # the git index won't find the files under a symlink :(
        # And we include files under a symlink as seperate copies of the files
        # So we still want to generate modified times for those files
        extras = set(self.extra_symlinked_files(use_files))

        # Combine use_files and extras
        use_files.update(extras)

        # Tell the user something
        if not self.silent:
            log.info("Finding modified times for %s/%s git controlled files in %s", len(use_files), len(all_files), self.root_folder)

        # Finally get the dates from git!
        return self.commit_times_for(git, use_files)
1336222
def _iter_packed_refs(cls, repo):
        """"""
        try:
            with open(cls._get_packed_refs_path(repo), 'rt') as fp:
                for line in fp:
                    line = line.strip()
                    if not line:
                        continue
                    if line.startswith('#'):
                        # "# pack-refs with: peeled fully-peeled sorted"
                        # the git source code shows "peeled",
                        # "fully-peeled" and "sorted" as the keywords
                        # that can go on this line, as per comments in git file
                        # refs/packed-backend.c
                        # I looked at master on 2017-10-11,
                        # commit 111ef79afe, after tag v2.15.0-rc1
                        # from repo https://github.com/git/git.git
                        if line.startswith('# pack-refs with:') and 'peeled' not in line:
                            raise TypeError("PackingType of packed-Refs not understood: %r" % line)
                        # END abort if we do not understand the packing scheme
                        continue
                    # END parse comment

                    # skip dereferenced tag object entries - previous line was actual
                    # tag reference for it
                    if line[0] == '^':
                        continue

                    yield tuple(line.split(' ', 1))
                # END for each line
        except (OSError, IOError):
            return
1319692
def get_scm_data(ref = @config[:ref])
      @_version = ""
      @_date = Time.now
      begin
        if File.exist?(git_dir)
          @_version = `git --git-dir=#{git_dir} describe --tags #{ref} 2>&1`
          
          if $?.to_i > 0
            # HEAD is not a tagged verison, get the short SHA1 instead            
            @_version = `git --git-dir=#{git_dir} show #{ref} --format=format:"%h" -s 2>&1` 
          else
            # HEAD is a tagged version, if version is prefixed with "v" it will be stripped off
            @_version.gsub!(/^v/,"")
          end
          @_version.strip!
    
          # Get the date in epoch time
          date = `git --git-dir=#{git_dir} show #{ref} --format=format:"%ct" -s 2>&1`
          if date =~ /\d+/
            @_date = Time.at(date.to_i)
          else
            @_date = Time.now
          end
    
        end
      rescue RuntimeError => e
      end

    end
1194717
def get_commits(self, since_sha=None):
        
        assert self.tempdir

        cmd = ['git', 'log', '--first-parent', '--reverse', COMMIT_FORMAT]
        if since_sha:
            commits = [self.get_commit(since_sha)]
            cmd.append('{}..HEAD'.format(since_sha))
        else:
            commits = []
            cmd.append('HEAD')

        output = cmd_output(*cmd, cwd=self.tempdir)

        for sha, date in chunk_iter(output.splitlines(), 2):
            commits.append(Commit(sha, int(date)))

        return commits
1193653
def _gitinfo():
    '''  '''
    result = None
    repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', '.git')

    if os.path.exists(repo_path):
        # Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
        if os.path.isfile(repo_path):
            try:
                gitdir = yaml.load(open(repo_path)).get('gitdir')
                # There is a posibility the .git file to have an absolute path.
                if os.path.isabs(gitdir):
                    repo_path = gitdir
                else:
                    repo_path = os.path.join(repo_path.split('.git')[0], gitdir)
            except (IOError, AttributeError):
                return ''
        f = open(os.path.join(repo_path, "HEAD"))
        branch = f.readline().split('/')[-1].rstrip("\n")
        f.close()
        branch_path = os.path.join(repo_path, "refs", "heads", branch)
        if os.path.exists(branch_path):
            f = open(branch_path)
            commit = f.readline()[:10]
            f.close()
            date = time.localtime(os.stat(branch_path).st_mtime)
            if time.daylight == 0:
                offset = time.timezone
            else:
                offset = time.altzone
            result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit,
                time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36)
    else:
        result = ''
    return result
644744
def _find_git_info(self, gitdir):
        
        res = {'remotes': None, 'tag': None, 'commit': None, 'dirty': None}
        try:
            logger.debug('opening %s as git.Repo', gitdir)
            repo = Repo(path=gitdir, search_parent_directories=False)
            res['commit'] = repo.head.commit.hexsha
            res['dirty'] = repo.is_dirty(untracked_files=True)
            res['remotes'] = {}
            for rmt in repo.remotes:
                # each is a git.Remote
                urls = [u for u in rmt.urls]  # generator
                if len(urls) > 0:
                    res['remotes'][rmt.name] = urls[0]
            for tag in repo.tags:
                # each is a git.Tag object
                if tag.commit.hexsha == res['commit']:
                    res['tag'] = tag.name
        except Exception:
            logger.debug('Exception getting git information', exc_info=True)
        return res