Expose libgit2's git_reference_create_matching (atomic compare-and-swap ref update)

オープン
#1,013 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
c, ruby

調査の方向性

ReferenceCollection#create から始め、#update および既存の libgit2 バインディングと比較します。issue に記載されている current_id の結果(シンボリックターゲットを含む)を対象とするカバレッジを追加し、その後 CHANGELOG と rdoc を更新します。提案された API の動作がテストされ、文書化されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Motivation

I'd like to advance a reference atomically from in-process Rugged, the way
git update-ref <ref> <new-oid> <old-oid> does on the command line: update the
ref to a new OID only if it still points at the OID I expect. This is the one
operation that currently forces a service doing everything else in-process
(index build, Rugged::Commit.create, reads) to shell out to git.

libgit2 has the primitive -- git_reference_create_matching, which takes a
current_id and returns GIT_EMODIFIED if the ref has moved -- but Rugged
doesn't currently surface it. ReferenceCollection#create calls plain
git_reference_create, and #update uses git_reference_set_target; neither
lets the caller pass an expected current value.

Proposed API

Add a :current_id option to ReferenceCollection#create, dispatching to
git_reference_create_matching when present:

# advance refs/heads/main to new_oid only if it still points at base_oid
repo.references.create("refs/heads/main", new_oid,
                       force: true, current_id: base_oid)

Outcomes:

  • ref points at current_id -> updated, returns the new Rugged::Reference
  • ref exists but points elsewhere -> no change, returns nil (this mirrors how
    merge_trees returns nil on GIT_EMERGECONFLICT and rebase.commit on
    GIT_EAPPLIED -- a CAS miss is an expected outcome under concurrency, not an
    error)
  • ref does not exist -> raises Rugged::ReferenceError (libgit2's not-found)
  • :current_id with a symbolic target -> ArgumentError (CAS is OID-only)
Open question

Is create the right home for this, or would you prefer it on #update, or a
dedicated method? I put it on create because that mirrors libgit2's own
naming (..._create_matching) and handles both create-if-absent and
conditional-update in one call, but I'm happy to reshape it to whatever fits
Rugged's conventions best.

Status

I'm opening a PR alongside this issue (thin C wrapper + tests covering all the
outcomes above + CHANGELOG/rdoc). Happy to rework the API shape before it's
merged if you'd prefer a different form.

主要言語
C
スター
2.3k
フォーク
293
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

libgit2/rugged のほかの issue

libgit2/rugged の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。