Exemple #1
0
func mainDiff(args []string) int {
	f := flag.NewFlagSet("status", flag.ExitOnError)
	opt_from := f.String("from", "", "Specify the source directory")
	opt_to := f.String("to", "", "Specify the destination directory")
	f.Usage = func() {
		fmt.Print(usageMissing)
		f.PrintDefaults()
	}
	f.Parse(args)
	src, dst := findSourceDest(*opt_from, *opt_to, f.Args())

	srcfiles, err := commit.ReadCommit(src)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %s", src, err.Error())
	}

	dstfiles, err := commit.ReadCommit(dst)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %s", dst, err.Error())
	}

	var filelist []string
	for file := range srcfiles.ByPath {
		filelist = append(filelist, file)
	}
	for file := range dstfiles.ByPath {
		if _, ok := srcfiles.ByPath[file]; !ok {
			filelist = append(filelist, file)
		}
	}
	sort.Strings(filelist)

	for _, file := range filelist {
		var s, d commit.Entry
		sid, hassrc := srcfiles.ByPath[file]
		did, hasdst := dstfiles.ByPath[file]
		if hassrc {
			s = srcfiles.Entries[sid]
		}
		if hasdst {
			d = dstfiles.Entries[did]
		}
		if hassrc && !hasdst {
			fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(file))
		} else if !hassrc && hasdst {
			fmt.Printf("+ %s\t%s\n", d.HashText(), commit.EncodePath(file))
		} else if !bytes.Equal(s.Hash, d.Hash) {
			fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(file))
			fmt.Printf("+ %s\t%s\n", d.HashText(), commit.EncodePath(file))
		}
	}

	return 0
}
Exemple #2
0
func mainAttr(args []string) int {
	f := flag.NewFlagSet("status", flag.ExitOnError)
	f.Usage = func() {
		fmt.Print(usageAttr)
		f.PrintDefaults()
	}
	f.Parse(args)
	dir := f.Arg(0)
	if dir == "" {
		dir = "."
	}

	attrname := f.Arg(1)

	if attrname != "" {

		c, err := commit.ReadCommit(filepath.Dir(dir))
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			return 1
		}

		fmt.Println(c.GetAttr(filepath.Base(dir), attrname))

	} else {

		c, err := commit.ReadCommit(dir)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			return 1
		}

		for f, a := range c.Attrs {
			path := filepath.Join(dir, f)
			if strings.HasSuffix(f, "/") {
				path = path + "/"
			}
			if path == "./" {
				path = ""
			}
			if !strings.HasPrefix(path, "/") {
				path = "/" + path
			}
			fmt.Printf("%s\n", path)
			for k, v := range a {
				fmt.Printf(" %s=%s\n", k, v)
			}
		}

	}

	return 0
}
Exemple #3
0
func Copy(srcdir, dstdir string, p Progress, rename bool) (error, []error) {
	if p != nil {
		p.SetProgress(0, 4, "Read commit "+srcdir)
	}

	src, err := commit.ReadCommit(srcdir)
	if err != nil {
		return err, nil
	}

	if p != nil {
		p.SetProgress(1, 4, "Read commit "+dstdir)
	}

	os.MkdirAll(dstdir, 0777)

	dst, err := commit.ReadCommit(dstdir)
	if err != nil {
		return err, nil
	}

	if p != nil {
		p.SetProgress(2, 4, "Prepare copy")
	}

	successes, err, errs := copyTree(srcdir, dstdir, src, dst, p)
	if err != nil {
		return err, errs
	}

	if p != nil {
		p.SetProgress(len(successes)+3, len(successes)+4, fmt.Sprintf("Commit %d new files to %#v", len(successes), dstdir))
	}

	err = commit.WriteDirAppend(dstdir, successes)

	if p != nil && err == nil {
		p.SetProgress(len(successes)+4, len(successes)+4,
			fmt.Sprintf("%d files copied with %d errors", len(successes), len(errs)))
	}
	return err, errs
}
Exemple #4
0
func mainMissing(args []string) int {
	f := flag.NewFlagSet("status", flag.ExitOnError)
	opt_from := f.String("from", "", "Specify the source directory")
	opt_to := f.String("to", "", "Specify the destination directory")
	f.Usage = func() {
		fmt.Print(usageMissing)
		f.PrintDefaults()
	}
	f.Parse(args)
	src, dst := findSourceDest(*opt_from, *opt_to, f.Args())

	srcfiles, err := commit.ReadCommit(src)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %s", src, err.Error())
	}

	dstfiles, err := commit.ReadCommit(dst)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %s", dst, err.Error())
	}

	for _, s := range srcfiles.Entries {
		did, hasd := dstfiles.ByPath[s.Path]
		if !hasd {
			fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(s.Path))
		} else {
			d := dstfiles.Entries[did]
			if !bytes.Equal(s.Hash, d.Hash) {
				fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(s.Path))
				fmt.Printf("+ %s\t%s\n", d.HashText(), commit.EncodePath(d.Path))
			}
		}
	}

	return 0
}