Expose libgit2's git_reference_create_matching (atomic compare-and-swap ref update)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
調査の方向性
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 newRugged::Reference - ref exists but points elsewhere -> no change, returns
nil(this mirrors how
merge_treesreturnsnilonGIT_EMERGECONFLICTandrebase.commiton
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_idwith 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 はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
libgit2/rugged のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
LFS support? オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
level/task module/gcp type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
hapostgres/pg_auto_failover#1190 ·
-
docs
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
P3 sonic-vpp
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sonic-net/sonic-buildimage#29662 ·