|
|
|
@@ -207,6 +207,7 @@ type Repository struct { |
|
|
|
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` |
|
|
|
ForkID int64 `xorm:"INDEX"` |
|
|
|
BaseRepo *Repository `xorm:"-"` |
|
|
|
Size int64 `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
Created time.Time `xorm:"-"` |
|
|
|
CreatedUnix int64 `xorm:"INDEX"` |
|
|
|
@@ -546,6 +547,18 @@ func (repo *Repository) IsOwnedBy(userID int64) bool { |
|
|
|
return repo.OwnerID == userID |
|
|
|
} |
|
|
|
|
|
|
|
// UpdateSize updates the repository size, calculating it using git.GetRepoSize |
|
|
|
func (repo *Repository) UpdateSize() error { |
|
|
|
repoInfoSize, err := git.GetRepoSize(repo.RepoPath()) |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("UpdateSize: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
repo.Size = repoInfoSize.Size + repoInfoSize.SizePack |
|
|
|
_, err = x.ID(repo.ID).Cols("size").Update(repo) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// CanBeForked returns true if repository meets the requirements of being forked. |
|
|
|
func (repo *Repository) CanBeForked() bool { |
|
|
|
return !repo.IsBare |
|
|
|
@@ -810,6 +823,10 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err = repo.UpdateSize(); err != nil { |
|
|
|
log.Error(4, "Failed to update size for repository: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.IsMirror { |
|
|
|
if _, err = x.InsertOne(&Mirror{ |
|
|
|
RepoID: repo.ID, |
|
|
|
@@ -1464,6 +1481,10 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e |
|
|
|
return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err = repo.UpdateSize(); err != nil { |
|
|
|
log.Error(4, "Failed to update size for repository: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
@@ -2171,6 +2192,10 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
if err = repo.UpdateSize(); err != nil { |
|
|
|
log.Error(4, "Failed to update size for repository: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
// Copy LFS meta objects in new session |
|
|
|
sess2 := x.NewSession() |
|
|
|
defer sessionRelease(sess2) |
|
|
|
|