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

Function ParseRevisions

db/revtree.go:787–816  ·  view source on GitHub ↗

ENCODED REVISION LISTS (_revisions): Parses a CouchDB _rev or _revisions property into a list of revision IDs

(ctx context.Context, body Body)

Source from the content-addressed store, hash-verified

785
786// Parses a CouchDB _rev or _revisions property into a list of revision IDs
787func ParseRevisions(ctx context.Context, body Body) []string {
788 // http://wiki.apache.org/couchdb/HTTP_Document_API#GET
789
790 revisionsProperty, ok := body[BodyRevisions]
791 if !ok {
792 revid, ok := body[BodyRev].(string)
793 if !ok {
794 return nil
795 }
796 if genOfRevID(ctx, revid) < 1 {
797 return nil
798 }
799 oneRev := make([]string, 0, 1)
800 oneRev = append(oneRev, revid)
801 return oneRev
802 }
803
804 // Revisions may be stored in a Body as Revisions or map[string]interface{}, depending on the source of the Body
805 var revisions Revisions
806 switch revs := revisionsProperty.(type) {
807 case Revisions:
808 revisions = revs
809 case map[string]interface{}:
810 revisions = Revisions(revs)
811 default:
812 return nil
813 }
814
815 return revisions.ParseRevisions()
816}
817
818// Splits out the "start" and "ids" properties from encoded revision list
819func splitRevisionList(revisions Revisions) (int, []string) {

Callers 3

handlePutDocMethod · 0.92
handleBulkDocsMethod · 0.92
TestParseRevisionsFunction · 0.85

Calls 3

ParseRevisionsMethod · 0.95
genOfRevIDFunction · 0.85
RevisionsTypeAlias · 0.85

Tested by 1

TestParseRevisionsFunction · 0.68