Skip to content

feat: --git-churn flag to rank clones by git change frequency #23

Closed

Description

@machado144

Problem

Not all clones are equally urgent. A 20-line clone that has been modified 40 times in the last 6 months is a much higher-priority fix than a stable 50-line clone that hasn't changed in 2 years. Today dupehound ranks clones by line count — a purely static metric.

Correlating clones with git log churn gives teams an actionable priority order: fix the clones that are actively causing pain first.

Proposed behavior

Add --git-churn flag. When set, dupehound runs git log --follow -p -- <file> to count commits touching each file in the last N days (default 90), then annotates each clone with the total churn score of its instances (sum of commit counts across all instance files).

# Rank clones by git churn (last 90 days, default)
dupehound scan . --git-churn

# Custom window
dupehound scan . --git-churn --churn-days 180

Example output (text format)

Clone list is re-sorted by churn score when --git-churn is active:

dupehound scan . --git-churn --churn-days 90

Top clones (by churn score, last 90 days):

  #1  type-2  similarity: 1.00  18 lines  2 instances  churn: 47 commits
      src/handlers/payment.go:88-105     (31 commits)
      src/handlers/refund.go:12-29       (16 commits)
      | func validateAmount(v float64) error {

  #2  type-1  similarity: 1.00  42 lines  3 instances  churn: 28 commits
      src/services/auth.go:55-96         (15 commits)
      src/services/session.go:10-51      (8 commits)
      src/services/oauth.go:200-241      (5 commits)
      | func buildTokenClaims(user User) jwt.MapClaims {

  #3  type-3  similarity: 0.78  11 lines  2 instances  churn: 2 commits
      src/utils/old_parser.go:44-54      (1 commit)
      src/utils/legacy.go:88-98          (1 commit)
      (low churn — low priority)

JSON additions

{
  "clones": [
    {
      "hash": "a1b2c3d4",
      "churn_score": 47,
      "instances": [
        {
          "file": "src/handlers/payment.go",
          "file_commits_in_window": 31,
          ...
        }
      ]
    }
  ]
}

Graceful degradation

  • If git is not available or the directory is not a git repo, --git-churn logs a warning and falls back to the default line-count ranking. No error exit.
  • If a file has no git history (e.g., untracked), its churn score is 0.
[warn] git not available — --git-churn disabled, falling back to line-count ranking

Performance

git log is called once per unique file in the clone report (not per clone). Results are cached for the duration of the scan. For typical repos with <500 clone-touched files, this adds <2s overhead.

For very large repos, --churn-days 30 reduces log traversal time.

Backward compatibility

  • --git-churn is opt-in and off by default.
  • Default ranking (by line count × instances) is unchanged when flag is absent.
  • --churn-days is only valid when --git-churn is set; ignored otherwise.
  • All output formats supported; JSON adds churn_score and file_commits_in_window fields.

Activity

  1. added 5 commits that reference this issue on Apr 8, 2026
  2. machado144 commented on Apr 8, 2026

    @machado144
    ContributorAuthor

    Shipped in #24 (merged in 562be6c). The full list of features, tests, and follow-ups is in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址