summaryrefslogtreecommitdiff
path: root/repo.new.go
diff options
context:
space:
mode:
Diffstat (limited to 'repo.new.go')
-rw-r--r--repo.new.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/repo.new.go b/repo.new.go
index 64cf897..5e3f8b4 100644
--- a/repo.new.go
+++ b/repo.new.go
@@ -68,3 +68,30 @@ func (all *Repos) AppendByGoPath(newr *Repo) bool {
all.Append(newr)
return true
}
+
+func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) {
+ if r := all.FindByFullPath(fullpath); r != nil {
+ log.Info("gitpb.NewRepo() might already have namespace", r.GetNamespace())
+ log.Info("gitpb.NewRepo() already has FullPath", r.FullPath)
+ // already had this gopath
+ return r, errors.New("gitpb.NewRepo() duplicate path " + fullpath)
+ }
+
+ // add a new one here
+ newr := Repo{
+ FullPath: fullpath,
+ Namespace: namespace,
+ }
+ newr.Times = new(GitTimes)
+
+ // everything happens in here
+ newr.Reload()
+
+ if all.AppendByFullPath(&newr) {
+ // worked
+ return &newr, nil
+ }
+
+ // todo: use Repos.Lock()
+ return nil, errors.New("gitpb.NewRepo() append failed " + fullpath)
+}