Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 13, 2025

This PR adds two new methods to Repository that allow creating commit objects without automatically updating references:

  • Repository::commit_raw() - Creates a commit using author/committer from configuration
  • Repository::commit_as_raw() - Creates a commit with explicitly specified author/committer

Problem

The existing Repository::commit() and Repository::commit_as() methods always update the specified reference (like HEAD) after creating the commit object. This coupling makes it difficult to:

  1. Create commit objects in batch operations before updating references
  2. Implement custom reference update strategies
  3. Build higher-level Git operations that need fine-grained control over when references are updated

Solution

The new methods return a gix_object::Commit that can be written to the object database separately using Repository::write_object(). This allows users to:

// Create commit object without updating references
let raw_commit = repo.commit_raw("My commit message", tree_id, parent_ids)?;

// Write it to the database when ready
let commit_id = repo.write_object(&raw_commit)?;

// Update references manually at the appropriate time
// (using existing reference update methods)

Key Features

  • Same API surface: Identical parameters to existing methods, just without the reference parameter
  • Same error handling: Reuses existing commit::Error type for consistency
  • Proper testing: Comprehensive test suite verifying the methods work correctly
  • Documentation: Clear documentation explaining the difference from regular commit methods
  • Example: Working demonstration showing the difference between raw and regular commits

Implementation Details

The implementation extracts the commit object creation logic from the existing commit_as_inner() method, removing the reference update portion. This ensures:

  • No code duplication
  • Consistent commit object format
  • Same validation and error handling
  • Minimal performance overhead

Use Cases

This enables several advanced Git workflows:

  1. Batch operations: Create multiple commits before updating any references
  2. Atomic operations: Group commit creation and reference updates in transactions
  3. Custom merge strategies: Build commits incrementally with precise control
  4. Performance optimization: Reduce reference lock contention in high-throughput scenarios

The methods maintain full compatibility with existing code while providing the flexibility needed for advanced Git operations.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and Byron Sep 13, 2025
@Copilot Copilot AI changed the title [WIP] Create a version of Repository::commit and Repository::commit_as which doesn't set the reference, but just creates a raw commit which then can be written to the object database in a separate step. Add commit_raw and commit_as_raw methods for creating commits without reference updates Sep 13, 2025
Copilot finished work on behalf of Byron September 13, 2025 17:34
@Copilot Copilot AI requested a review from Byron September 13, 2025 17:34
@Byron Byron force-pushed the copilot/fix-01a02b99-91ef-4e27-b90f-19af7d0d252c branch from 707ad35 to 862a809 Compare September 13, 2025 19:08
@Byron Byron marked this pull request as ready for review September 13, 2025 19:08
@Byron Byron force-pushed the copilot/fix-01a02b99-91ef-4e27-b90f-19af7d0d252c branch from 862a809 to d4c2542 Compare September 13, 2025 19:09
@Byron Byron enabled auto-merge September 13, 2025 19:10
@Byron Byron merged commit f891c37 into main Sep 13, 2025
28 checks passed
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.

2 participants