Beispiel #1
0
func main() {
	// Set var hgexe to whatever is appropriate for your situation.
	// You can also change it to test with different versions of Mercurial.
	hgexe := "hg"
	repo := "."
	var cfg []string

	hgcl := hg.NewHgClient()
	if err := hgcl.Connect(hgexe, repo, cfg, false); err != nil {
		log.Fatal(err)
	}
	defer hgcl.Disconnect()

	hc := hg.NewLogCmd(nil, nil)
	o := make([]hg.HgOption, 2)
	var lim hg.Limit = 2
	o[0] = lim
	var verb hg.Verbose = true
	o[1] = verb
	hc.SetOptions(o)
	// hc.SetParams([]string{"\"my param\""})
	cl, _ := hc.CmdLine(hgcl)
	fmt.Printf("%s\n", cl)
	res, _ := hc.Exec(hgcl)
	fmt.Printf("result:\n%s", string(res))
}
Beispiel #2
0
func main() {
	var err error
	hc := hg.NewHgClient()
	if err = hc.Connect("", "", nil, false); err != nil {
		log.Fatal(err)
	}
	defer hc.Disconnect()

	var summ []byte
	if summ, err = hc.Summary(nil, nil); err != nil {
		fmt.Println(err)
	}
	fmt.Printf("\"summary\" for repo %s:\n%s\n", hc.RepoRoot(), summ)

	var l []byte
	files := []string{}
	if l, err = hc.Log([]hg.HgOption{hg.Limit(2)}, files); err != nil {
		fmt.Println(err)
	}
	fmt.Printf("\"log -l 2\" for repo %s:\n%s\n", hc.RepoRoot(), l)
}
Beispiel #3
0
func main() {
	// Set var hgexe to whatever is appropriate for your situation.
	// You can also change it to test with different versions of Mercurial.
	hgexe := "hg"
	repo := "."
	var cfg []string

	hgcl := hg.NewHgClient()
	if err := hgcl.Connect(hgexe, repo, cfg, false); err != nil {
		log.Fatal(err)
	}
	defer hgcl.Disconnect()

	cmd := make([]string, 4)
	cmd[0] = "log"
	cmd[1] = "--limit"
	cmd[2] = "2"
	cmd[3] = "-v"
	res, _ := hgcl.ExecCmd(cmd)
	fmt.Printf("%s\n", hgcl.ShowLastCmd())
	fmt.Printf("result:\n%s", string(res))
}
Beispiel #4
0
func main() {
	hc := hg.NewHgClient()
	if err := hc.Connect("", "", nil, false); err != nil {
		log.Fatal(err)
	}
	defer hc.Disconnect()

	t, err := hc.Tip([]hg.HgOption{hg.Template("{rev}")}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	revs, err := strconv.Atoi(string(t))

	m, err := hc.Manifest(nil, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	// don't count empty value after last \n
	files := len(strings.Split(string(m), "\n")) - 1

	h, err := hc.Heads([]hg.HgOption{hg.Template("{rev}\n")}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	// don't count empty value after last \n
	heads := len(strings.Split(string(h), "\n")) - 1

	b, err := hc.Branches([]hg.HgOption{hg.Quiet(true)}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	// don't count empty value after last \n
	branches := len(strings.Split(string(b), "\n")) - 1

	tg, err := hc.Tags([]hg.HgOption{hg.Quiet(true)}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	// don't count empty value after last \n
	// don't count tip
	tags := len(strings.Split(string(tg), "\n")) - 1 - 1

	au, err := hc.Log([]hg.HgOption{hg.Template("{author}\n")}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	var am = make(map[string]bool)
	var sn string
	for _, n := range strings.Split(strings.TrimRight(string(au), "\n"), "\n") {
		sn = string(n)
		_, ok := am[sn]
		if !ok {
			am[sn] = true
		}
	}
	authors := len(am)

	mg, err := hc.Log([]hg.HgOption{hg.Rev("merge()"), hg.Template("{rev}\n")}, nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	// don't count empty value after last \n
	merges := len(strings.Split(string(mg), "\n")) - 1

	fmt.Printf("some stats for repo %s:\n"+
		"%8d revisions\n"+
		"%8d merges\n"+
		"%8d files\n"+
		"%8d heads\n"+
		"%8d branches\n"+
		"%8d tags\n"+
		"%8d authors\n",
		hc.RepoRoot(), revs, merges, files, heads, branches, tags, authors)
}
Beispiel #5
0
func main() {
	// Set var hgexe to whatever is appropriate for your situation.
	// You can also change it to test with different versions of Mercurial.
	hgexe := "hg"
	repo := "."

	fmt.Println("========== Begin of example1 ==========")

	var err error
	fmt.Printf("Using Mercurial repo at: %s\n", repo)
	fmt.Println("--------------------")

	hc := hg.NewHgClient()
	var cfg []string
	if err = hc.Connect(hgexe, repo, cfg, false); err != nil {
		log.Fatal(err)
	}
	defer hc.Disconnect()
	defer func() { fmt.Println("========== End of example1 ==========") }()

	var v string
	if v, err = hc.Version(); err != nil {
		log.Println(err)
	}
	fmt.Printf("[[version]]: %s\n", v)

	fmt.Println("--------------------")

	var i []byte
	if i, err = hc.Identify(nil /*[]hg.HgOption{hg.Verbose(true)}*/, []string{""}); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("[[identify]]:\n%s", i)

	// fmt.Printf("%s", hg.SprintfOpts(*(new(hg.IdentifyOpts))))

	fmt.Println("--------------------")

	var s []byte
	if s, err = hc.Summary(nil, nil); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("[[summary]]:\n%s", s)

	// fmt.Printf("%s", SprintfOpts(*(new(SummaryOpts))))

	fmt.Println("--------------------")

	var limit hg.Limit = 2
	var verbose hg.Verbose = true
	opts := []hg.HgOption{limit, verbose}
	params := []string{}
	var l []byte
	// if l, err = hc.Log2([]hg.HgOption{hg.Limit(2), hg.Verbose(true)}, []hg.Param{}); err != nil {
	if l, err = hc.Log(opts, params); err != nil {
		fmt.Println(err)
		return
	}
	// use 'go run example1.go | less' (or more) to view big results (such as a full log)
	fmt.Printf("[[log -v -l 2 branches_test.go]]:\n%s", l)

	// give time to see the Hg CS session live and die from Process Explorer
	// fmt.Print("waiting...")
	// time.Sleep(3 * time.Second)
}