MergeResult jgit的行为不正确

时间:2017-03-31 15:47:09

标签: java jgit

已使用的jGit 4.5.0.201609210915-r

版本

我有一个大文件(大约10k行),并且在拉(或合并)期间我有这个文件的冲突。

我有一些代码来获取冲突的行:

 Git git = getGit();
    Repository repo = git.getRepository();
    ThreeWayMerger merger = new StrategyResolve().newMerger(repo, true);
    merger.merge(repo.resolve(Constants.HEAD), repo.resolve(Constants.FETCH_HEAD));
    ResolveMerger resolveMerger = (ResolveMerger) merger;
    Map < String, org.eclipse.jgit.merge.MergeResult <? >> mergeResults = resolveMerger.getMergeResults();
    org.eclipse.jgit.merge.MergeResult <? > mergeChunks = mergeResults.get(fileName);
    if (mergeChunks == null) {
        return null;
    }
    if (!mergeChunks.containsConflicts()) {
        return null;
    }
    for (MergeChunk mergeChunk: mergeChunks) {
            ...get merge chunk and convert to my object
            my object has begin-end lines 
            and which version of file I need use (from my commit or another). 
            After I get lines from sides and display on my panel
    }

之后,在mergeChunks我有一个非常大的序列。它的开头看起来像这样:

0, 0, 0, 2, 1, 1, 2, 7, 2, 2, 2, 7, 0, 0, 7, 8, 0, 1, 8, 10, 0, 0, 10, 11, 0, 1, 11, 13 ...

如果我没错,我们有下表

ConflictState       sourceIndex      begin        end
0                   0                0            2        //No conflict
1                   1                2            7        //First conflict range
2                   2                2            7        //Next conflict range
0                   0                7            8        //No conflict
0                   1                8            10       //No conflict
0                   0                10           11       //No conflict
0                   1                11           13       //No conflict
...
//about on 15+ I have difference, between begin and end of chunk
0                   1                69           71       //No conflict
0                   0                60           61       //No conflict
0                   1                72           74       //No conflict
0                   0                65           66       //No conflict 
...
//end of sequence
0                   0                10387        10388    //No conflict           
0                   1                11501        11502    //No conflict
0                   0                10389        10390    //No conflict
0                   1                11503        11504    //No conflict

我正在尝试通过ConflictState解析它而我正在试着我会得到这样的序列

NoConflict
FirstConflict
NextConflict
NoConflict
FirstConflict
NextConflict
...

但是jGit返回非常大的NoConflict序列(在我的场景中,这个序列大约是5k)。并且文件包含冲突的行

这是jGit的错误还是我做错了什么?

此行为很少出现,但在这种情况下,我无法正常显示冲突行之间的差异。

0 个答案:

没有答案