Exemplo n.º 1
0
func (lfs localfileservice) PostCommit(c objects.Commit) (err error) {
	lfs.PostBlob(objects.Blob(c.Bytes()))
	filepath := fmt.Sprintf("bin/commits/%s/%d", c.Hkid.Hex(), c.Version)
	//log.Printf("[localfileservice] PostCommit %s\n\t%d", filepath, c.Version())
	dirpath := fmt.Sprintf("bin/commits/%s", c.Hkid.Hex())
	err = os.MkdirAll(dirpath, 0764)
	err = ioutil.WriteFile(filepath, c.Bytes(), 0664)
	return
}
Exemplo n.º 2
0
func (k kademliaservice) PostCommit(c objects.Commit) (err error) {
	values := url.Values{}
	values.Add("type", "commit")
	values.Add("hkid", c.Hkid.Hex())
	data, err := k.postobject(values, c.Bytes())
	if err != nil {
		log.Println(err)
		log.Printf("%s", data)
		return err
	}
	return err
}
Exemplo n.º 3
0
func indexCommit(inCommit objects.Commit) {
	indexBlob(inCommit.Bytes())
	hashHex := inCommit.Hash().Hex()
	blobIndex[hashHex] = blobIndex[hashHex].insertType("Commit")
	blobIndex[inCommit.Hkid.Hex()] =
		blobIndex[inCommit.Hkid.Hex()].insertType("Repository")
	blobIndex[hashHex] =
		blobIndex[hashHex].insertCollection(inCommit.Hkid.Hex())
	if _, present := blobIndex[inCommit.ListHash.Hex()]; !present {
		blobIndex[inCommit.ListHash.Hex()] =
			blobIndexEntry{HCID: inCommit.ListHash.Hex()}
	}
	blobIndex[inCommit.ListHash.Hex()] =
		blobIndex[inCommit.ListHash.Hex()].insertRefCommits(hashHex)

	if commitIndex == nil {
		commitIndex = make(map[string]commitIndexEntry)
	}
	if _, present := commitIndex[inCommit.Hkid.Hex()]; !present {
		commitIndex[inCommit.Hkid.Hex()] = commitIndexEntry{}
	}
	commitIndex[inCommit.Hkid.Hex()] =
		commitIndex[inCommit.Hkid.Hex()].insertVersion(
			inCommit.Version,
			inCommit.Hash(),
		)
	insertDescendantS(inCommit.Parents, inCommit.Hash(), inCommit.Version)
}
Exemplo n.º 4
0
func get(objecthash objects.HID, path string, typeString string) (b objects.Blob, err error) {
	//typeString := "commit"
	err = nil
	nameSegments := []string{"", path}
	for {
		if len(nameSegments) > 1 {
			nameSegments = strings.SplitN(nameSegments[1], "/", 2)
		} else {
			nameSegments = []string{""}
		}
		//log.Printf("\n\tPath: %s\n\tType: %v\n\tobjecthash: %v\n",
		//	nameSegments, typeString, objecthash)
		switch typeString {
		case "blob":
			b, err = GetBlob(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			return b, err
		case "list":
			var l objects.List
			l, err = GetList(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			typeString, objecthash = l.HashForNamesegment(nameSegments[0])
			if objecthash == nil && nameSegments[0] != "" {
				err = fmt.Errorf("Blob not found")
			}
			b = l.Bytes()
		case "tag":
			var t objects.Tag
			//if nameSegments[0] == "" {
			//	log.Printf("\n\tNo Path\n")
			//}
			t, err = GetTag(objecthash.(objects.HKID), nameSegments[0])
			if err != nil {
				//log.Printf("\n\t%v\n", err)
				return nil, err
			}
			if !t.Verify() {
				return nil, fmt.Errorf("Tag Verify Failed")
			}
			typeString = t.TypeString
			objecthash = t.HashBytes
			b = t.Bytes()
		case "commit":
			var c objects.Commit
			c, err = GetCommit(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			if !c.Verify() {
				return nil, fmt.Errorf("Commit Verify Failed")
			}
			var l objects.List
			l, err = GetList(c.ListHash)
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			typeString, objecthash = l.HashForNamesegment(nameSegments[0])
			if objecthash == nil && nameSegments[0] != "" {
				err = fmt.Errorf("Blob not found")
			}
			//if err != nil {
			//	log.Printf("%v\n", err)
			//}
			b = l.Bytes()
		default:
			log.Printf("\n\t%v\n", err)
			panic(err)
		}
		//if len(nameSegments) == 1 && typeString != "blob" {
		if objecthash == nil {
			return b, err
		}
	}
}