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:
cyph3rasi
2026-07-11 19:42:05 -07:00
committed by Hop
parent ff62e89596
commit 4364e1d8a4
4 changed files with 54 additions and 15 deletions
+21
View File
@@ -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.