libgit2 / libgit2/pygit2

Broken GIT_SORT_TIME ?

未关闭
#747 17 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
1.7k
派生
408
平均合并
2 天 57 分钟
30 天内合并 PR
7

描述

This is a script to reproduce the behavior I'm seeing:

#!/usr/bin/env python

import tempfile
import time
import os

import pygit2

path = tempfile.mkdtemp(prefix='pygit2_test_')
repo = pygit2.init_repository(path)

author = pygit2.Signature('Alice Author', 'alice@authors.tld')
committer = pygit2.Signature('Cecil Committer', 'cecil@committers.tld')

# Commit #1

 # Create a file in that git repo
with open(os.path.join(path, 'sources'), 'w') as stream:
    stream.write('foo\n bar')
repo.index.add('sources')
repo.index.write()

parents = []
# Commits the files added
tree = repo.index.write_tree()
print(repo.create_commit(
    'refs/heads/master',  # the name of the reference to update
    author,
    committer,
    'Commit #1',
    # binary string representing the tree object ID
    tree,
    # list of binary strings representing parents of the new commit
    parents,
))
commit1 = repo.revparse_single('HEAD')
time.sleep(0.1)

# Commit #2

parents = [commit1.oid.hex]

subfolder = os.path.join('folder1', 'folder2')
os.makedirs(os.path.join(path, subfolder))
# Create a file in that git repo
with open(os.path.join(path, subfolder, 'file'), 'w') as stream:
    stream.write('foo\n bar\nbaz')
repo.index.add(os.path.join(subfolder, 'file'))
repo.index.write()

# Commits the files added
tree = repo.index.write_tree()
print(repo.create_commit(
    'refs/heads/master',  # the name of the reference to update
    author,
    committer,
    'Commit #2',
    # binary string representing the tree object ID
    tree,
    # list of binary strings representing parents of the new commit
    parents
))
commit2 = repo.revparse_single('HEAD')
time.sleep(0.1)


# Commit #3

parents = [commit2.oid.hex]

# Update the sources file
with open(os.path.join(path, 'sources'), 'w') as stream:
    stream.write('foo\n bar\nbaz!')
repo.index.add('sources')
repo.index.write()

# Commits the files added
tree = repo.index.write_tree()
print(repo.create_commit(
    'refs/heads/master',  # the name of the reference to update
    author,
    committer,
    'Commit #3',
    # binary string representing the tree object ID
    tree,
    # list of binary strings representing parents of the new commit
    parents
))
commit3 = repo.revparse_single('HEAD')


print('')
main_walker = repo.walk(commit3.oid.hex, pygit2.GIT_SORT_TIME)
commits_msgs = []
while 1:
    try:
        com = main_walker.next()
        print(com.message)
        print(com.oid.hex)
    except StopIteration:
        break

It gives me the following output:

7335ffcfdb2039a9631ef5c891ec6a12feaeb342
50ea7d4691ee78b60323ac1d4174a6609190fbaf
47e61d2eaa8c5d3d1562475a43aa99c0e7fb9b8a

Commit #3
47e61d2eaa8c5d3d1562475a43aa99c0e7fb9b8a
Commit #1
7335ffcfdb2039a9631ef5c891ec6a12feaeb342
Commit #2
50ea7d4691ee78b60323ac1d4174a6609190fbaf

The first three lines are the commit as they are committed.
The following lines are the commit message and hash as repo.walk(commit3, pygit2.GIT_SORT_TIME) is returning them.

Something looks broken to me :)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行复现脚本,并检查使用 GIT_SORT_TIME 时 repo.walk 的 pygit2 绑定。将观察到的顺序与文档中说明的排序行为以及现有的 walker 测试进行比较;当顺序得到修正,或通过回归测试清楚地记录该行为时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, python
领域
devtools
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。