microsoft / microsoft/FluidFramework
Duplicate Code: GitRest route FS manager + soft-delete check
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.9k
- Forks
- 586
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 146
Description
🔍 Duplicate Code Detected: GitRest route FS manager + soft-delete check
Analysis of commit edf996f5e3b26fc2478218abdaee30e68b4af010
Assignee: @copilot
Summary
Several GitRest route handlers repeat the same multi-step block to:
- choose a filesystem manager factory (
getFilesystemManagerFactory), - create an
fsManagerrooted atrepoManager.path, and await checkSoftDeleted(...)before performing the actual repo operation.
This is >10 lines per instance and appears repeatedly across multiple routes, increasing the risk of inconsistent future changes (e.g., changing soft-delete behavior, params, or ephemeral handling).
Duplication Details
Pattern: getFilesystemManagerFactory + fsManager.create(...) + checkSoftDeleted(...)
-
Severity: Medium
-
Occurrences: 15 (across 8 files)
-
Locations:
server/gitrest/packages/gitrest-base/src/routes/git/blobs.ts(lines 37-48, 67-78)server/gitrest/packages/gitrest-base/src/routes/git/commits.ts(lines 40-51)server/gitrest/packages/gitrest-base/src/routes/git/refs.ts(lines 48-59, 74-85, 107-118, 137-148, 167-178)server/gitrest/packages/gitrest-base/src/routes/git/tags.ts(lines 40-51, 66-77)server/gitrest/packages/gitrest-base/src/routes/git/trees.ts(lines 38-49, 64-75)server/gitrest/packages/gitrest-base/src/routes/repository/commits.ts(lines 41-52)server/gitrest/packages/gitrest-base/src/routes/repository/contents.ts(lines 33-44)server/gitrest/packages/gitrest-base/src/routes/summaries.ts(lines 293-304)
-
Code Sample (from
server/gitrest/packages/gitrest-base/src/routes/git/refs.ts):const fileSystemManagerFactory = getFilesystemManagerFactory( fileSystemManagerFactories, repoManagerParams.isEphemeralContainer ?? false, ); const fsManager = fileSystemManagerFactory.create({ ...repoManagerParams.fileSystemManagerParams, rootDir: repoManager.path, }); await checkSoftDeleted( fsManager, repoManager.path, repoManagerParams, repoPerDocEnabled, );
Impact Analysis
- Maintainability: Any change to soft-delete enforcement, filesystem initialization, or routing params must be repeated in many route handlers.
- Bug Risk: Higher chance of drift (some routes updated, others missed), especially across
open(...)vsgetRepoManagerFromWriteAPI(...)call sites. - Code Bloat: 15 near-identical blocks across related routes.
Refactoring Recommendations
-
Extract a shared helper for “open repo + create fsManager + soft-delete check”
- Suggested location:
server/gitrest/packages/gitrest-base/src/utils(near existingcheckSoftDeleted/ filesystem helpers) - Shape idea: a helper that takes
(repoManagerParams, repoPerDocEnabled, fileSystemManagerFactories, repoManagerFactory, openMode)and returns{ repoManager, fsManager }. - Benefits: single place to adjust soft-delete behavior and fsManager creation.
- Suggested location:
-
Optionally provide an inline wrapper to reduce boilerplate per route
- Example:
withRepoAndFsManager(repoManagerFactory, fileSystemManagerFactories, repoManagerParams, repoPerDocEnabled, async ({repoManager, fsManager}) => { ... }) - Benefits: keeps route handlers focused on request-specific logic.
- Example:
Implementation Checklist
- Confirm intended behavior differences between
repoManagerFactory.open(...)andgetRepoManagerFromWriteAPI(...)and encode that in the helper API - Implement helper and migrate the 8 affected route modules
- Ensure error handling (
logAndThrowApiError) continues to includerepoManagerParams - Run server/gitrest tests (if present) and validate endpoints
Analysis Metadata
- Analyzed Files: 2,792 non-test
.ts/.mjs/.cjstracked files (excluded.d.ts, tests, and.github/workflows) - Detection Method: Serena-assisted semantic review + duplicate 12-line block detection
- Commit:
edf996f5e3b26fc2478218abdaee30e68b4af010 - Analysis Date: 2026-03-28
Generated by Duplicate Code Detector · ◷
To install this agentic workflow, run
gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with checkSoftDeleted and the filesystem helpers under server/gitrest/packages/gitrest-base/src/utils, then compare the repeated blocks in the eight listed route modules, especially repoManagerFactory.open(...) and getRepoManagerFromWriteAPI(...) call sites. Define and implement a shared helper that preserves their behavior, migrate all 15 occurrences, retain error context, and run the server/gitrest tests and endpoint validation if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100