| 34 | } |
| 35 | |
| 36 | func (access *CodeAccess) execute(ctx context.Context, args map[string]any, current *FileReader, run func(*FileReader) (string, error)) (string, error) { |
| 37 | rawSide, supplied := args["side"] |
| 38 | if access == nil { |
| 39 | if supplied { |
| 40 | return "", fmt.Errorf("side is not supported for this task") |
| 41 | } |
| 42 | return run(current) |
| 43 | } |
| 44 | side := "new" |
| 45 | if supplied { |
| 46 | var valid bool |
| 47 | side, valid = rawSide.(string) |
| 48 | if !valid || (side != "new" && side != "old") { |
| 49 | return "", fmt.Errorf("side must be new or old") |
| 50 | } |
| 51 | } |
| 52 | if side == "new" { |
| 53 | return run(&access.newReader) |
| 54 | } |
| 55 | prefix := "SIDE: old\nREVISION: " + access.oldReader.Ref + "\n" |
| 56 | if access.oldReader.Mode == ModeEmpty { |
| 57 | prefix = "SIDE: old\nSOURCE: empty-tree\n" |
| 58 | } |
| 59 | if err := ctx.Err(); err != nil { |
| 60 | return "", fmt.Errorf("%s%w", prefix, err) |
| 61 | } |
| 62 | content, err := run(&access.oldReader) |
| 63 | if err != nil { |
| 64 | return "", fmt.Errorf("%s%w", prefix, err) |
| 65 | } |
| 66 | return prefix + content, nil |
| 67 | } |