Ejemplo n.º 1
0
func main() {
	listenAddr, baseDir, rawPatch := processArgs()

	nav, err := navpatch.NewNavigator(baseDir, rawPatch)
	if err != nil {
		internal.ErrorExit(err)
	}

	listener, err := net.Listen("tcp", listenAddr)
	if err != nil {
		internal.ErrorExit("starting server:", err)
	}

	fmt.Println("Serving at " + listener.Addr().String())
	log.Fatal(http.Serve(listener, nav))
}
Ejemplo n.º 2
0
func (gc gitCommandUnix) patchNavigator(repoURL, oldCommit, newCommit string, feedback func(string)) (*navpatch.Navigator, func(), error) {
	repoPath, err := gc.copyRepo(repoURL, feedback)
	if err != nil {
		return nil, nil, err
	}

	cleanupNav := func() {
		os.RemoveAll(repoPath)
	}

	cmd := exec.Command("git", "diff", "--no-color", oldCommit, newCommit)
	cmd.Dir = repoPath
	rawPatch, err := cmd.CombinedOutput()
	if err != nil {
		cleanupNav()
		return nil, nil, fmt.Errorf("diffing: %v; git output: %v", err, string(rawPatch))
	}

	feedback("Checking out base commit...")
	cmd = exec.Command("git", "stash")
	cmd.Dir = repoPath
	cmd.Run()

	cmd = exec.Command("git", "checkout", oldCommit)
	cmd.Dir = repoPath
	out, err := cmd.CombinedOutput()
	if err != nil {
		cleanupNav()
		return nil, nil, fmt.Errorf("checking out %s: %v; git output: %v", oldCommit, err, string(out))
	}

	cmd = exec.Command("git", "stash", "pop")
	cmd.Dir = repoPath
	cmd.Run()

	feedback("Generating patch visualization...")
	nav, err := navpatch.NewNavigator(repoPath, rawPatch)
	if err != nil {
		cleanupNav()
		return nil, nil, err
	}

	return nav, cleanupNav, nil
}