diff --git a/models/repo_language_stats.go b/models/repo_language_stats.go index bf8f5f59d0..fd5bcbb8ec 100644 --- a/models/repo_language_stats.go +++ b/models/repo_language_stats.go @@ -144,3 +144,32 @@ func (repo *Repository) UpdateLanguageStats(commitID string, stats map[string]fl return sess.Commit() } + +// CopyLanguageStat Copy originalRepo language stat information to destRepo (use for forked repo) +func CopyLanguageStat(originalRepo, destRepo *Repository) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + RepoLang := make(LanguageStatList, 0, 6) + if err := sess.Where("`repo_id` = ?", originalRepo.ID).Desc("`percentage`").Find(&RepoLang); err != nil { + return err + } + if len(RepoLang) > 0 { + for i := range RepoLang { + RepoLang[i].ID = 0 + RepoLang[i].RepoID = destRepo.ID + RepoLang[i].CreatedUnix = timeutil.TimeStampNow() + } + //update destRepo's indexer status + tmpCommitID := RepoLang[0].CommitID + if err := destRepo.updateIndexerStatus(sess, RepoIndexerTypeStats, tmpCommitID); err != nil { + return err + } + if _, err := sess.Insert(&RepoLang); err != nil { + return err + } + } + return sess.Commit() +} diff --git a/modules/repository/fork.go b/modules/repository/fork.go index 638d3588ec..2ed2a0eb78 100644 --- a/modules/repository/fork.go +++ b/modules/repository/fork.go @@ -82,6 +82,8 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name, if err = repo.UpdateSize(ctx); err != nil { log.Error("Failed to update size for repository: %v", err) } - + if err := models.CopyLanguageStat(oldRepo, repo); err != nil { + log.Error("Copy language stat from oldRepo failed") + } return repo, models.CopyLFS(ctx, repo, oldRepo) } diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index f4edc74396..4daaa201d0 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -17,7 +17,7 @@ {{else if .IsMirror}} {{svg "octicon-repo-clone" 32}} {{else if .IsFork}} - {{svg "octicon-repo-fork" 32}} + {{svg "octicon-repo-forked" 32}} {{else}} {{svg "octicon-repo" 32}} {{end}} @@ -38,7 +38,7 @@ {{else if .IsMirror}} {{svg "octicon-repo-clone" 32}} {{else if .IsFork}} - {{svg "octicon-repo-fork" 32}} + {{svg "octicon-repo-forked" 32}} {{else}} {{svg "octicon-repo" 32}} {{end}} @@ -76,7 +76,7 @@ {{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}