MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / parseRevID

Function parseRevID

db/revision.go:441–459  ·  view source on GitHub ↗

parseRevID splits a revision ID into generation number and hex digest. Returns an error if the revID is invalid.

(revid string)

Source from the content-addressed store, hash-verified

439
440// parseRevID splits a revision ID into generation number and hex digest. Returns an error if the revID is invalid.
441func 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

Callers 2

ParseRevIDFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected