libgit2 / libgit2/pygit2

Broken GIT_SORT_TIME ?

オープン
#747 コメント 17 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
1.7k
フォーク
408
平均マージ
2日 57分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず再現スクリプトを実行し、GIT_SORT_TIME を指定した repo.walk の pygit2 バインディングを調査します。観測された順序を、文書化されているソート動作および既存の walker テストと比較します。順序が修正されるか、回帰テストによって動作が明確に文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
git, python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。