How to use the pygit2.GIT_SORT_TIME function in pygit2

To help you get started, we’ve selected a few pygit2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github presslabs / gitfs / tests / cache / test_commits.py View on Github external
cache = CommitCache(mocked_repo)
        cache.update()

        cache["2014-09-20"] = Commit(1, 1, "1111111111")
        assert sorted(cache.keys()) == ["2014-09-19", "2014-09-20"]
        asserted_time = datetime.fromtimestamp(mocked_commit.commit_time)
        asserted_time = "{}-{}-{}".format(
            asserted_time.hour, asserted_time.minute, asserted_time.second
        )
        assert repr(cache["2014-09-19"]) == "[%s-1111111111]" % asserted_time
        del cache["2014-09-20"]
        for commit_date in cache:
            assert commit_date == "2014-09-19"

        mocked_repo.lookup_reference.has_calls([call("HEAD")])
        mocked_repo.walk.assert_called_once_with("head", GIT_SORT_TIME)
        assert mocked_repo.lookup_reference().resolve.call_count == 2
github sjagoe / cygit2 / test / test_revwalk.py View on Github external
def test_walk(self):
        walker = self.repo.walk(log[0], GIT_SORT_TIME)
        self.assertEqual([x.hex for x in walker], log)
github sjagoe / cygit2 / test / test_revwalk.py View on Github external
def test_sort(self):
        walker = self.repo.walk(log[0], GIT_SORT_TIME)
        walker.sort(GIT_SORT_TIME | GIT_SORT_REVERSE)
        self.assertEqual([x.hex for x in walker], list(reversed(log)))
github presslabs / gitfs / gitfs / cache / commits.py View on Github external
def update(self):
        new_commits = {}
        head = self.repo.lookup_reference("HEAD").resolve().target

        for commit in self.repo.walk(head, GIT_SORT_TIME):
            commit_time = datetime.fromtimestamp(commit.commit_time)

            date = commit_time.date().strftime("%Y-%m-%d")
            time = commit_time.time().strftime("%H-%M-%S")

            if date not in new_commits:
                new_commits[date] = []

            insort_left(
                new_commits[date], Commit(commit.commit_time, time, commit.hex[:10])
            )

        self.__commits = new_commits
github AKSW / QuitStore / quit / git.py View on Github external
def history(self):
        walker = self._repository._repository.walk(self._commit.oid, pygit2.GIT_SORT_TIME)

        c0 = self._commit
        e0 = c0.tree[self.name]

        for c1 in walker:
            try:
                e1 = c1.tree[self.name]
                if e0 and e0.oid != e1.oid:
                    yield Node(self._repository, c1, self.name)
            except KeyError:
                return

            c0 = c1
            e0 = e1
github rafaelmartins / blohg / blohg / vcs_backends / git / filectx.py View on Github external
def _last_changeset(self):
        try:
            ref = self._repo.lookup_reference('refs/heads/master')
        except Exception:
            return
        head = ref.peel()
        for commit in self._repo.walk(ref.target,
                                      GIT_SORT_TOPOLOGICAL |
                                      GIT_SORT_TIME):
            diff = self._repo.diff(head, commit)
            for patch in diff:
                try:
                    new_file_path = patch.delta.new_file.path
                except AttributeError:
                    new_file_path = patch.new_file_path
                if new_file_path == self._path:
                    return head
            head = commit
github hforge / itools / database / git.py View on Github external
pattern
          grep    -- filter out commits whose message does not match the
                     given pattern
          reverse -- return results in reverse order
        """
        # Get the sha
        sha = self._resolve_reference(reference)

        # Sort
        sort = GIT_SORT_TIME
        if reverse is True:
            sort |= GIT_SORT_REVERSE

        # Go
        commits = []
        for commit in self.repo.walk(sha, GIT_SORT_TIME):
            # --author=
github sdg-mit / gitless / gitless / core.py View on Github external
def walker(git_repo, target, reverse):
  flags = pygit2.GIT_SORT_TOPOLOGICAL | pygit2.GIT_SORT_TIME
  if reverse:
    flags = flags | pygit2.GIT_SORT_REVERSE
  return git_repo.walk(target, flags)
github sagemath / sage-workflow / sagedev / pr_export.py View on Github external
return resp


def get_attachement(num, attachment):
  url = TRAC_HTTP + "/raw-attachment/ticket/%d/%s" % (num, attachment)
  print url
  resp = requests.get(url)
  print resp.status_code
  if resp.status_code == 200:
    return resp.text
  return None


repo = Repository(GIT_REPO)

for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):
  try:
    tickets = re.findall('#[0-9]+', commit.message)
    if tickets:
      if len(commit.parents) != 1:
        continue
      base = commit.parents[0].hex
      head = commit.hex
      title = commit.message
      ticket = tickets[0][1:]
      body = "PR for issue #%s" % (ticket)
      trac_ticket = trac._tracserver.ticket.get(ticket)
      num, updated, created, props = trac_ticket
      if props['status'] != 'closed':
        continue
      print commit.message
      branch = 'issue_branch_' + ticket
github presslabs / gitfs / gitfs / views / history_index.py View on Github external
def _get_commits_by_date(self, date):
        """
        Retrieves all the commits from a particular date.

        :param date: date with the format: yyyy-mm-dd
        :type date: str
        :returns: a list containg the commits for that day. Each list item
            will have the format: hh:mm:ss-, where short_sha1 is
            the short sha1 of the commit.
        :rtype: list
        """

        date = datetime.strptime(date, '%Y-%m-%d').date()
        commits = []
        for commit in self.repo.walk(self.repo.head.target, GIT_SORT_TIME):
            commit_time = datetime.fromtimestamp(commit.commit_time)
            if  commit_time.date() == date:
                time = commit_time.time().strftime('%H:%M:%S')
                commits.append("%s-%s" % (time, commit.hex[:10]))

        return commits