Make prompt capture fast and resilient
Hop-State: A_06FN8D0CK06GY5XBDYZ632R Hop-Proposal: R_06FN8CY2FJBV5QA0WFEDWHR Hop-Task: T_06FN8C4PMFJRT8APV4G03Y8 Hop-Attempt: AT_06FN8C4PMFRJEE4B7KKQ740
This commit is contained in:
@@ -655,6 +655,27 @@ func (r *Repository) ReadHiddenRef(ctx context.Context, name string) (oid string
|
||||
return r.ReadRef(ctx, ref)
|
||||
}
|
||||
|
||||
// ListHiddenRefs reads all refs below refs/hop in one Git process. Keys are
|
||||
// relative to refs/hop/ (for example, "states/P_..." or "accepted").
|
||||
func (r *Repository) ListHiddenRefs(ctx context.Context) (map[string]string, error) {
|
||||
output, err := r.run(ctx, nil, nil, "for-each-ref", "--format=%(refname) %(objectname)", hiddenRefPrefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refs := make(map[string]string)
|
||||
for _, line := range strings.Split(strings.TrimSpace(output), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
name, oid, found := strings.Cut(line, " ")
|
||||
if !found || !strings.HasPrefix(name, hiddenRefPrefix) {
|
||||
return nil, fmt.Errorf("unexpected hidden ref listing %q", line)
|
||||
}
|
||||
refs[strings.TrimPrefix(name, hiddenRefPrefix)] = strings.TrimSpace(oid)
|
||||
}
|
||||
return refs, nil
|
||||
}
|
||||
|
||||
// UpdateHiddenRef atomically updates refs/hop/name. With no expectedOld value,
|
||||
// it is unconditional. Passing expectedOld performs compare-and-swap; an empty
|
||||
// expected value means the ref must not exist.
|
||||
|
||||
+9
-13
@@ -1640,17 +1640,17 @@ func (s *Service) reconcileDerivedRefs(ctx context.Context, reconcileAccepted bo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
refs, err := s.Repo.ListHiddenRefs(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, row := range rows {
|
||||
state := row.State
|
||||
if err := s.Repo.VerifyObjects(ctx, state.GitCommit, state.SourceTree); err != nil {
|
||||
return fmt.Errorf("state %s references unavailable Git data: %w", state.ID, err)
|
||||
}
|
||||
name := "states/" + state.ID
|
||||
commit, exists, err := s.Repo.ReadHiddenRef(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists || commit != state.GitCommit {
|
||||
if refs[name] != state.GitCommit {
|
||||
if err := s.Repo.VerifyObjects(ctx, state.GitCommit, state.SourceTree); err != nil {
|
||||
return fmt.Errorf("state %s references unavailable Git data: %w", state.ID, err)
|
||||
}
|
||||
if err := s.Repo.UpdateHiddenRef(ctx, name, state.GitCommit); err != nil {
|
||||
return fmt.Errorf("repair Git pin for state %s: %w", state.ID, err)
|
||||
}
|
||||
@@ -1668,11 +1668,7 @@ func (s *Service) reconcileDerivedRefs(ctx context.Context, reconcileAccepted bo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
commit, exists, err := s.Repo.ReadHiddenRef(ctx, acceptedRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists || commit != head.GitCommit {
|
||||
if refs[acceptedRef] != head.GitCommit {
|
||||
if err := s.Repo.UpdateHiddenRef(ctx, acceptedRef, head.GitCommit); err != nil {
|
||||
return fmt.Errorf("repair accepted Git ref: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user