예제 #1
0
파일: refs.go 프로젝트: jbrukh/ggit
func (p *refParser) ParsePackedRefs() ([]objects.Ref, error) {
	r := make([]objects.Ref, 0)
	err := util.SafeParse(func() {
		for !p.EOF() {
			c := p.PeekByte()
			switch c {
			case '#':
				// if this is the first line, then it should be a comment
				// that says '# pack-refs with: <extention>' and <extention>
				// is exactly one of the items in this set: { 'peeled' }.
				// currently, we are just ignoring all comments.
				p.ReadString(token.LF)
			case '^':
				// this means the previous line is an annotated tag and the the current
				// line contains the commit that tag points to
				p.ConsumeByte('^')
				commit := p.ParseOid()
				p.ConsumeByte(token.LF)

				if l := len(r); l > 0 {
					_, oid := r[l-1].Target()
					//TODO: inefficient (copying):
					r[l-1] = objects.NewRef(r[l-1].Name(), "", oid.(*objects.ObjectId), commit)
				}
			default:
				oid := p.ParseOid()
				p.ConsumeByte(token.SP)
				name := p.ReadString(token.LF)

				r = append(r, objects.NewRef(name, "", oid, nil))
			}
		}
	})
	return r, err
}
예제 #2
0
파일: rev_parser.go 프로젝트: jbrukh/ggit
func (p *revParser) Parse() error {
	e := util.SafeParse(func() {
		if p.rev == "" {
			util.PanicErr("revision spec is empty")
		}

		if p.PeekByte() == ':' {
			util.PanicErr(": syntaxes not supported") // TODO
		}

		start := p.Count()
		// read until modifier or end
		for !p.EOF() {
			if !isModifier(p.PeekByte()) {
				p.ReadByte()
			} else {
				break
			}
		}
		end := p.Count()

		rev := p.rev[start:end]
		if rev == "" {
			util.PanicErr("revision is empty")
		}

		err := p.findObject(rev)
		if err != nil {
			util.PanicErr(err.Error())
		}

		for !p.EOF() {
			var err error
			b := p.ReadByte()
			if b == '^' {
				if !p.EOF() && p.PeekByte() == '{' {
					p.ConsumeByte('{')
					otype := objects.ObjectType(p.ConsumeStrings(token.ObjectTypes))
					err = applyDereference(p, otype)
					if err != nil {

					}
					p.ConsumeByte('}')
				} else {
					err = applyParentFunc(p, CommitNthParent)
				}
			} else if b == '~' {
				err = applyParentFunc(p, CommitNthAncestor)
			} else {
				util.PanicErrf("unexpected modifier: '%s'", string(b))
			}

			if err != nil {
				util.PanicErr(err.Error())
			}
		}
	})
	return e
}
예제 #3
0
파일: refs.go 프로젝트: jbrukh/ggit
func (p *refParser) ParseRef() (r objects.Ref, err error) {
	err = util.SafeParse(func() {
		// is it a symbolic ref?
		if p.PeekString(len(markerRef)) == markerRef {
			p.ConsumeString(markerRef)
			p.ConsumeByte(token.SP)
			spec := p.ReadString(token.LF)
			r = objects.NewRef(p.name, spec, nil, nil)
		} else {
			oid := p.ParseOid()
			p.ConsumeByte(token.LF)
			r = objects.NewRef(p.name, "", oid, nil)
		}
	})
	return r, err
}