@@ -41,20 +41,40 @@ const (
41
41
var repoWorkingPool = sync .NewExclusivePool ()
42
42
43
43
var (
44
- ErrRepoFileNotExist = errors .New ("Repository file does not exist" )
44
+ // ErrRepoFileNotExist repository file does not exist error
45
+ ErrRepoFileNotExist = errors .New ("Repository file does not exist" )
46
+
47
+ // ErrRepoFileNotLoaded repository file not loaded error
45
48
ErrRepoFileNotLoaded = errors .New ("Repository file not loaded" )
46
- ErrMirrorNotExist = errors .New ("Mirror does not exist" )
47
- ErrInvalidReference = errors .New ("Invalid reference specified" )
48
- ErrNameEmpty = errors .New ("Name is empty" )
49
+
50
+ // ErrMirrorNotExist mirror does not exist error
51
+ ErrMirrorNotExist = errors .New ("Mirror does not exist" )
52
+
53
+ // ErrInvalidReference invalid reference specified error
54
+ ErrInvalidReference = errors .New ("Invalid reference specified" )
55
+
56
+ // ErrNameEmpty name is empty error
57
+ ErrNameEmpty = errors .New ("Name is empty" )
49
58
)
50
59
51
60
var (
52
- Gitignores , Licenses , Readmes , LabelTemplates []string
61
+ // Gitignores contains the gitiginore files
62
+ Gitignores []string
63
+
64
+ // Licenses contains the license files
65
+ Licenses []string
66
+
67
+ // Readmes contains the readme files
68
+ Readmes []string
69
+
70
+ // LabelTemplates contains the label template files
71
+ LabelTemplates []string
53
72
54
- // Maximum items per page in forks, watchers and stars of a repo
73
+ // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
55
74
ItemsPerPage = 40
56
75
)
57
76
77
+ // LoadRepoConfig loads the repository config
58
78
func LoadRepoConfig () {
59
79
// Load .gitignore and license files and readme templates.
60
80
types := []string {"gitignore" , "license" , "readme" , "label" }
@@ -104,6 +124,7 @@ func LoadRepoConfig() {
104
124
Licenses = sortedLicenses
105
125
}
106
126
127
+ // NewRepoContext creates a new repository context
107
128
func NewRepoContext () {
108
129
zip .Verbose = false
109
130
@@ -200,15 +221,18 @@ type Repository struct {
200
221
UpdatedUnix int64
201
222
}
202
223
224
+ // BeforeInsert is invoked from XORM before inserting an object of this type.
203
225
func (repo * Repository ) BeforeInsert () {
204
226
repo .CreatedUnix = time .Now ().Unix ()
205
227
repo .UpdatedUnix = repo .CreatedUnix
206
228
}
207
229
230
+ // BeforeUpdate is invoked from XORM before updating this object.
208
231
func (repo * Repository ) BeforeUpdate () {
209
232
repo .UpdatedUnix = time .Now ().Unix ()
210
233
}
211
234
235
+ // AfterSet is invoked from XORM after setting the value of a field of this object.
212
236
func (repo * Repository ) AfterSet (colName string , _ xorm.Cell ) {
213
237
switch colName {
214
238
case "default_branch" :
@@ -241,14 +265,17 @@ func (repo *Repository) MustOwner() *User {
241
265
return repo .mustOwner (x )
242
266
}
243
267
268
+ // FullName returns the repository full name
244
269
func (repo * Repository ) FullName () string {
245
270
return repo .MustOwner ().Name + "/" + repo .Name
246
271
}
247
272
273
+ // HTMLURL returns the repository HTML URL
248
274
func (repo * Repository ) HTMLURL () string {
249
275
return setting .AppURL + repo .FullName ()
250
276
}
251
277
278
+ // APIFormat converts a Repository to api.Repository
252
279
// Arguments that are allowed to be nil: permission
253
280
func (repo * Repository ) APIFormat (permission * api.Permission ) * api.Repository {
254
281
cloneLink := repo .CloneLink ()
@@ -284,6 +311,7 @@ func (repo *Repository) getOwner(e Engine) (err error) {
284
311
return err
285
312
}
286
313
314
+ // GetOwner returns the repository owner
287
315
func (repo * Repository ) GetOwner () error {
288
316
return repo .getOwner (x )
289
317
}
@@ -381,11 +409,13 @@ func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int6
381
409
return GetRepoIssueStats (repo .ID , uid , filterMode , isPull )
382
410
}
383
411
412
+ // GetMirror sets the repository mirror, returns an error upon failure
384
413
func (repo * Repository ) GetMirror () (err error ) {
385
414
repo .Mirror , err = GetMirrorByRepoID (repo .ID )
386
415
return err
387
416
}
388
417
418
+ // GetBaseRepo returns the base repository
389
419
func (repo * Repository ) GetBaseRepo () (err error ) {
390
420
if ! repo .IsFork {
391
421
return nil
@@ -399,31 +429,38 @@ func (repo *Repository) repoPath(e Engine) string {
399
429
return RepoPath (repo .mustOwner (e ).Name , repo .Name )
400
430
}
401
431
432
+ // RepoPath returns the repository path
402
433
func (repo * Repository ) RepoPath () string {
403
434
return repo .repoPath (x )
404
435
}
405
436
437
+ // GitConfigPath returns the repository git config path
406
438
func (repo * Repository ) GitConfigPath () string {
407
439
return filepath .Join (repo .RepoPath (), "config" )
408
440
}
409
441
442
+ // RelLink returns the repository relative link
410
443
func (repo * Repository ) RelLink () string {
411
444
return "/" + repo .FullName ()
412
445
}
413
446
447
+ // Link returns the repository link
414
448
func (repo * Repository ) Link () string {
415
449
return setting .AppSubURL + "/" + repo .FullName ()
416
450
}
417
451
452
+ // ComposeCompareURL returns the repository comparison URL
418
453
func (repo * Repository ) ComposeCompareURL (oldCommitID , newCommitID string ) string {
419
454
return fmt .Sprintf ("%s/%s/compare/%s...%s" , repo .MustOwner ().Name , repo .Name , oldCommitID , newCommitID )
420
455
}
421
456
457
+ // HasAccess returns true when user has access to this repository
422
458
func (repo * Repository ) HasAccess (u * User ) bool {
423
459
has , _ := HasAccess (u , repo , AccessModeRead )
424
460
return has
425
461
}
426
462
463
+ // IsOwnedBy returns true when user owns this repository
427
464
func (repo * Repository ) IsOwnedBy (userID int64 ) bool {
428
465
return repo .OwnerID == userID
429
466
}
@@ -438,7 +475,7 @@ func (repo *Repository) CanEnablePulls() bool {
438
475
return ! repo .IsMirror
439
476
}
440
477
441
- // AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
478
+ // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
442
479
func (repo * Repository ) AllowsPulls () bool {
443
480
return repo .CanEnablePulls () && repo .EnablePulls
444
481
}
@@ -448,29 +485,31 @@ func (repo *Repository) CanEnableEditor() bool {
448
485
return ! repo .IsMirror
449
486
}
450
487
488
+ // NextIssueIndex returns the next issue index
451
489
// FIXME: should have a mutex to prevent producing same index for two issues that are created
452
490
// closely enough.
453
491
func (repo * Repository ) NextIssueIndex () int64 {
454
492
return int64 (repo .NumIssues + repo .NumPulls ) + 1
455
493
}
456
494
457
495
var (
458
- DescPattern = regexp .MustCompile (`https?://\S+` )
496
+ descPattern = regexp .MustCompile (`https?://\S+` )
459
497
)
460
498
461
- // DescriptionHtml does special handles to description and return HTML string.
462
- func (repo * Repository ) DescriptionHtml () template.HTML {
499
+ // DescriptionHTML does special handles to description and return HTML string.
500
+ func (repo * Repository ) DescriptionHTML () template.HTML {
463
501
sanitize := func (s string ) string {
464
502
return fmt .Sprintf (`<a href="%[1]s" target="_blank">%[1]s</a>` , s )
465
503
}
466
- return template .HTML (DescPattern .ReplaceAllStringFunc (markdown .Sanitizer .Sanitize (repo .Description ), sanitize ))
504
+ return template .HTML (descPattern .ReplaceAllStringFunc (markdown .Sanitizer .Sanitize (repo .Description ), sanitize ))
467
505
}
468
506
507
+ // LocalCopyPath returns the local repository copy path
469
508
func (repo * Repository ) LocalCopyPath () string {
470
509
return path .Join (setting .AppDataPath , "tmp/local-rpeo" , com .ToStr (repo .ID ))
471
510
}
472
511
473
- // UpdateLocalCopy pulls latest changes of given branch from repoPath to localPath.
512
+ // UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
474
513
// It creates a new clone if local copy does not exist.
475
514
// This function checks out target branch by default, it is safe to assume subsequent
476
515
// operations are operating against target branch when caller has confidence for no race condition.
@@ -575,6 +614,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
575
614
return repo .cloneLink (false )
576
615
}
577
616
617
+ // MigrateRepoOptions contains the repository migrate options
578
618
type MigrateRepoOptions struct {
579
619
Name string
580
620
Description string
@@ -711,7 +751,7 @@ func createUpdateHook(repoPath string) error {
711
751
fmt .Sprintf (tplUpdateHook , setting .ScriptType , "\" " + setting .AppPath + "\" " , setting .CustomConf ))
712
752
}
713
753
714
- // Finish migrating repository and/or wiki with things that don't need to be done for mirrors.
754
+ // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
715
755
func CleanUpMigrateInfo (repo * Repository ) (* Repository , error ) {
716
756
repoPath := repo .RepoPath ()
717
757
if err := createUpdateHook (repoPath ); err != nil {
@@ -759,6 +799,7 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
759
799
return nil
760
800
}
761
801
802
+ // CreateRepoOptions contains the create repository options
762
803
type CreateRepoOptions struct {
763
804
Name string
764
805
Description string
@@ -897,6 +938,7 @@ var (
897
938
reservedRepoPatterns = []string {"*.git" , "*.wiki" }
898
939
)
899
940
941
+ // IsUsableRepoName returns true when repository is usable
900
942
func IsUsableRepoName (name string ) error {
901
943
return isUsableName (reservedRepoNames , reservedRepoPatterns , name )
902
944
}
@@ -1030,6 +1072,7 @@ func CountUserRepositories(userID int64, private bool) int64 {
1030
1072
return countRepositories (userID , private )
1031
1073
}
1032
1074
1075
+ // Repositories returns all repositories
1033
1076
func Repositories (page , pageSize int ) (_ []* Repository , err error ) {
1034
1077
repos := make ([]* Repository , 0 , pageSize )
1035
1078
return repos , x .Limit (pageSize , (page - 1 )* pageSize ).Asc ("id" ).Find (& repos )
@@ -1275,6 +1318,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
1275
1318
return nil
1276
1319
}
1277
1320
1321
+ // UpdateRepository updates a repository
1278
1322
func UpdateRepository (repo * Repository , visibilityChanged bool ) (err error ) {
1279
1323
sess := x .NewSession ()
1280
1324
defer sessionRelease (sess )
@@ -1474,7 +1518,7 @@ func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Rep
1474
1518
return repos , sess .Find (& repos )
1475
1519
}
1476
1520
1477
- // GetUserRepositories returns a list of mirror repositories of given user.
1521
+ // GetUserMirrorRepositories returns a list of mirror repositories of given user.
1478
1522
func GetUserMirrorRepositories (userID int64 ) ([]* Repository , error ) {
1479
1523
repos := make ([]* Repository , 0 , 10 )
1480
1524
return repos , x .
@@ -1502,6 +1546,7 @@ func GetRepositoryCount(u *User) (int64, error) {
1502
1546
return getRepositoryCount (x , u )
1503
1547
}
1504
1548
1549
+ // SearchRepoOptions holds the search options
1505
1550
type SearchRepoOptions struct {
1506
1551
Keyword string
1507
1552
OwnerID int64
@@ -1670,6 +1715,7 @@ func GitFsck() {
1670
1715
}
1671
1716
}
1672
1717
1718
+ // GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
1673
1719
func GitGcRepos () error {
1674
1720
args := append ([]string {"gc" }, setting .Git .GCArgs ... )
1675
1721
return x .
@@ -1712,6 +1758,7 @@ func repoStatsCheck(checker *repoChecker) {
1712
1758
}
1713
1759
}
1714
1760
1761
+ // CheckRepoStats checks the repository stats
1715
1762
func CheckRepoStats () {
1716
1763
if taskStatusTable .IsRunning (checkRepos ) {
1717
1764
return
@@ -1806,6 +1853,7 @@ func CheckRepoStats() {
1806
1853
// ***** END: Repository.NumForks *****
1807
1854
}
1808
1855
1856
+ // RepositoryList contains a list of repositories
1809
1857
type RepositoryList []* Repository
1810
1858
1811
1859
func (repos RepositoryList ) loadAttributes (e Engine ) error {
@@ -1838,10 +1886,12 @@ func (repos RepositoryList) loadAttributes(e Engine) error {
1838
1886
return nil
1839
1887
}
1840
1888
1889
+ // LoadAttributes loads the attributes for the given RepositoryList
1841
1890
func (repos RepositoryList ) LoadAttributes () error {
1842
1891
return repos .loadAttributes (x )
1843
1892
}
1844
1893
1894
+ // MirrorRepositoryList contains the mirror repositories
1845
1895
type MirrorRepositoryList []* Repository
1846
1896
1847
1897
func (repos MirrorRepositoryList ) loadAttributes (e Engine ) error {
@@ -1876,6 +1926,7 @@ func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
1876
1926
return nil
1877
1927
}
1878
1928
1929
+ // LoadAttributes loads the attributes for the given MirrorRepositoryList
1879
1930
func (repos MirrorRepositoryList ) LoadAttributes () error {
1880
1931
return repos .loadAttributes (x )
1881
1932
}
@@ -1925,7 +1976,7 @@ func watchRepo(e Engine, userID, repoID int64, watch bool) (err error) {
1925
1976
return err
1926
1977
}
1927
1978
1928
- // Watch or unwatch repository.
1979
+ // WatchRepo watch or unwatch repository.
1929
1980
func WatchRepo (userID , repoID int64 , watch bool ) (err error ) {
1930
1981
return watchRepo (x , userID , repoID , watch )
1931
1982
}
@@ -1940,7 +1991,7 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
1940
1991
return getWatchers (x , repoID )
1941
1992
}
1942
1993
1943
- // Repository. GetWatchers returns range of users watching given repository.
1994
+ // GetWatchers returns range of users watching given repository.
1944
1995
func (repo * Repository ) GetWatchers (page int ) ([]* User , error ) {
1945
1996
users := make ([]* User , 0 , ItemsPerPage )
1946
1997
sess := x .
@@ -1993,13 +2044,14 @@ func NotifyWatchers(act *Action) error {
1993
2044
// /_______ /|__| (____ /__|
1994
2045
// \/ \/
1995
2046
2047
+ // Star contains the star information
1996
2048
type Star struct {
1997
2049
ID int64 `xorm:"pk autoincr"`
1998
2050
UID int64 `xorm:"UNIQUE(s)"`
1999
2051
RepoID int64 `xorm:"UNIQUE(s)"`
2000
2052
}
2001
2053
2002
- // Star or unstar repository.
2054
+ // StarRepo star or unstar repository.
2003
2055
func StarRepo (userID , repoID int64 , star bool ) (err error ) {
2004
2056
if star {
2005
2057
if IsStaring (userID , repoID ) {
@@ -2031,6 +2083,7 @@ func IsStaring(userID, repoID int64) bool {
2031
2083
return has
2032
2084
}
2033
2085
2086
+ // GetStargazers returns the users who gave stars to this repository
2034
2087
func (repo * Repository ) GetStargazers (page int ) ([]* User , error ) {
2035
2088
users := make ([]* User , 0 , ItemsPerPage )
2036
2089
sess := x .
@@ -2060,6 +2113,7 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
2060
2113
return repo , has
2061
2114
}
2062
2115
2116
+ // ForkRepository forks a repository
2063
2117
func ForkRepository (u * User , oldRepo * Repository , name , desc string ) (_ * Repository , err error ) {
2064
2118
repo := & Repository {
2065
2119
OwnerID : u .ID ,
@@ -2109,6 +2163,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
2109
2163
return repo , sess .Commit ()
2110
2164
}
2111
2165
2166
+ // GetForks returns all the forks of the repository
2112
2167
func (repo * Repository ) GetForks () ([]* Repository , error ) {
2113
2168
forks := make ([]* Repository , 0 , repo .NumForks )
2114
2169
return forks , x .Find (& forks , & Repository {ForkID : repo .ID })
@@ -2122,6 +2177,7 @@ func (repo *Repository) GetForks() ([]*Repository, error) {
2122
2177
// \/ \/ \/ \/ \/
2123
2178
//
2124
2179
2180
+ // CreateNewBranch creates a new repository branch
2125
2181
func (repo * Repository ) CreateNewBranch (doer * User , oldBranchName , branchName string ) (err error ) {
2126
2182
repoWorkingPool .CheckIn (com .ToStr (repo .ID ))
2127
2183
defer repoWorkingPool .CheckOut (com .ToStr (repo .ID ))
0 commit comments