func Unpack(repo, dir, hash string) error { db, err := libpack.Init(repo, hash) if err != nil { return err } r, w := io.Pipe() var ( inErr error outErr error ) var tasks sync.WaitGroup tasks.Add(2) go func() { inErr = db.GetTar(os.Stdout) w.Close() tasks.Done() }() go func() { outErr = archive.Untar(r, dir, &archive.TarOptions{}) tasks.Done() }() tasks.Wait() if inErr != nil { return fmt.Errorf("git2tar: %v", inErr) } if outErr != nil { return fmt.Errorf("untar: %v", outErr) } return nil }
func Pack(repo, dir, branch string) (hash string, err error) { db, err := libpack.Init(repo, branch) if err != nil { return "", err } a, err := archive.TarWithOptions(dir, &archive.TarOptions{Excludes: []string{".git"}}) if err != nil { return "", err } if err := db.SetTar(a); err != nil { return "", err } if err := db.Commit("imported tar filesystem tree"); err != nil { return "", err } head := db.Head() if head != nil { hash = head.String() } return }