parseRevID splits a revision ID into generation number and hex digest. Returns an error if the revID is invalid.
(revid string)
| 439 | |
| 440 | // parseRevID splits a revision ID into generation number and hex digest. Returns an error if the revID is invalid. |
| 441 | func parseRevID(revid string) (int, string, error) { |
| 442 | if revid == "" { |
| 443 | return 0, "", errors.New("empty revID passed to parseRevID") |
| 444 | } |
| 445 | |
| 446 | idx := strings.Index(revid, "-") |
| 447 | if idx == -1 { |
| 448 | return -1, "", fmt.Errorf("parseRevID found no separator in rev %q", revid) |
| 449 | } |
| 450 | |
| 451 | gen, err := strconv.Atoi(revid[:idx]) |
| 452 | if err != nil { |
| 453 | return -1, "", fmt.Errorf("parseRevID unexpected generation in rev %q: %s", revid, err) |
| 454 | } else if gen < 1 { |
| 455 | return -1, "", fmt.Errorf("parseRevID unexpected generation in rev %q", revid) |
| 456 | } |
| 457 | |
| 458 | return gen, revid[idx+1:], nil |
| 459 | } |
| 460 | |
| 461 | // compareRevIDs compares the two rev IDs and returns: |
| 462 | // 1 if id1 is 'greater' than id2 |
no test coverage detected