Exemplo n.º 1
0
/*
TODO: remove this method, it is mainly for debugging
*/
func (b *ShowRefBuiltin) Which(p *Params) {
	repo := p.Repo.(*api.DiskRepository)
	fmtr := format.NewFormat(p.Wout)

	fmt.Fprintln(p.Wout, "Loose refs:")
	refs, e := repo.LooseRefs()
	if e != nil {
		fmt.Fprint(p.Werr, e.Error())
		return
	}
	for _, v := range refs {
		fmtr.Ref(v)
		fmtr.Lf()
	}

	fmt.Fprintln(p.Wout, "\nPacked refs:")
	prefs, e := repo.PackedRefs()
	if e != nil {
		fmt.Fprint(p.Werr, e.Error())
		return
	}
	for _, v := range prefs {
		fmtr.Ref(v)
		fmtr.Lf()
	}
}
Exemplo n.º 2
0
func (b *ShowRefBuiltin) filterRefs(p *Params, filters []api.Filter) {
	refs, e := p.Repo.Refs()
	if e != nil {
		fmt.Fprintln(p.Werr, e.Error())
		return
	}
	f := api.FilterAnd(filters...)
	filtered := api.FilterRefs(refs, f)

	if b.flagHead {
		if r, err := api.PeeledRefFromSpec(p.Repo, "HEAD"); err == nil {
			filtered = append([]objects.Ref{r}, filtered...)
		}
	}
	// formatter
	fmtr := format.NewFormat(p.Wout)

	if b.flagQuiet {
		return
	}

	if b.flagDeref {
		for _, r := range filtered {
			fmtr.Ref(r)
			fmtr.Lf()
			if r.Commit() != nil {
				fmtr.Deref(r)
				fmtr.Lf()
			} else {
				_, oid := r.Target() // better not be symbolic
				o, err := p.Repo.ObjectFromOid(oid.(*objects.ObjectId))
				if err == nil {
					if o.Header().Type() == objects.ObjectTag {
						tag := o.(*objects.Tag)
						fmtr.Printf("%s %s^{}\n", tag.Object(), r.Name()) // TODO
					}
				}
			}
		}
	} else { // just do the non-deref case separately, for performance
		for _, r := range filtered {
			fmtr.Ref(r)
			fmtr.Lf()
		}
	}
}
Exemplo n.º 3
0
func (b *CatFileBuiltin) Execute(p *Params, args []string) {
	CatFile.Parse(args)
	args = CatFile.Args()
	expected := 2
	if b.flagPrettyPrint || b.flagShowSize || b.flagShowType {
		expected = 1
	}
	if len(args) != expected {
		b.HelpInfo.WriteUsage(p.Werr)
		return
	}
	id := args[expected-1]
	o, err := api.ObjectFromRevision(p.Repo, id)
	if err != nil {
		fmt.Fprintln(p.Werr, err)
		return
	}

	switch {
	case b.flagPrettyPrint:
		f := format.NewPrettyFormat(p.Wout)
		f.ObjectPretty(o)
	case b.flagShowType:
		fmt.Fprintln(p.Wout, o.Header().Type())
	case b.flagShowSize:
		fmt.Fprintln(p.Wout, o.Header().Size())
	default:
		t := args[0]
		if o.Header().Type().String() != t {
			b.HelpInfo.WriteUsage(p.Werr)
			return
		}
		f := format.NewFormat(p.Wout)
		f.Object(o)
	}
}