示例#1
0
文件: pack.go 项目: jbrukh/ggit
func (dp *packedObjectParser) parseTree(size int64) *PackedObject {
	dp.hdr = objects.NewObjectHeader(objects.ObjectTree, size)
	tree := dp.objectParser.parseTree()
	return &PackedObject{
		object: tree,
		bytes:  dp.bytes,
	}
}
示例#2
0
文件: pack.go 项目: jbrukh/ggit
func (dp *packedObjectParser) parseTag(size int64) *PackedObject {
	dp.hdr = objects.NewObjectHeader(objects.ObjectTag, size)
	tag := dp.objectParser.parseTag()
	return &PackedObject{
		object: tag,
		bytes:  dp.bytes,
	}
}
示例#3
0
文件: pack.go 项目: jbrukh/ggit
func (dp *packedObjectParser) parseCommit(size int64) *PackedObject {
	dp.hdr = objects.NewObjectHeader(objects.ObjectCommit, size)
	commit := dp.objectParser.parseCommit()

	return &PackedObject{
		object: commit,
		bytes:  dp.bytes,
	}
}
示例#4
0
文件: pack.go 项目: jbrukh/ggit
func (dp *packedObjectParser) parseBlob(size int64) *PackedObject {
	data := dp.Bytes()
	oid := dp.objectParser.oid
	hdr := objects.NewObjectHeader(objects.ObjectBlob, size)
	blob := objects.NewBlob(oid, hdr, data)
	return &PackedObject{
		object: blob,
		bytes:  data,
	}
}
示例#5
0
文件: pack.go 项目: jbrukh/ggit
func (dp *packedObjectParser) applyDelta(base *PackedObject, id *objects.ObjectId) (object *PackedObject) {
	p := dp.objectParser

	baseSize := p.parseIntWhileMSB()
	outputSize := p.parseIntWhileMSB()

	src := base.bytes

	if int(baseSize) != len(src) {
		util.PanicErrf("Expected size of base object is %d, but actual size is %d")
	}

	out := make([]byte, outputSize, outputSize)
	var appended int64
	cmd := p.ReadByte()
	for {
		if cmd == 0 {
			util.PanicErrf("Invalid delta! Byte 0 is not a supported delta code.")
		}
		var offset, len int64
		if cmd&0x80 != 0 {
			//copy from base to output
			offset, len = dp.parseCopyCmd(cmd)
			for i := offset; i < offset+len; i++ {
				out[appended+(i-offset)] = src[i]
			}
			if offset+len > baseSize {
				util.PanicErrf("Bad delta - references byte %d of a %d-byte source", offset+len, baseSize)
				break
			}
		} else {
			//copy from delta to output
			offset, len = 0, int64(cmd)
			for i := offset; i < offset+len; i++ {
				out[appended+(i-offset)] = p.ReadByte()
			}
		}
		appended += len
		if appended < outputSize {
			cmd = p.ReadByte()
		} else {
			break
		}
	}
	if appended != outputSize {
		util.PanicErrf("Expected output of size %d, got %d. \n", outputSize, appended)
	}
	if outputSize != int64(len(out)) {
		util.PanicErrf("Expected output of len %d, got %d. \n", outputSize, len(out))
	}
	outputType := base.object.Header().Type()
	outputParser := NewObjectParser(bufio.NewReader(bytes.NewReader(out)), id)
	outputParser.hdr = objects.NewObjectHeader(outputType, outputSize)
	var obj objects.Object
	switch outputType {
	case objects.ObjectBlob:
		obj = outputParser.parseBlob()
	case objects.ObjectTree:
		obj = outputParser.parseTree()
	case objects.ObjectCommit:
		obj = outputParser.parseCommit()
	case objects.ObjectTag:
		obj = outputParser.parseTag()
	}
	return &PackedObject{
		obj,
		out,
		base.object.ObjectId(),
		base.Depth + 1,
	}
}