Skip to content

Split ImitatePass::reencryptFiles - #2425

Merged
annejan merged 1 commit into
mainfrom
refactor/complexity-2157-b4
Dec 1, 2026
Merged

annejan merged 1 commit into
mainfrom
refactor/complexity-2157-b4

Conversation

@annejan

@annejan annejan commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fourth batch for #2157: ImitatePass::reencryptFiles, the largest function left (lizard CCN 55, 306 lines), on its own because it is the re-encryption worker. The code and its comments move into helpers; the run does the same steps in the same order.

Helper What it holds
startReencryptRun() the checks after the run's own pull (unfinished Git operation, a link, the list Init() wrote changed by the pull), leftover recovery, the backup commit
reencryptEntry() one entry; returns false when the run was cancelled meanwhile, and the caller stops as the old break did (no walked, no checked++)
listKeysFor() a list's keys now and before Init(), once per run
readerChangeOf() who would gain the entry, and who was taken off and still reads it
holdForAgreement() the question after the run, or the failure when the entry's bytes cannot be read to hold a yes to
isTrustedEntry(), namedReaders() the former lambdas

The run's record of key IDs, names and list keys is one WhoReads struct; ListKeys, WhoReads and ReaderChange are defined next to ReencryptResult. reencryptFiles 55 → 8, every helper below 15.

Checked by comparing removed and added lines without indentation: the only removed lines that do not come back are renames (primaries → who.primaries, gaining → change.gaining, the lambdas), return result → return false in the start checks, and the two ask branches folded into holdForAgreement(). All seven tr() calls stay in ImitatePass.

Test plan

  • Full make check in a scratch HOME/GNUPGHOME with a Git identity: 36 suites, 2,043 passed, 0 failed (tst_imitatepass and tst_integration cover the question, the removed-reader record, cancel and the pull checks)
  • doxygen Doxyfile prints no warnings
  • clang-format clean

Part of #2157.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Re-encryption now pauses entries that would grant access to additional recipients until they’re reviewed, unless those entries are trusted.
  • Bug Fixes
    • Entries that can’t be read to confirm an agreement are reported as failed.
    • Cancellation and aborted runs now return a clear outcome.

Fourth batch for #2157: the largest function left (lizard CCN 55, 306
lines). The code and its comments move into helpers; the run does the
same steps in the same order.

- startReencryptRun(): the checks after the run's own pull (unfinished
  Git operation, a link, the list Init() wrote changed by the pull), the
  leftovers of an interrupted run and the backup commit.
- reencryptEntry(): one entry, returning false when the run was cancelled
  meanwhile (the caller then stops, as the old break did).
- listKeysFor(): a list's keys now and before Init(), once per run.
- readerChangeOf(): who would gain the entry and who was taken off and
  still reads it.
- holdForAgreement(): the question after the run, or the failure when
  the entry's bytes cannot be read to hold a yes to.
- isTrustedEntry() and namedReaders(): the former lambdas.

The run's record of key IDs, names and list keys is one WhoReads struct;
ListKeys, WhoReads and ReaderChange are defined next to ReencryptResult.

reencryptFiles 55 -> 8; every helper is below 15. No behaviour change.

Part of #2157.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anne Jan Brouwer <[email protected]>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The re-encryption flow now delegates setup, recipient analysis, and per-entry handling to private helpers. The helpers track reader changes, check trusted entries, and hold entries for agreement when re-encryption would add readers.

Changes: Re-encryption flow

Layer / File(s) Summary
Run setup and orchestration
src/imitatepass.h, src/imitatepass.cpp
startReencryptRun reports setup aborts and cancellations with a boolean result. reencryptFiles delegates setup and entry handling to helpers.
Recipient and reader comparison
src/imitatepass.h, src/imitatepass.cpp
New data structures and helpers cache current and previous recipient keys, compare reader sets, and format reader descriptions.
Trust, agreement, and entry processing
src/imitatepass.h, src/imitatepass.cpp
Entry handling checks trust and file paths, records agreement requirements or failures, and re-encrypts eligible entries. Cancellation stops processing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

Possibly related PRs

  • IJHack/QtPass#2375: Both PRs modify the reader-change and agreement flow for entries that would gain readers.
  • IJHack/QtPass#2379: This PR extracts logic that #2379 changed into helpers, so the changes need to be reconciled.

Suggested reviewers: nogeenhenk, nogeenharrie

Merge Risk: Minimal · up to 5a0ba

This refactor splits the re-encryption flow into helpers without changing its behavior. No concrete defect was found, and the reported tests cover the question, removed-reader record, cancellation and pull paths, so no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Split ImitatePass::reencryptFiles" names the main change. The PR extracts helpers (startReencryptRun, reencryptEntry, listKeysFor, readerChangeOf, holdForAgreement, isTrustedEntry, namedRea…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Split ImitatePass::reencryptFiles" names the main change. The PR extracts helpers (startReencryptRun, reencryptEntry, listKeysFor, readerChangeOf, holdForAgreement, isTrustedEntry, namedReaders) out of ImitatePass::reencryptFiles, and the raw summary confirms this refactor in src/imitatepass.cpp and src/imitatepass.h. The title is short, specific, and matches the objectives, which describe this as a refactor with no behavior change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each reader key,
Then sorts the names for all to see.
If new eyes might read a file,
It pauses there a little while.
Approved, it hops the cipher through.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a6fdef24-1f3a-47a2-a2f4-ad17a30e1bc1
Commits

Reviewing files that changed from the base of the PR and between 214c593 and 5a0babc.

Files selected for processing: 2

  • src/imitatepass.cpp
  • src/imitatepass.h

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@nogeenhenk nogeenhenk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5a0babc. The re-encryption worker, so I compared the old function and the new helpers side by side rather than by removed lines alone. The run is the same:

  • startReencryptRun() keeps the order pull, unfinished Git operation, link, list changed by the pull, leftover recovery, backup commit, and sets aborted or cancelled in the same cases.
  • reencryptEntry() returns false only at the two cancel points the old loop left with break, before walked and checked were touched, and the caller sets cancelled and breaks there. A recipientsForDir() failure still returns the result at once.
  • listKeysFor() still runs before primaryKeysOf() for the entry (it is evaluated as an argument of readerChangeOf()), so primaries and names fill in the old order, and the reference it returns into who.lists stays valid: nothing inserts into that hash while readerChangeOf() reads it.
  • holdForAgreement() returns true exactly where the old code set keepRecord (the bytes cannot be held to a yes), false for a question, so walked and stillReadByRemoved come out as before. An entry with no listable recipients still goes straight to reencryptSingleFile().
  • All tr() calls stay in ImitatePass.

Nothing to add.


Generated by Claude Code

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 94.546% (+0.005%) from 94.541% — refactor/complexity-2157-b4 into main

@annejan
annejan merged commit 328c919 into main Dec 1, 2026
33 checks passed
@annejan
annejan deleted the refactor/complexity-2157-b4 branch December 1, 2026 00:26
@annejan annejan mentioned this pull request Dec 1, 2026
18 of 40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants