Rename detection misses renames in large commits; adopt C git's algorithm

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
git, java

調査の方向性

Start with RenameDetector, DiffConfig, and the existing rename-detection tests and benchmarks; the issue also names diffcore-rename.c as the behavioral reference. Trace parsing of diff.renameAlgorithm, diff.renameLimit, and diff.renames, then add coverage for basename matching, C Git-compatible scores, limits, and copy detection. Done means the opt-in basename algorithm matches the expected C Git pairings and scores, the copy case works, and benchmark results demonstrate improved runtime and allocation without changing matrix defaults.

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

説明

Description

Problem

When a commit moves many slightly edited files (e.g. a directory or package move that also touches each file), JGit either finds no renames or becomes very expensive:

  • With the default diff.renameLimit (400), inexact detection is skipped as soon as more than 400 files are added or deleted: every rename is reported as a deletion plus an addition.
  • Raising the limit makes the matrix algorithm quadratic: about 8 s and 3.1 GB allocated per diff for 1000 files.
  • C git reports all renames of the same commit with its default settings.

Scenario

  • N files of 50 lines in old/dir0..dir9/, moved to new/dir0..dir9/.
  • One line out of ten is edited in every file, so no rename is exact (C git scores them 85-86%).
  • MOVE keeps the basename (File1.java); RENAME also changes it (Renamed1.java), so matching by name cannot help.

Renames reported with default settings:

Files JGit (matrix, limit 400) C git 2.54 Proposed (basename, limit 1000)
100 100 100 100
1000 0 (over limit) 1000 1000

Cost with the limit disabled (JMH, JDK 25, rename score 60 for both; both find all renames):

Case Files matrix basename Allocated per op
MOVE 100 33 ms 0.9 ms 30.9 MB → 1.3 MB
MOVE 1000 7992 ms 27 ms 3.1 GB → 12.8 MB
RENAME 100 32 ms 1.8 ms 30.9 MB → 1.3 MB
RENAME 1000 8415 ms 128 ms 3.1 GB → 12.8 MB

Proposal

Add an opt-in algorithm following C git's diffcore-rename.c, selected with diff.renameAlgorithm = basename (default stays matrix):

  1. Pair identical content first, preferring the same basename.
  2. Then compare files whose basename is unique among the remaining sources and destinations.
  3. Then score content, keeping the 4 best sources per destination. Similarity is computed like C git, so scores match git diff -M.
  4. Honor diff.renames = copies like git diff -C; log --follow and blame keep following renames only.
  5. Use C git's defaults (score 50, limit 1000) when the algorithm is configured; an explicit diff.renameLimit still wins.

Planned changes, as one review chain:

  1. Similarity index compatible with C git
  2. Basename algorithm in RenameDetector, with a benchmark
  3. diff.renameAlgorithm configuration
  4. Copy detection
Motivation
  • Tools built on JGit (code review, hosting, IDEs) show large refactorings as unrelated deletions and additions, while git shows renames.
  • Results should be consistent with the git CLI, in pairings and scores.
  • diff.renames = copies is parsed (DiffConfig#getRenameDetectionType() returns COPY) but never used: modified files are never considered as sources, so a file copied from one that still exists shows up as an addition, unlike with git diff -C.
Alternatives considered
  • Raising diff.renameLimit: works, but costs 8 s and 3.1 GB per diff for 1000 files.
  • Optimizing the matrix algorithm in place: it would still score every pair, and changing its scoring would change results for all users. Hence opt-in.
  • Making the new algorithm the default: could be discussed once it has been used for a while.
Additional context
  • I have an implementation with tests (expected results taken from C git) and the benchmark. I will push it to Gerrit and link the changes here.
  • Feedback welcome on: the option name and values, and whether the defaults should depend on the configured algorithm.
  • Related: #110. RenameDetector still defaults to a score of 60; this proposal leaves the matrix defaults unchanged.
  • The implementation was developed with AI assistance. I have reviewed and tested it and will answer for it in review. Commits carry Assisted-by trailers, and largely generated files the AI disclosure header described in the Eclipse handbook.
主要言語
Java
スター
427
フォーク
116
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

eclipse-jgit/jgit のほかの issue

eclipse-jgit/jgit の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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