Skip to content

Optimizations to git integration - #134

Merged
Avni2000 merged 10 commits into
mainfrom
stream-notebooks
Feb 22, 2026
Merged

Avni2000 merged 10 commits into
mainfrom
stream-notebooks

Conversation

@Avni2000

@Avni2000 Avni2000 commented Feb 22, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Performance

    • Optimized git path resolution performance through enhanced indexing and batch read operations for faster repository path lookups.
  • Bug Fixes

    • Enhanced reliability of Git file path resolution and context detection.
    • Improved error handling and messaging for better diagnostics during git operations, including edge cases and Windows path compatibility.

@coderabbitai

coderabbitai Bot commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Refactors git integration by introducing normalized path comparison, per-root repository path indexing for faster resolution, replacing status porcelain queries with diff-based unmerged detection, and implementing batch-based git-cat-file operations for three-way merge version retrieval with fallback mechanisms.

Changes

Cohort / File(s) Summary
Path Normalization & Comparison
src/gitIntegration.ts
Introduces normalized path info objects and target-based comparison helpers. Adds utilities for resolving real paths and normalizing status paths, with improved Windows long/short name mismatch handling.
Repository Indexing & Caching
src/gitIntegration.ts
Implements per-root index of repository paths to accelerate file-to-repository path resolution. Includes population and querying logic for the index with fallback to unmerged status scanning.
Unmerged File Detection
src/gitIntegration.ts
Replaces git status porcelain approach with diff-based detection (git diff --name-only --diff-filter=U -z). Updates line parsing to use NUL-terminated records and adjusts error handling accordingly.
Batch Three-Way Version Retrieval
src/gitIntegration.ts
Introduces streaming-based git-cat-file --batch for fetching base/current/incoming stage versions in single operations. Includes batch reader, robust output parsing with missing file handling, and per-stage fallback mechanism.
Context-Based File Resolution
src/gitIntegration.ts
Adds resolveGitFileContext helper and high-level functions (readGitShowFromStage, readGitShowFromStages). Refactors getThreeWayVersions, getBaseVersion, getCurrentVersion, and getIncomingVersion to use context-based resolver while preserving public signatures.
Error Handling & Logging
src/gitIntegration.ts
Updates error messages and logging to reflect batch operations, index lookups, streaming strategies, and improved diagnostics for git diff/batch failures and partial outputs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

Poem

🐰 Hop hop! The paths now dance in batches,
Git repos indexed, no more mismatches,
Windows long names hide from our sight,
Three-way merges, streaming so bright,
Internal refactored to pure delight! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Optimizations to git integration' accurately reflects the main focus of the changes, which involve multiple performance-oriented refactorings to path resolution, unmerged file querying, and version retrieval in git integration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch stream-notebooks

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/gitIntegration.ts (1)

759-971: Batch cat-file --batch reader is well implemented, with one small consistency nit.

The streaming parser correctly handles the git batch protocol (header parsing, content+trailing-LF extraction, missing responses) and the byte-level buffer queue avoids unnecessary copies. The canUseBatchStageRead guard for newline-containing paths and the fallback to per-stage reads is a nice resilience pattern.

Minor nit: Line 963 uses stdin.on('error', ...) while all other event handlers (stdout.on('data'), gitShow.once(...)) use .once() for lifecycle events. Consider using stdin.once('error', ...) for consistency—although functionally harmless since reject is a no-op after the first call.

Consistency fix
-        stdin.on('error', (error) => {
+        stdin.once('error', (error) => {
             reject(error);
         });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gitIntegration.ts` around lines 759 - 971, In readGitShowFromStages, make
the error handler on the git child stdin consistent with the other one-time
handlers by replacing stdin.on('error', ...) with stdin.once('error', ...) so
the error callback is registered exactly once (match the style used for
gitShow.once and keep rejection behavior unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/gitIntegration.ts`:
- Around line 1024-1041: In queryUnmergedFilesForRoot, do not hardcode status:
'UU' for entries coming from streamGitUnmergedPaths; instead inspect the index
stages via git ls-files -u (or parse its output) to determine the actual
conflict type per repoPath and set status accordingly (e.g., UU, AU, DU, etc.),
while keeping isUnmerged: true; if you intentionally want a simplified marker,
update the inline comment near status in queryUnmergedFilesForRoot to state that
the status is a simplified placeholder and not the real index-stage-derived
conflict type so downstream consumers are aware.

---

Nitpick comments:
In `@src/gitIntegration.ts`:
- Around line 759-971: In readGitShowFromStages, make the error handler on the
git child stdin consistent with the other one-time handlers by replacing
stdin.on('error', ...) with stdin.once('error', ...) so the error callback is
registered exactly once (match the style used for gitShow.once and keep
rejection behavior unchanged).

Comment thread src/gitIntegration.ts Resolved
@Avni2000
Avni2000 merged commit 0492228 into main Feb 22, 2026
5 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Feb 27, 2026
@Avni2000
Avni2000 deleted the stream-notebooks branch March 1, 2026 01:38
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.

1 participant