libgit2 / libgit2/libgit2sharp

repo.Commits.QueryBy(<path>) doesn't return entire history of changing commits

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

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

主要言語
C#
スター
3.5k
フォーク
925
PR マージ指標
30日以内にマージされた PR はありません

説明

I was playing around with using CommitLog.QueryBy() to obtain the history of a specific file, and I am not clear if I'm using the feature correctly, but not getting the output I would expect.

Specifically, in a sample repo with 5 commits where each commit changes the same file, .QueryBy() appears to omit the commit that is merging and changing the file.

Is it possible this is by design, and the merge change in Iteration 4 is being purposefully omitted, or might this be a bug?

Here's the output of my sample program:

History of sample.txt has 4 entries:
 - 742d4c5d1fa8c8b4f3fd6894580cb33e7a3ab4e0: Iteration 5
 - 0cbfdb9a0f98ef3e62ba9e8f2d5dd6ef9bd755f6: Iteration 2
 - 59947c86d20f45b6f19dfd52dcbc4c4b23fc4d16: Iteration 3
 - 020323b5bc36f931442343df6aa0557e8d20581f: Iteration 1
Commit history has 5 entries:
 - 742d4c5d1fa8c8b4f3fd6894580cb33e7a3ab4e0: Iteration 5
 - d096877e0d40c0a002e73c308a50d94d6ffbcb67: Iteration 4
 - 0cbfdb9a0f98ef3e62ba9e8f2d5dd6ef9bd755f6: Iteration 2
 - 59947c86d20f45b6f19dfd52dcbc4c4b23fc4d16: Iteration 3
 - 020323b5bc36f931442343df6aa0557e8d20581f: Iteration 1

Here's the code that i'm running against a sample repo (see below):

using LibGit2Sharp;
using System;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        // This program is compiled against:
        // - LibGit2Sharp v0.23.0
        // - Native binaries v1.0.129
        static void Main(string[] args)
        {
            var repo = new Repository(Repository.Discover(Environment.CurrentDirectory));

            var filePath = "sample.txt";

            // Look at the history of sample.txt
            var fileHist = repo.Commits.QueryBy(filePath).Select(x => x.Commit).ToList();
            Console.WriteLine("History of {0} has {1} entries:", filePath, fileHist.Count);
            foreach (var commit in fileHist)
                Console.WriteLine(" - {0}: {1}", commit.Sha, commit.MessageShort);

            // Look at the entire history
            var fullHist = repo.Commits.ToList();
            Console.WriteLine("Commit history has {1} entries:", filePath, fullHist.Count);
            foreach (var commit in fullHist)
                Console.WriteLine(" - {0}: {1}", commit.Sha, commit.MessageShort);
        }
    }
}

Here's the script to create a sample git repo that has a diamond pattern of commits around a file:

@REM create a git repo with a single file
git init
echo 1 > sample.txt
git add sample.txt
git commit -m "Iteration 1"

@REM create a branch and make a change
git checkout -b "branch"
echo 2 >> sample.txt
git commit -a -m "Iteration 2"

@REM make a change on the master
git checkout master
echo 3 >> sample.txt
git commit -a -m "Iteration 3"

@REM merge branch into master and overwrite conflict
git merge branch
echo 1 > sample.txt
echo 2 >> sample.txt
echo 3 >> sample.txt
echo 4 >> sample.txt
git commit -a -m "Iteration 4"

@REM one last change for good measure
echo 5 >> sample.txt
git commit -a -m "Iteration 5"

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まずサンプルリポジトリを再現し、issue に示されている repo.Commits.QueryBy(filePath) コードを repo.Commits の完全な履歴に対して実行します。エントリポイントの CommitLog.QueryBy を調べ、マージコミットがどのように扱われているかを比較します。Iteration 4 のマージコミットが表示されるべきかを判断し、動作を修正するか、意図された結果を文書化すれば完了です。

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

評価

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

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

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