Browse Source

WIP: create PR - choose branch

Unknwon 4 years ago
parent
commit
dea3a8c6a4

+ 3 - 3
cmd/serve.go

@@ -146,12 +146,12 @@ func runServ(c *cli.Context) {
146 146
 				fail("Key permission denied", "Cannot push with deployment key: %d", key.ID)
147 147
 			}
148 148
 			// Check if this deploy key belongs to current repository.
149
-			if !models.HasDeployKey(key.ID, repo.Id) {
150
-				fail("Key access denied", "Key access denied: %d-%d", key.ID, repo.Id)
149
+			if !models.HasDeployKey(key.ID, repo.ID) {
150
+				fail("Key access denied", "Key access denied: %d-%d", key.ID, repo.ID)
151 151
 			}
152 152
 
153 153
 			// Update deploy key activity.
154
-			deployKey, err := models.GetDeployKeyByRepo(key.ID, repo.Id)
154
+			deployKey, err := models.GetDeployKeyByRepo(key.ID, repo.ID)
155 155
 			if err != nil {
156 156
 				fail("Internal error", "GetDeployKey: %v", err)
157 157
 			}

+ 3 - 1
cmd/web.go

@@ -449,6 +449,8 @@ func runWeb(ctx *cli.Context) {
449 449
 			m.Get("/edit/:tagname", repo.EditRelease)
450 450
 			m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
451 451
 		}, reqRepoAdmin, middleware.RepoRef())
452
+
453
+		m.Combo("/compare/*").Get(repo.CompareAndPullRequest)
452 454
 	}, reqSignIn, middleware.RepoAssignment(true))
453 455
 
454 456
 	m.Group("/:username/:reponame", func() {
@@ -469,7 +471,7 @@ func runWeb(ctx *cli.Context) {
469 471
 			m.Get("/commit/*", repo.Diff)
470 472
 		}, middleware.RepoRef())
471 473
 
472
-		m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff)
474
+		m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", repo.CompareDiff)
473 475
 	}, ignSignIn, middleware.RepoAssignment(true))
474 476
 
475 477
 	m.Group("/:username", func() {

+ 3 - 0
conf/locale/locale_en-US.ini

@@ -395,6 +395,9 @@ issues.label_deletion = Label Deletion
395 395
 issues.label_deletion_desc = Delete this label will remove its information in all related issues. Do you want to continue?
396 396
 issues.label_deletion_success = Label has been deleted successfully!
397 397
 
398
+pulls.compare_changes = Compare Changes
399
+pulls.compare_changes_desc = Compare two branches and make a pull request for changes.
400
+
398 401
 milestones.new = New Milestone
399 402
 milestones.open_tab = %d Open
400 403
 milestones.close_tab = %d Closed

+ 7 - 7
models/access.go

@@ -37,11 +37,11 @@ func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) {
37 37
 	}
38 38
 
39 39
 	if u != nil {
40
-		if u.Id == repo.OwnerId {
40
+		if u.Id == repo.OwnerID {
41 41
 			return ACCESS_MODE_OWNER, nil
42 42
 		}
43 43
 
44
-		a := &Access{UserID: u.Id, RepoID: repo.Id}
44
+		a := &Access{UserID: u.Id, RepoID: repo.ID}
45 45
 		if has, err := e.Get(a); !has || err != nil {
46 46
 			return mode, err
47 47
 		}
@@ -77,7 +77,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
77 77
 
78 78
 	repos := make(map[*Repository]AccessMode, len(accesses))
79 79
 	for _, access := range accesses {
80
-		repo, err := GetRepositoryById(access.RepoID)
80
+		repo, err := GetRepositoryByID(access.RepoID)
81 81
 		if err != nil {
82 82
 			if IsErrRepoNotExist(err) {
83 83
 				log.Error(4, "%v", err)
@@ -87,7 +87,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
87 87
 		}
88 88
 		if err = repo.GetOwner(); err != nil {
89 89
 			return nil, err
90
-		} else if repo.OwnerId == u.Id {
90
+		} else if repo.OwnerID == u.Id {
91 91
 			continue
92 92
 		}
93 93
 		repos[repo] = access.Mode
@@ -121,13 +121,13 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode
121 121
 		}
122 122
 		newAccesses = append(newAccesses, Access{
123 123
 			UserID: userID,
124
-			RepoID: repo.Id,
124
+			RepoID: repo.ID,
125 125
 			Mode:   mode,
126 126
 		})
127 127
 	}
128 128
 
129 129
 	// Delete old accesses and insert new ones for repository.
130
-	if _, err = e.Delete(&Access{RepoID: repo.Id}); err != nil {
130
+	if _, err = e.Delete(&Access{RepoID: repo.ID}); err != nil {
131 131
 		return fmt.Errorf("delete old accesses: %v", err)
132 132
 	} else if _, err = e.Insert(newAccesses); err != nil {
133 133
 		return fmt.Errorf("insert new accesses: %v", err)
@@ -193,7 +193,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
193 193
 			// have relations with repository.
194 194
 			if t.IsOwnerTeam() {
195 195
 				t.Authorize = ACCESS_MODE_OWNER
196
-			} else if !t.hasRepository(e, repo.Id) {
196
+			} else if !t.hasRepository(e, repo.ID) {
197 197
 				continue
198 198
 			}
199 199
 

+ 8 - 8
models/action.go

@@ -348,7 +348,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
348 348
 	// check if repo belongs to org and append additional webhooks
349 349
 	if repo.Owner.IsOrganization() {
350 350
 		// get hooks for org
351
-		orgws, err := GetActiveWebhooksByOrgId(repo.OwnerId)
351
+		orgws, err := GetActiveWebhooksByOrgId(repo.OwnerID)
352 352
 		if err != nil {
353 353
 			return errors.New("GetActiveWebhooksByOrgId: " + err.Error())
354 354
 		}
@@ -388,7 +388,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
388 388
 		Ref:     refFullName,
389 389
 		Commits: commits,
390 390
 		Repo: &PayloadRepo{
391
-			Id:          repo.Id,
391
+			Id:          repo.ID,
392 392
 			Name:        repo.LowerName,
393 393
 			Url:         repoLink,
394 394
 			Description: repo.Description,
@@ -431,7 +431,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
431 431
 		}
432 432
 
433 433
 		if err = CreateHookTask(&HookTask{
434
-			RepoID:      repo.Id,
434
+			RepoID:      repo.ID,
435 435
 			HookID:      w.Id,
436 436
 			Type:        w.HookTaskType,
437 437
 			Url:         w.Url,
@@ -453,12 +453,12 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
453 453
 		ActUserName:  u.Name,
454 454
 		ActEmail:     u.Email,
455 455
 		OpType:       CREATE_REPO,
456
-		RepoID:       repo.Id,
456
+		RepoID:       repo.ID,
457 457
 		RepoUserName: repo.Owner.Name,
458 458
 		RepoName:     repo.Name,
459 459
 		IsPrivate:    repo.IsPrivate,
460 460
 	}); err != nil {
461
-		return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.Id)
461
+		return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.ID)
462 462
 	}
463 463
 
464 464
 	log.Trace("action.NewRepoAction: %s/%s", u.Name, repo.Name)
@@ -476,19 +476,19 @@ func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repos
476 476
 		ActUserName:  actUser.Name,
477 477
 		ActEmail:     actUser.Email,
478 478
 		OpType:       TRANSFER_REPO,
479
-		RepoID:       repo.Id,
479
+		RepoID:       repo.ID,
480 480
 		RepoUserName: newOwner.Name,
481 481
 		RepoName:     repo.Name,
482 482
 		IsPrivate:    repo.IsPrivate,
483 483
 		Content:      path.Join(oldOwner.LowerName, repo.LowerName),
484 484
 	}
485 485
 	if err = notifyWatchers(e, action); err != nil {
486
-		return fmt.Errorf("notify watchers '%d/%s'", actUser.Id, repo.Id)
486
+		return fmt.Errorf("notify watchers '%d/%s'", actUser.Id, repo.ID)
487 487
 	}
488 488
 
489 489
 	// Remove watch for organization.
490 490
 	if repo.Owner.IsOrganization() {
491
-		if err = watchRepo(e, repo.Owner.Id, repo.Id, false); err != nil {
491
+		if err = watchRepo(e, repo.Owner.Id, repo.ID, false); err != nil {
492 492
 			return fmt.Errorf("watch repository: %v", err)
493 493
 		}
494 494
 	}

+ 14 - 14
models/issue.go

@@ -68,7 +68,7 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
68 68
 }
69 69
 
70 70
 func (i *Issue) GetPoster() (err error) {
71
-	i.Poster, err = GetUserById(i.PosterID)
71
+	i.Poster, err = GetUserByID(i.PosterID)
72 72
 	if IsErrUserNotExist(err) {
73 73
 		i.Poster = &User{Name: "FakeUser"}
74 74
 		return nil
@@ -104,7 +104,7 @@ func (i *Issue) GetAssignee() (err error) {
104 104
 		return nil
105 105
 	}
106 106
 
107
-	i.Assignee, err = GetUserById(i.AssigneeID)
107
+	i.Assignee, err = GetUserByID(i.AssigneeID)
108 108
 	if IsErrUserNotExist(err) {
109 109
 		return nil
110 110
 	}
@@ -170,7 +170,7 @@ func GetIssueByRef(ref string) (issue *Issue, err error) {
170 170
 		return
171 171
 	}
172 172
 
173
-	return GetIssueByIndex(repo.Id, issueNumber)
173
+	return GetIssueByIndex(repo.ID, issueNumber)
174 174
 }
175 175
 
176 176
 // GetIssueByIndex returns issue by given index in repository.
@@ -304,7 +304,7 @@ func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID in
304 304
 
305 305
 	iu := &IssueUser{
306 306
 		IssueId: issueID,
307
-		RepoId:  repo.Id,
307
+		RepoId:  repo.ID,
308 308
 	}
309 309
 
310 310
 	isNeedAddPoster := true
@@ -331,9 +331,9 @@ func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID in
331 331
 	}
332 332
 
333 333
 	// Add owner's as well.
334
-	if repo.OwnerId != posterID {
334
+	if repo.OwnerID != posterID {
335 335
 		iu.Id = 0
336
-		iu.Uid = repo.OwnerId
336
+		iu.Uid = repo.OwnerID
337 337
 		iu.IsAssigned = iu.Uid == assigneeID
338 338
 		if _, err = x.Insert(iu); err != nil {
339 339
 			return err
@@ -760,7 +760,7 @@ func MilestoneStats(repoID int64) (open int64, closed int64) {
760 760
 
761 761
 // ChangeMilestoneStatus changes the milestone open/closed status.
762 762
 func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
763
-	repo, err := GetRepositoryById(m.RepoID)
763
+	repo, err := GetRepositoryByID(m.RepoID)
764 764
 	if err != nil {
765 765
 		return err
766 766
 	}
@@ -776,9 +776,9 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
776 776
 		return err
777 777
 	}
778 778
 
779
-	repo.NumMilestones = int(countRepoMilestones(sess, repo.Id))
780
-	repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.Id))
781
-	if _, err = sess.Id(repo.Id).AllCols().Update(repo); err != nil {
779
+	repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
780
+	repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
781
+	if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil {
782 782
 		return err
783 783
 	}
784 784
 	return sess.Commit()
@@ -886,7 +886,7 @@ func DeleteMilestoneByID(mid int64) error {
886 886
 		return err
887 887
 	}
888 888
 
889
-	repo, err := GetRepositoryById(m.RepoID)
889
+	repo, err := GetRepositoryByID(m.RepoID)
890 890
 	if err != nil {
891 891
 		return err
892 892
 	}
@@ -901,9 +901,9 @@ func DeleteMilestoneByID(mid int64) error {
901 901
 		return err
902 902
 	}
903 903
 
904
-	repo.NumMilestones = int(countRepoMilestones(sess, repo.Id))
905
-	repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.Id))
906
-	if _, err = sess.Id(repo.Id).AllCols().Update(repo); err != nil {
904
+	repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
905
+	repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
906
+	if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil {
907 907
 		return err
908 908
 	}
909 909
 

+ 1 - 1
models/oauth2.go

@@ -58,7 +58,7 @@ func GetOauth2(identity string) (oa *Oauth2, err error) {
58 58
 	} else if oa.Uid == -1 {
59 59
 		return oa, ErrOauth2NotAssociated
60 60
 	}
61
-	oa.User, err = GetUserById(oa.Uid)
61
+	oa.User, err = GetUserByID(oa.Uid)
62 62
 	return oa, err
63 63
 }
64 64
 

+ 15 - 15
models/org.go

@@ -66,7 +66,7 @@ func (org *User) GetMembers() error {
66 66
 
67 67
 	org.Members = make([]*User, len(ous))
68 68
 	for i, ou := range ous {
69
-		org.Members[i], err = GetUserById(ou.Uid)
69
+		org.Members[i], err = GetUserByID(ou.Uid)
70 70
 		if err != nil {
71 71
 			return err
72 72
 		}
@@ -343,11 +343,11 @@ func RemoveOrgUser(orgId, uid int64) error {
343 343
 		return nil
344 344
 	}
345 345
 
346
-	u, err := GetUserById(uid)
346
+	u, err := GetUserByID(uid)
347 347
 	if err != nil {
348 348
 		return fmt.Errorf("GetUserById: %v", err)
349 349
 	}
350
-	org, err := GetUserById(orgId)
350
+	org, err := GetUserByID(orgId)
351 351
 	if err != nil {
352 352
 		return fmt.Errorf("get organization: %v", err)
353 353
 	} else if err = org.GetRepositories(); err != nil {
@@ -380,10 +380,10 @@ func RemoveOrgUser(orgId, uid int64) error {
380 380
 	// Delete all repository accesses.
381 381
 	access := &Access{UserID: u.Id}
382 382
 	for _, repo := range org.Repos {
383
-		access.RepoID = repo.Id
383
+		access.RepoID = repo.ID
384 384
 		if _, err = sess.Delete(access); err != nil {
385 385
 			return err
386
-		} else if err = watchRepo(sess, u.Id, repo.Id, false); err != nil {
386
+		} else if err = watchRepo(sess, u.Id, repo.ID, false); err != nil {
387 387
 			return err
388 388
 		}
389 389
 	}
@@ -443,7 +443,7 @@ func (t *Team) getRepositories(e Engine) (err error) {
443 443
 
444 444
 	t.Repos = make([]*Repository, 0, len(teamRepos))
445 445
 	for i := range teamRepos {
446
-		repo, err := getRepositoryById(e, teamRepos[i].RepoID)
446
+		repo, err := getRepositoryByID(e, teamRepos[i].RepoID)
447 447
 		if err != nil {
448 448
 			return fmt.Errorf("getRepositoryById(%d): %v", teamRepos[i].RepoID, err)
449 449
 		}
@@ -487,7 +487,7 @@ func (t *Team) HasRepository(repoID int64) bool {
487 487
 }
488 488
 
489 489
 func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
490
-	if err = addTeamRepo(e, t.OrgID, t.ID, repo.Id); err != nil {
490
+	if err = addTeamRepo(e, t.OrgID, t.ID, repo.ID); err != nil {
491 491
 		return err
492 492
 	}
493 493
 
@@ -504,7 +504,7 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
504 504
 		return fmt.Errorf("getMembers: %v", err)
505 505
 	}
506 506
 	for _, u := range t.Members {
507
-		if err = watchRepo(e, u.Id, repo.Id, true); err != nil {
507
+		if err = watchRepo(e, u.Id, repo.ID, true); err != nil {
508 508
 			return fmt.Errorf("watchRepo: %v", err)
509 509
 		}
510 510
 	}
@@ -513,9 +513,9 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
513 513
 
514 514
 // AddRepository adds new repository to team of organization.
515 515
 func (t *Team) AddRepository(repo *Repository) (err error) {
516
-	if repo.OwnerId != t.OrgID {
516
+	if repo.OwnerID != t.OrgID {
517 517
 		return errors.New("Repository does not belong to organization")
518
-	} else if t.HasRepository(repo.Id) {
518
+	} else if t.HasRepository(repo.ID) {
519 519
 		return nil
520 520
 	}
521 521
 
@@ -533,7 +533,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) {
533 533
 }
534 534
 
535 535
 func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (err error) {
536
-	if err = removeTeamRepo(e, t.ID, repo.Id); err != nil {
536
+	if err = removeTeamRepo(e, t.ID, repo.ID); err != nil {
537 537
 		return err
538 538
 	}
539 539
 
@@ -560,7 +560,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
560 560
 			continue
561 561
 		}
562 562
 
563
-		if err = watchRepo(e, u.Id, repo.Id, false); err != nil {
563
+		if err = watchRepo(e, u.Id, repo.ID, false); err != nil {
564 564
 			return err
565 565
 		}
566 566
 	}
@@ -574,7 +574,7 @@ func (t *Team) RemoveRepository(repoID int64) error {
574 574
 		return nil
575 575
 	}
576 576
 
577
-	repo, err := GetRepositoryById(repoID)
577
+	repo, err := GetRepositoryByID(repoID)
578 578
 	if err != nil {
579 579
 		return err
580 580
 	}
@@ -713,7 +713,7 @@ func DeleteTeam(t *Team) error {
713 713
 	}
714 714
 
715 715
 	// Get organization.
716
-	org, err := GetUserById(t.OrgID)
716
+	org, err := GetUserByID(t.OrgID)
717 717
 	if err != nil {
718 718
 		return err
719 719
 	}
@@ -903,7 +903,7 @@ func removeTeamMember(e Engine, orgId, teamId, uid int64) error {
903 903
 	}
904 904
 
905 905
 	// Get organization.
906
-	org, err := getUserById(e, orgId)
906
+	org, err := getUserByID(e, orgId)
907 907
 	if err != nil {
908 908
 		return err
909 909
 	}

+ 51 - 52
models/repo.go

@@ -129,8 +129,8 @@ func NewRepoContext() {
129 129
 
130 130
 // Repository represents a git repository.
131 131
 type Repository struct {
132
-	Id            int64
133
-	OwnerId       int64  `xorm:"UNIQUE(s)"`
132
+	ID            int64  `xorm:"pk autoincr"`
133
+	OwnerID       int64  `xorm:"UNIQUE(s)"`
134 134
 	Owner         *User  `xorm:"-"`
135 135
 	LowerName     string `xorm:"UNIQUE(s) INDEX NOT NULL"`
136 136
 	Name          string `xorm:"INDEX NOT NULL"`
@@ -159,8 +159,8 @@ type Repository struct {
159 159
 	*Mirror  `xorm:"-"`
160 160
 
161 161
 	IsFork   bool `xorm:"NOT NULL DEFAULT false"`
162
-	ForkId   int64
163
-	ForkRepo *Repository `xorm:"-"`
162
+	ForkID   int64
163
+	BaseRepo *Repository `xorm:"-"`
164 164
 
165 165
 	Created time.Time `xorm:"CREATED"`
166 166
 	Updated time.Time `xorm:"UPDATED"`
@@ -168,7 +168,7 @@ type Repository struct {
168 168
 
169 169
 func (repo *Repository) getOwner(e Engine) (err error) {
170 170
 	if repo.Owner == nil {
171
-		repo.Owner, err = getUserById(e, repo.OwnerId)
171
+		repo.Owner, err = getUserByID(e, repo.OwnerID)
172 172
 	}
173 173
 	return err
174 174
 }
@@ -178,16 +178,16 @@ func (repo *Repository) GetOwner() (err error) {
178 178
 }
179 179
 
180 180
 func (repo *Repository) GetMirror() (err error) {
181
-	repo.Mirror, err = GetMirror(repo.Id)
181
+	repo.Mirror, err = GetMirror(repo.ID)
182 182
 	return err
183 183
 }
184 184
 
185
-func (repo *Repository) GetForkRepo() (err error) {
185
+func (repo *Repository) GetBaseRepo() (err error) {
186 186
 	if !repo.IsFork {
187 187
 		return nil
188 188
 	}
189 189
 
190
-	repo.ForkRepo, err = GetRepositoryById(repo.ForkId)
190
+	repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
191 191
 	return err
192 192
 }
193 193
 
@@ -211,7 +211,7 @@ func (repo *Repository) HasAccess(u *User) bool {
211 211
 }
212 212
 
213 213
 func (repo *Repository) IsOwnedBy(u *User) bool {
214
-	return repo.OwnerId == u.Id
214
+	return repo.OwnerID == u.Id
215 215
 }
216 216
 
217 217
 // DescriptionHtml does special handles to description and return HTML string.
@@ -224,7 +224,7 @@ func (repo *Repository) DescriptionHtml() template.HTML {
224 224
 
225 225
 func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
226 226
 	has, err := e.Get(&Repository{
227
-		OwnerId:   u.Id,
227
+		OwnerID:   u.Id,
228 228
 		LowerName: strings.ToLower(repoName),
229 229
 	})
230 230
 	return has && com.IsDir(RepoPath(u.Name, repoName)), err
@@ -287,8 +287,8 @@ func IsUsableName(name string) error {
287 287
 
288 288
 // Mirror represents a mirror information of repository.
289 289
 type Mirror struct {
290
-	Id         int64
291
-	RepoId     int64
290
+	ID         int64 `xorm:"pk autoincr"`
291
+	RepoID     int64
292 292
 	RepoName   string    // <user name>/<repo name>
293 293
 	Interval   int       // Hour.
294 294
 	Updated    time.Time `xorm:"UPDATED"`
@@ -296,7 +296,7 @@ type Mirror struct {
296 296
 }
297 297
 
298 298
 func getMirror(e Engine, repoId int64) (*Mirror, error) {
299
-	m := &Mirror{RepoId: repoId}
299
+	m := &Mirror{RepoID: repoId}
300 300
 	has, err := e.Get(m)
301 301
 	if err != nil {
302 302
 		return nil, err
@@ -312,7 +312,7 @@ func GetMirror(repoId int64) (*Mirror, error) {
312 312
 }
313 313
 
314 314
 func updateMirror(e Engine, m *Mirror) error {
315
-	_, err := e.Id(m.Id).Update(m)
315
+	_, err := e.Id(m.ID).Update(m)
316 316
 	return err
317 317
 }
318 318
 
@@ -330,7 +330,7 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er
330 330
 	}
331 331
 
332 332
 	if _, err = x.InsertOne(&Mirror{
333
-		RepoId:     repoId,
333
+		RepoID:     repoId,
334 334
 		RepoName:   strings.ToLower(userName + "/" + repoName),
335 335
 		Interval:   24,
336 336
 		NextUpdate: time.Now().Add(24 * time.Hour),
@@ -365,7 +365,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
365 365
 
366 366
 	repo.IsBare = false
367 367
 	if mirror {
368
-		if err = MirrorRepository(repo.Id, u.Name, repo.Name, repoPath, url); err != nil {
368
+		if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, url); err != nil {
369 369
 			return repo, err
370 370
 		}
371 371
 		repo.IsMirror = true
@@ -517,7 +517,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, initRe
517 517
 	if len(fileName) == 0 {
518 518
 		// Re-fetch the repository from database before updating it (else it would
519 519
 		// override changes that were done earlier with sql)
520
-		if repo, err = getRepositoryById(e, repo.Id); err != nil {
520
+		if repo, err = getRepositoryByID(e, repo.ID); err != nil {
521 521
 			return err
522 522
 		}
523 523
 		repo.IsBare = true
@@ -562,7 +562,7 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
562 562
 		}
563 563
 	}
564 564
 
565
-	if err = watchRepo(e, u.Id, repo.Id, true); err != nil {
565
+	if err = watchRepo(e, u.Id, repo.ID, true); err != nil {
566 566
 		return fmt.Errorf("watchRepo: %v", err)
567 567
 	} else if err = newRepoAction(e, u, repo); err != nil {
568 568
 		return fmt.Errorf("newRepoAction: %v", err)
@@ -574,7 +574,7 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
574 574
 // CreateRepository creates a repository for given user or organization.
575 575
 func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMirror, initReadme bool) (_ *Repository, err error) {
576 576
 	repo := &Repository{
577
-		OwnerId:     u.Id,
577
+		OwnerID:     u.Id,
578 578
 		Owner:       u,
579 579
 		Name:        name,
580 580
 		LowerName:   strings.ToLower(name),
@@ -630,12 +630,12 @@ func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) {
630 630
 	}
631 631
 
632 632
 	for _, repo := range repos {
633
-		repo.Owner = &User{Id: repo.OwnerId}
633
+		repo.Owner = &User{Id: repo.OwnerID}
634 634
 		has, err := x.Get(repo.Owner)
635 635
 		if err != nil {
636 636
 			return nil, err
637 637
 		} else if !has {
638
-			return nil, ErrUserNotExist{repo.OwnerId, ""}
638
+			return nil, ErrUserNotExist{repo.OwnerID, ""}
639 639
 		}
640 640
 	}
641 641
 
@@ -672,11 +672,11 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
672 672
 
673 673
 	// Note: we have to set value here to make sure recalculate accesses is based on
674 674
 	//	new owner.
675
-	repo.OwnerId = newOwner.Id
675
+	repo.OwnerID = newOwner.Id
676 676
 	repo.Owner = newOwner
677 677
 
678 678
 	// Update repository.
679
-	if _, err := sess.Id(repo.Id).Update(repo); err != nil {
679
+	if _, err := sess.Id(repo.ID).Update(repo); err != nil {
680 680
 		return fmt.Errorf("update owner: %v", err)
681 681
 	}
682 682
 
@@ -687,7 +687,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
687 687
 	}
688 688
 
689 689
 	// Dummy object.
690
-	collaboration := &Collaboration{RepoID: repo.Id}
690
+	collaboration := &Collaboration{RepoID: repo.ID}
691 691
 	for _, c := range collaborators {
692 692
 		collaboration.UserID = c.Id
693 693
 		if c.Id == newOwner.Id || newOwner.IsOrgMember(c.Id) {
@@ -703,7 +703,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
703 703
 			return fmt.Errorf("getTeams: %v", err)
704 704
 		}
705 705
 		for _, t := range owner.Teams {
706
-			if !t.hasRepository(sess, repo.Id) {
706
+			if !t.hasRepository(sess, repo.ID) {
707 707
 				continue
708 708
 			}
709 709
 
@@ -713,7 +713,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
713 713
 			}
714 714
 		}
715 715
 
716
-		if err = owner.removeOrgRepo(sess, repo.Id); err != nil {
716
+		if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
717 717
 			return fmt.Errorf("removeOrgRepo: %v", err)
718 718
 		}
719 719
 	}
@@ -739,7 +739,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
739 739
 		return fmt.Errorf("decrease old owner repository count: %v", err)
740 740
 	}
741 741
 
742
-	if err = watchRepo(sess, newOwner.Id, repo.Id, true); err != nil {
742
+	if err = watchRepo(sess, newOwner.Id, repo.ID, true); err != nil {
743 743
 		return fmt.Errorf("watchRepo: %v", err)
744 744
 	} else if err = transferRepoAction(sess, u, owner, newOwner, repo); err != nil {
745 745
 		return fmt.Errorf("transferRepoAction: %v", err)
@@ -747,7 +747,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
747 747
 
748 748
 	// Update mirror information.
749 749
 	if repo.IsMirror {
750
-		mirror, err := getMirror(sess, repo.Id)
750
+		mirror, err := getMirror(sess, repo.ID)
751 751
 		if err != nil {
752 752
 			return fmt.Errorf("getMirror: %v", err)
753 753
 		}
@@ -794,7 +794,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
794 794
 		repo.Website = repo.Website[:255]
795 795
 	}
796 796
 
797
-	if _, err = e.Id(repo.Id).AllCols().Update(repo); err != nil {
797
+	if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
798 798
 		return fmt.Errorf("update: %v", err)
799 799
 	}
800 800
 
@@ -831,7 +831,7 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
831 831
 
832 832
 // DeleteRepository deletes a repository for a user or organization.
833 833
 func DeleteRepository(uid, repoID int64, userName string) error {
834
-	repo := &Repository{Id: repoID, OwnerId: uid}
834
+	repo := &Repository{ID: repoID, OwnerID: uid}
835 835
 	has, err := x.Get(repo)
836 836
 	if err != nil {
837 837
 		return err
@@ -840,7 +840,7 @@ func DeleteRepository(uid, repoID int64, userName string) error {
840 840
 	}
841 841
 
842 842
 	// In case is a organization.
843
-	org, err := GetUserById(uid)
843
+	org, err := GetUserByID(uid)
844 844
 	if err != nil {
845 845
 		return err
846 846
 	}
@@ -866,15 +866,15 @@ func DeleteRepository(uid, repoID int64, userName string) error {
866 866
 		}
867 867
 	}
868 868
 
869
-	if _, err = sess.Delete(&Repository{Id: repoID}); err != nil {
869
+	if _, err = sess.Delete(&Repository{ID: repoID}); err != nil {
870 870
 		return err
871
-	} else if _, err = sess.Delete(&Access{RepoID: repo.Id}); err != nil {
871
+	} else if _, err = sess.Delete(&Access{RepoID: repo.ID}); err != nil {
872 872
 		return err
873
-	} else if _, err = sess.Delete(&Action{RepoID: repo.Id}); err != nil {
873
+	} else if _, err = sess.Delete(&Action{RepoID: repo.ID}); err != nil {
874 874
 		return err
875 875
 	} else if _, err = sess.Delete(&Watch{RepoID: repoID}); err != nil {
876 876
 		return err
877
-	} else if _, err = sess.Delete(&Mirror{RepoId: repoID}); err != nil {
877
+	} else if _, err = sess.Delete(&Mirror{RepoID: repoID}); err != nil {
878 878
 		return err
879 879
 	} else if _, err = sess.Delete(&IssueUser{RepoId: repoID}); err != nil {
880 880
 		return err
@@ -902,7 +902,7 @@ func DeleteRepository(uid, repoID int64, userName string) error {
902 902
 	}
903 903
 
904 904
 	if repo.IsFork {
905
-		if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkId); err != nil {
905
+		if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
906 906
 			return err
907 907
 		}
908 908
 	}
@@ -946,7 +946,7 @@ func GetRepositoryByRef(ref string) (*Repository, error) {
946 946
 // GetRepositoryByName returns the repository by given name under user if exists.
947 947
 func GetRepositoryByName(uid int64, repoName string) (*Repository, error) {
948 948
 	repo := &Repository{
949
-		OwnerId:   uid,
949
+		OwnerID:   uid,
950 950
 		LowerName: strings.ToLower(repoName),
951 951
 	}
952 952
 	has, err := x.Get(repo)
@@ -958,7 +958,7 @@ func GetRepositoryByName(uid int64, repoName string) (*Repository, error) {
958 958
 	return repo, err
959 959
 }
960 960
 
961
-func getRepositoryById(e Engine, id int64) (*Repository, error) {
961
+func getRepositoryByID(e Engine, id int64) (*Repository, error) {
962 962
 	repo := new(Repository)
963 963
 	has, err := e.Id(id).Get(repo)
964 964
 	if err != nil {
@@ -969,9 +969,9 @@ func getRepositoryById(e Engine, id int64) (*Repository, error) {
969 969
 	return repo, nil
970 970
 }
971 971
 
972
-// GetRepositoryById returns the repository by given id if exists.
973
-func GetRepositoryById(id int64) (*Repository, error) {
974
-	return getRepositoryById(x, id)
972
+// GetRepositoryByID returns the repository by given id if exists.
973
+func GetRepositoryByID(id int64) (*Repository, error) {
974
+	return getRepositoryByID(x, id)
975 975
 }
976 976
 
977 977
 // GetRepositories returns a list of repositories of given user.
@@ -982,8 +982,7 @@ func GetRepositories(uid int64, private bool) ([]*Repository, error) {
982 982
 		sess.Where("is_private=?", false)
983 983
 	}
984 984
 
985
-	err := sess.Find(&repos, &Repository{OwnerId: uid})
986
-	return repos, err
985
+	return repos, sess.Find(&repos, &Repository{OwnerID: uid})
987 986
 }
988 987
 
989 988
 // GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
@@ -993,8 +992,8 @@ func GetRecentUpdatedRepositories(num int) (repos []*Repository, err error) {
993 992
 }
994 993
 
995 994
 // GetRepositoryCount returns the total number of repositories of user.
996
-func GetRepositoryCount(user *User) (int64, error) {
997
-	return x.Count(&Repository{OwnerId: user.Id})
995
+func GetRepositoryCount(u *User) (int64, error) {
996
+	return x.Count(&Repository{OwnerID: u.Id})
998 997
 }
999 998
 
1000 999
 type SearchOption struct {
@@ -1199,7 +1198,7 @@ type Collaboration struct {
1199 1198
 // Add collaborator and accompanying access
1200 1199
 func (repo *Repository) AddCollaborator(u *User) error {
1201 1200
 	collaboration := &Collaboration{
1202
-		RepoID: repo.Id,
1201
+		RepoID: repo.ID,
1203 1202
 		UserID: u.Id,
1204 1203
 	}
1205 1204
 
@@ -1238,13 +1237,13 @@ func (repo *Repository) AddCollaborator(u *User) error {
1238 1237
 
1239 1238
 func (repo *Repository) getCollaborators(e Engine) ([]*User, error) {
1240 1239
 	collaborations := make([]*Collaboration, 0)
1241
-	if err := e.Find(&collaborations, &Collaboration{RepoID: repo.Id}); err != nil {
1240
+	if err := e.Find(&collaborations, &Collaboration{RepoID: repo.ID}); err != nil {
1242 1241
 		return nil, err
1243 1242
 	}
1244 1243
 
1245 1244
 	users := make([]*User, len(collaborations))
1246 1245
 	for i, c := range collaborations {
1247
-		user, err := getUserById(e, c.UserID)
1246
+		user, err := getUserByID(e, c.UserID)
1248 1247
 		if err != nil {
1249 1248
 			return nil, err
1250 1249
 		}
@@ -1261,7 +1260,7 @@ func (repo *Repository) GetCollaborators() ([]*User, error) {
1261 1260
 // Delete collaborator and accompanying access
1262 1261
 func (repo *Repository) DeleteCollaborator(u *User) (err error) {
1263 1262
 	collaboration := &Collaboration{
1264
-		RepoID: repo.Id,
1263
+		RepoID: repo.ID,
1265 1264
 		UserID: u.Id,
1266 1265
 	}
1267 1266
 
@@ -1430,14 +1429,14 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
1430 1429
 
1431 1430
 func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
1432 1431
 	repo := &Repository{
1433
-		OwnerId:     u.Id,
1432
+		OwnerID:     u.Id,
1434 1433
 		Owner:       u,
1435 1434
 		Name:        name,
1436 1435
 		LowerName:   strings.ToLower(name),
1437 1436
 		Description: desc,
1438 1437
 		IsPrivate:   oldRepo.IsPrivate,
1439 1438
 		IsFork:      true,
1440
-		ForkId:      oldRepo.Id,
1439
+		ForkID:      oldRepo.ID,
1441 1440
 	}
1442 1441
 
1443 1442
 	sess := x.NewSession()
@@ -1450,7 +1449,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
1450 1449
 		return nil, err
1451 1450
 	}
1452 1451
 
1453
-	if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.Id); err != nil {
1452
+	if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
1454 1453
 		return nil, err
1455 1454
 	}
1456 1455
 

+ 2 - 2
models/update.go

@@ -105,7 +105,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
105 105
 		commit := &base.PushCommits{}
106 106
 
107 107
 		if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
108
-			repos.Id, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil {
108
+			repos.ID, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil {
109 109
 			log.GitLogger.Fatal(4, "CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
110 110
 		}
111 111
 		return err
@@ -154,7 +154,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
154 154
 	}
155 155
 
156 156
 	if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
157
-		repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitId, newCommitId); err != nil {
157
+		repos.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitId, newCommitId); err != nil {
158 158
 		return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
159 159
 	}
160 160
 	return nil

+ 8 - 8
models/user.go

@@ -226,7 +226,7 @@ func (u *User) GetOrganizations() error {
226 226
 
227 227
 	u.Orgs = make([]*User, len(ous))
228 228
 	for i, ou := range ous {
229
-		u.Orgs[i], err = GetUserById(ou.OrgID)
229
+		u.Orgs[i], err = GetUserByID(ou.OrgID)
230 230
 		if err != nil {
231 231
 			return err
232 232
 		}
@@ -555,7 +555,7 @@ func GetUserByKeyId(keyId int64) (*User, error) {
555 555
 	return user, nil
556 556
 }
557 557
 
558
-func getUserById(e Engine, id int64) (*User, error) {
558
+func getUserByID(e Engine, id int64) (*User, error) {
559 559
 	u := new(User)
560 560
 	has, err := e.Id(id).Get(u)
561 561
 	if err != nil {
@@ -566,9 +566,9 @@ func getUserById(e Engine, id int64) (*User, error) {
566 566
 	return u, nil
567 567
 }
568 568
 
569
-// GetUserById returns the user object by given ID if exists.
570
-func GetUserById(id int64) (*User, error) {
571
-	return getUserById(x, id)
569
+// GetUserByID returns the user object by given ID if exists.
570
+func GetUserByID(id int64) (*User, error) {
571
+	return getUserByID(x, id)
572 572
 }
573 573
 
574 574
 // GetUserByName returns user by given name.
@@ -620,7 +620,7 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) {
620 620
 		return nil, err
621 621
 	}
622 622
 
623
-	u, err := GetUserById(uid)
623
+	u, err := GetUserByID(uid)
624 624
 	if err != nil {
625 625
 		return nil, err
626 626
 	}
@@ -666,7 +666,7 @@ func (email *EmailAddress) Activate() error {
666 666
 		return err
667 667
 	}
668 668
 
669
-	if user, err := GetUserById(email.Uid); err != nil {
669
+	if user, err := GetUserByID(email.Uid); err != nil {
670 670
 		return err
671 671
 	} else {
672 672
 		user.Rands = GetUserSalt()
@@ -793,7 +793,7 @@ func GetUserByEmail(email string) (*User, error) {
793 793
 		return nil, err
794 794
 	}
795 795
 	if has {
796
-		return GetUserById(emailAddress.Uid)
796
+		return GetUserByID(emailAddress.Uid)
797 797
 	}
798 798
 
799 799
 	return nil, ErrUserNotExist{0, "email"}

+ 2 - 2
modules/auth/auth.go

@@ -54,7 +54,7 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
54 54
 		return 0
55 55
 	}
56 56
 	if id, ok := uid.(int64); ok {
57
-		if _, err := models.GetUserById(id); err != nil {
57
+		if _, err := models.GetUserByID(id); err != nil {
58 58
 			if !models.IsErrUserNotExist(err) {
59 59
 				log.Error(4, "GetUserById: %v", err)
60 60
 			}
@@ -127,7 +127,7 @@ func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
127 127
 		return nil, false
128 128
 	}
129 129
 
130
-	u, err := models.GetUserById(uid)
130
+	u, err := models.GetUserByID(uid)
131 131
 	if err != nil {
132 132
 		log.Error(4, "GetUserById: %v", err)
133 133
 		return nil, false

File diff suppressed because it is too large
+ 2 - 2
modules/bindata/bindata.go


+ 2 - 2
modules/mailer/mail.go

@@ -156,7 +156,7 @@ func SendResetPasswdMail(r macaron.Render, u *models.User) {
156 156
 
157 157
 // SendIssueNotifyMail sends mail notification of all watchers of repository.
158 158
 func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
159
-	ws, err := models.GetWatchers(repo.Id)
159
+	ws, err := models.GetWatchers(repo.ID)
160 160
 	if err != nil {
161 161
 		return nil, errors.New("mail.NotifyWatchers(GetWatchers): " + err.Error())
162 162
 	}
@@ -167,7 +167,7 @@ func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *
167 167
 		if u.Id == uid {
168 168
 			continue
169 169
 		}
170
-		u, err := models.GetUserById(uid)
170
+		u, err := models.GetUserByID(uid)
171 171
 		if err != nil {
172 172
 			return nil, errors.New("mail.NotifyWatchers(GetUserById): " + err.Error())
173 173
 		}

+ 33 - 9
modules/middleware/repo.go

@@ -257,7 +257,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
257 257
 		ctx.Data["HasAccess"] = true
258 258
 
259 259
 		if repo.IsMirror {
260
-			ctx.Repo.Mirror, err = models.GetMirror(repo.Id)
260
+			ctx.Repo.Mirror, err = models.GetMirror(repo.ID)
261 261
 			if err != nil {
262 262
 				ctx.Handle(500, "GetMirror", err)
263 263
 				return
@@ -291,10 +291,34 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
291 291
 		ctx.Data["Tags"] = tags
292 292
 		ctx.Repo.Repository.NumTags = len(tags)
293 293
 
294
-		// Non-fork repository will not return error in this method.
295
-		if err = repo.GetForkRepo(); err != nil {
296
-			ctx.Handle(500, "GetForkRepo", err)
297
-			return
294
+		if repo.IsFork {
295
+			// Non-fork repository will not return error in this method.
296
+			if err = repo.GetBaseRepo(); err != nil {
297
+				ctx.Handle(500, "GetBaseRepo", err)
298
+				return
299
+			} else if repo.BaseRepo.GetOwner(); err != nil {
300
+				ctx.Handle(500, "BaseRepo.GetOwner", err)
301
+				return
302
+			}
303
+
304
+			bsaeRepo := repo.BaseRepo
305
+			baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name))
306
+			if err != nil {
307
+				ctx.Handle(500, "OpenRepository", err)
308
+				return
309
+			}
310
+			if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) {
311
+				ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch
312
+			} else {
313
+				baseBranches, err := baseGitRepo.GetBranches()
314
+				if err != nil {
315
+					ctx.Handle(500, "GetBranches", err)
316
+					return
317
+				}
318
+				if len(baseBranches) > 0 {
319
+					ctx.Data["BaseDefaultBranch"] = baseBranches[0]
320
+				}
321
+			}
298 322
 		}
299 323
 
300 324
 		ctx.Data["Title"] = u.Name + "/" + repo.Name
@@ -327,8 +351,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
327 351
 		}
328 352
 
329 353
 		if ctx.IsSigned {
330
-			ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.Id)
331
-			ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.Id)
354
+			ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID)
355
+			ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID)
332 356
 		}
333 357
 
334 358
 		ctx.Data["TagName"] = ctx.Repo.TagName
@@ -342,8 +366,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
342 366
 
343 367
 		// If not branch selected, try default one.
344 368
 		// If default branch doesn't exists, fall back to some other branch.
345
-		if ctx.Repo.BranchName == "" {
346
-			if ctx.Repo.Repository.DefaultBranch != "" && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
369
+		if len(ctx.Repo.BranchName) == 0 {
370
+			if len(ctx.Repo.Repository.DefaultBranch) > 0 && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
347 371
 				ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
348 372
 			} else if len(brs) > 0 {
349 373
 				ctx.Repo.BranchName = brs[0]

File diff suppressed because it is too large
+ 1 - 1
public/css/gogs.min.css


+ 11 - 0
public/js/gogs.js

@@ -93,6 +93,17 @@ function initRepository() {
93 93
             $('#add-deploy-key-panel').show();
94 94
         });
95 95
     }
96
+
97
+    // Pull request
98
+    if ($('.repository.compare.pull').length > 0) {
99
+        $('.choose.branch .dropdown').dropdown({
100
+            action: 'hide',
101
+            fullTextSearch: true,
102
+            onNoResults: function () {
103
+                $('.choose.branch .dropdown .active').addClass('selected');
104
+            }
105
+        });
106
+    }
96 107
 };
97 108
 
98 109
 $(document).ready(function () {

+ 40 - 0
public/less/_repository.less

@@ -223,6 +223,46 @@
223 223
 			padding-left: 20px!important;
224 224
 		}
225 225
 	}
226
+
227
+	&.compare.pull {
228
+		.choose.branch {
229
+			.octicon {
230
+				padding-right: 10px;
231
+			}
232
+		}
233
+	}
234
+
235
+	.filter.dropdown .menu {
236
+		margin-top: 1px!important;
237
+		.items {
238
+			max-height: 300px;
239
+			overflow-y: auto;
240
+			.item {
241
+				position: relative;
242
+				cursor: pointer;
243
+				display: block;
244
+				border: none;
245
+				height: auto;
246
+				border-top: none;
247
+				line-height: 1em;
248
+				color: rgba(0,0,0,.8);
249
+				padding: .71428571em 1.14285714em!important;
250
+				font-size: 1rem;
251
+				text-transform: none;
252
+				font-weight: 400;
253
+				box-shadow: none;
254
+				-webkit-touch-callout: none;
255
+				&.active {
256
+					font-weight: 700;
257
+				}
258
+				&:hover {
259
+			    background: rgba(0,0,0,.05);
260
+			    color: rgba(0,0,0,.8);
261
+			    z-index: 13;
262
+				}
263
+			}
264
+		}
265
+	}
226 266
 }
227 267
 
228 268
 .settings .key.list {

+ 5 - 5
routers/admin/users.go

@@ -139,9 +139,9 @@ func EditUser(ctx *middleware.Context) {
139 139
 		return
140 140
 	}
141 141
 
142
-	u, err := models.GetUserById(uid)
142
+	u, err := models.GetUserByID(uid)
143 143
 	if err != nil {
144
-		ctx.Handle(500, "GetUserById", err)
144
+		ctx.Handle(500, "GetUserByID", err)
145 145
 		return
146 146
 	}
147 147
 
@@ -166,7 +166,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
166 166
 		return
167 167
 	}
168 168
 
169
-	u, err := models.GetUserById(uid)
169
+	u, err := models.GetUserByID(uid)
170 170
 	if err != nil {
171 171
 		ctx.Handle(500, "GetUserById", err)
172 172
 		return
@@ -219,9 +219,9 @@ func DeleteUser(ctx *middleware.Context) {
219 219
 		return
220 220
 	}
221 221
 
222
-	u, err := models.GetUserById(uid)
222
+	u, err := models.GetUserByID(uid)
223 223
 	if err != nil {
224
-		ctx.Handle(500, "GetUserById", err)
224
+		ctx.Handle(500, "GetUserByID", err)
225 225
 		return
226 226
 	}
227 227
 

+ 6 - 6
routers/api/v1/repo.go

@@ -28,7 +28,7 @@ func ToApiRepository(owner *models.User, repo *models.Repository, permission api
28 28
 		log.Error(4, "CloneLink: %v", err)
29 29
 	}
30 30
 	return &api.Repository{
31
-		Id:          repo.Id,
31
+		Id:          repo.ID,
32 32
 		Owner:       *ToApiUser(owner),
33 33
 		FullName:    owner.Name + "/" + repo.Name,
34 34
 		Private:     repo.IsPrivate,
@@ -55,7 +55,7 @@ func SearchRepos(ctx *middleware.Context) {
55 55
 		if ctx.User.Id == opt.Uid {
56 56
 			opt.Private = true
57 57
 		} else {
58
-			u, err := models.GetUserById(opt.Uid)
58
+			u, err := models.GetUserByID(opt.Uid)
59 59
 			if err != nil {
60 60
 				ctx.JSON(500, map[string]interface{}{
61 61
 					"ok":    false,
@@ -89,7 +89,7 @@ func SearchRepos(ctx *middleware.Context) {
89 89
 			return
90 90
 		}
91 91
 		results[i] = &api.Repository{
92
-			Id:       repos[i].Id,
92
+			Id:       repos[i].ID,
93 93
 			FullName: path.Join(repos[i].Owner.Name, repos[i].Name),
94 94
 		}
95 95
 	}
@@ -111,7 +111,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
111 111
 		} else {
112 112
 			log.Error(4, "CreateRepository: %v", err)
113 113
 			if repo != nil {
114
-				if err = models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); err != nil {
114
+				if err = models.DeleteRepository(ctx.User.Id, repo.ID, ctx.User.Name); err != nil {
115 115
 					log.Error(4, "DeleteRepository: %v", err)
116 116
 				}
117 117
 			}
@@ -172,7 +172,7 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
172 172
 	ctxUser := u
173 173
 	// Not equal means current user is an organization.
174 174
 	if form.Uid != u.Id {
175
-		org, err := models.GetUserById(form.Uid)
175
+		org, err := models.GetUserByID(form.Uid)
176 176
 		if err != nil {
177 177
 			if models.IsErrUserNotExist(err) {
178 178
 				ctx.HandleAPI(422, err)
@@ -219,7 +219,7 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
219 219
 	repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
220 220
 	if err != nil {
221 221
 		if repo != nil {
222
-			if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
222
+			if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID, ctxUser.Name); errDelete != nil {
223 223
 				log.Error(4, "DeleteRepository: %v", errDelete)
224 224
 			}
225 225
 		}

+ 2 - 2
routers/api/v1/repo_hooks.go

@@ -17,7 +17,7 @@ import (
17 17
 // GET /repos/:username/:reponame/hooks
18 18
 // https://developer.github.com/v3/repos/hooks/#list-hooks
19 19
 func ListRepoHooks(ctx *middleware.Context) {
20
-	hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id)
20
+	hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID)
21 21
 	if err != nil {
22 22
 		ctx.JSON(500, &base.ApiJsonErr{"GetWebhooksByRepoId: " + err.Error(), base.DOC_URL})
23 23
 		return
@@ -67,7 +67,7 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
67 67
 	}
68 68
 
69 69
 	w := &models.Webhook{
70
-		RepoId:      ctx.Repo.Repository.Id,
70
+		RepoId:      ctx.Repo.Repository.ID,
71 71
 		Url:         form.Config["url"],
72 72
 		ContentType: models.ToHookContentType(form.Config["content_type"]),
73 73
 		Secret:      form.Config["secret"],

+ 1 - 1
routers/home.go

@@ -57,7 +57,7 @@ func Explore(ctx *middleware.Context) {
57 57
 	}
58 58
 	for _, repo := range repos {
59 59
 		if err = repo.GetOwner(); err != nil {
60
-			ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.Id, err))
60
+			ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
61 61
 			return
62 62
 		}
63 63
 	}

+ 2 - 2
routers/repo/http.go

@@ -122,7 +122,7 @@ func Http(ctx *middleware.Context) {
122 122
 				}
123 123
 				return
124 124
 			}
125
-			authUser, err = models.GetUserById(token.Uid)
125
+			authUser, err = models.GetUserByID(token.Uid)
126 126
 			if err != nil {
127 127
 				ctx.Handle(500, "GetUserById", err)
128 128
 				return
@@ -191,7 +191,7 @@ func Http(ctx *middleware.Context) {
191 191
 
192 192
 						// FIXME: handle error.
193 193
 						if err = models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id); err == nil {
194
-							models.HookQueue.AddRepoID(repo.Id)
194
+							models.HookQueue.AddRepoID(repo.ID)
195 195
 						}
196 196
 
197 197
 					}

+ 28 - 28
routers/repo/issue.go

@@ -44,7 +44,7 @@ var (
44 44
 )
45 45
 
46 46
 func RetrieveLabels(ctx *middleware.Context) {
47
-	labels, err := models.GetLabels(ctx.Repo.Repository.Id)
47
+	labels, err := models.GetLabels(ctx.Repo.Repository.ID)
48 48
 	if err != nil {
49 49
 		ctx.Handle(500, "RetrieveLabels.GetLabels: %v", err)
50 50
 		return
@@ -95,7 +95,7 @@ func Issues(ctx *middleware.Context) {
95 95
 	selectLabels := ctx.Query("labels")
96 96
 	milestoneID := ctx.QueryInt64("milestone")
97 97
 	isShowClosed := ctx.Query("state") == "closed"
98
-	issueStats := models.GetIssueStats(repo.Id, uid, com.StrTo(selectLabels).MustInt64(), milestoneID, isShowClosed, filterMode)
98
+	issueStats := models.GetIssueStats(repo.ID, uid, com.StrTo(selectLabels).MustInt64(), milestoneID, isShowClosed, filterMode)
99 99
 
100 100
 	page := ctx.QueryInt("page")
101 101
 	if page <= 1 {
@@ -111,7 +111,7 @@ func Issues(ctx *middleware.Context) {
111 111
 	ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)
112 112
 
113 113
 	// Get issues.
114
-	issues, err := models.Issues(uid, assigneeID, repo.Id, posterID, milestoneID,
114
+	issues, err := models.Issues(uid, assigneeID, repo.ID, posterID, milestoneID,
115 115
 		page, isShowClosed, filterMode == models.FM_MENTION, selectLabels, ctx.Query("sortType"))
116 116
 	if err != nil {
117 117
 		ctx.Handle(500, "GetIssues: %v", err)
@@ -119,7 +119,7 @@ func Issues(ctx *middleware.Context) {
119 119
 	}
120 120
 
121 121
 	// Get issue-user pairs.
122
-	pairs, err := models.GetIssueUserPairs(repo.Id, posterID, isShowClosed)
122
+	pairs, err := models.GetIssueUserPairs(repo.ID, posterID, isShowClosed)
123 123
 	if err != nil {
124 124
 		ctx.Handle(500, "GetIssueUserPairs: %v", err)
125 125
 		return
@@ -153,7 +153,7 @@ func Issues(ctx *middleware.Context) {
153 153
 	ctx.Data["Issues"] = issues
154 154
 
155 155
 	// Get milestones.
156
-	miles, err := models.GetAllRepoMilestones(repo.Id)
156
+	miles, err := models.GetAllRepoMilestones(repo.ID)
157 157
 	if err != nil {
158 158
 		ctx.Handle(500, "GetAllRepoMilestones: %v", err)
159 159
 		return
@@ -185,12 +185,12 @@ func CreateIssue(ctx *middleware.Context) {
185 185
 		err  error
186 186
 	)
187 187
 	// Get all milestones.
188
-	ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.Id, -1, false)
188
+	ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
189 189
 	if err != nil {
190 190
 		ctx.Handle(500, "GetMilestones.1: %v", err)
191 191
 		return
192 192
 	}
193
-	ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.Id, -1, true)
193
+	ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true)
194 194
 	if err != nil {
195 195
 		ctx.Handle(500, "GetMilestones.2: %v", err)
196 196
 		return
@@ -229,12 +229,12 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
229 229
 
230 230
 	var err error
231 231
 	// Get all milestones.
232
-	_, err = models.GetMilestones(ctx.Repo.Repository.Id, -1, false)
232
+	_, err = models.GetMilestones(ctx.Repo.Repository.ID, -1, false)
233 233
 	if err != nil {
234 234
 		send(500, nil, err)
235 235
 		return
236 236
 	}
237
-	_, err = models.GetMilestones(ctx.Repo.Repository.Id, -1, true)
237
+	_, err = models.GetMilestones(ctx.Repo.Repository.ID, -1, true)
238 238
 	if err != nil {
239 239
 		send(500, nil, err)
240 240
 		return
@@ -256,7 +256,7 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
256 256
 		form.AssigneeId = 0
257 257
 	}
258 258
 	issue := &models.Issue{
259
-		RepoID:      ctx.Repo.Repository.Id,
259
+		RepoID:      ctx.Repo.Repository.ID,
260 260
 		Index:       int64(ctx.Repo.Repository.NumIssues) + 1,
261 261
 		Name:        form.IssueName,
262 262
 		PosterID:    ctx.User.Id,
@@ -297,7 +297,7 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
297 297
 		ActEmail:     ctx.User.Email,
298 298
 		OpType:       models.CREATE_ISSUE,
299 299
 		Content:      fmt.Sprintf("%d|%s", issue.Index, issue.Name),
300
-		RepoID:       ctx.Repo.Repository.Id,
300
+		RepoID:       ctx.Repo.Repository.ID,
301 301
 		RepoUserName: ctx.Repo.Owner.Name,
302 302
 		RepoName:     ctx.Repo.Repository.Name,
303 303
 		RefName:      ctx.Repo.BranchName,
@@ -332,7 +332,7 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
332 332
 			return
333 333
 		}
334 334
 	}
335
-	log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.ID)
335
+	log.Trace("%d Issue created: %d", ctx.Repo.Repository.ID, issue.ID)
336 336
 
337 337
 	send(200, fmt.Sprintf("%s/%s/%s/issues/%d", setting.AppSubUrl, ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil)
338 338
 }
@@ -357,7 +357,7 @@ func ViewIssue(ctx *middleware.Context) {
357 357
 		return
358 358
 	}
359 359
 
360
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx)
360
+	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, idx)
361 361
 	if err != nil {
362 362
 		if err == models.ErrIssueNotExist {
363 363
 			ctx.Handle(404, "GetIssueByIndex", err)
@@ -372,7 +372,7 @@ func ViewIssue(ctx *middleware.Context) {
372 372
 		ctx.Handle(500, "GetLabels", err)
373 373
 		return
374 374
 	}
375
-	labels, err := models.GetLabels(ctx.Repo.Repository.Id)
375
+	labels, err := models.GetLabels(ctx.Repo.Repository.ID)
376 376
 	if err != nil {
377 377
 		ctx.Handle(500, "GetLabels.2", err)
378 378
 		return
@@ -394,12 +394,12 @@ func ViewIssue(ctx *middleware.Context) {
394 394
 	}
395 395
 
396 396
 	// Get all milestones.
397
-	ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, -1, false)
397
+	ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, false)
398 398
 	if err != nil {
399 399
 		ctx.Handle(500, "GetMilestones.1: %v", err)
400 400
 		return
401 401
 	}
402
-	ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, -1, true)
402
+	ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, true)
403 403
 	if err != nil {
404 404
 		ctx.Handle(500, "GetMilestones.2: %v", err)
405 405
 		return
@@ -439,7 +439,7 @@ func ViewIssue(ctx *middleware.Context) {
439 439
 
440 440
 	// Get posters.
441 441
 	for i := range comments {
442
-		u, err := models.GetUserById(comments[i].PosterId)
442
+		u, err := models.GetUserByID(comments[i].PosterId)
443 443
 		if err != nil {
444 444
 			ctx.Handle(500, "GetUserById.2: %v", err)
445 445
 			return
@@ -469,7 +469,7 @@ func UpdateIssue(ctx *middleware.Context, form auth.CreateIssueForm) {
469 469
 		return
470 470
 	}
471 471
 
472
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx)
472
+	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, idx)
473 473
 	if err != nil {
474 474
 		if err == models.ErrIssueNotExist {
475 475
 			ctx.Handle(404, "issue.UpdateIssue", err)
@@ -517,7 +517,7 @@ func UpdateIssueLabel(ctx *middleware.Context) {
517 517
 		return
518 518
 	}
519 519
 
520
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx)
520
+	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, idx)
521 521
 	if err != nil {
522 522
 		if err == models.ErrIssueNotExist {
523 523
 			ctx.Handle(404, "issue.UpdateIssueLabel(GetIssueByIndex)", err)
@@ -762,7 +762,7 @@ func Comment(ctx *middleware.Context) {
762 762
 		return
763 763
 	}
764 764
 
765
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, index)
765
+	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, index)
766 766
 	if err != nil {
767 767
 		if err == models.ErrIssueNotExist {
768 768
 			send(404, nil, err)
@@ -820,7 +820,7 @@ func Comment(ctx *middleware.Context) {
820 820
 				cmtType = models.COMMENT_TYPE_REOPEN
821 821
 			}
822 822
 
823
-			if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.ID, 0, 0, cmtType, "", nil); err != nil {
823
+			if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, cmtType, "", nil); err != nil {
824 824
 				send(200, nil, err)
825 825
 				return
826 826
 			}
@@ -836,7 +836,7 @@ func Comment(ctx *middleware.Context) {
836 836
 	if len(content) > 0 || len(ctx.Req.MultipartForm.File["attachments"]) > 0 {
837 837
 		switch ctx.Params(":action") {
838 838
 		case "new":
839
-			if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.ID, 0, 0, models.COMMENT_TYPE_COMMENT, content, nil); err != nil {
839
+			if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, models.COMMENT_TYPE_COMMENT, content, nil); err != nil {
840 840
 				send(500, nil, err)
841 841
 				return
842 842
 			}
@@ -872,7 +872,7 @@ func Comment(ctx *middleware.Context) {
872 872
 		ActEmail:     ctx.User.Email,
873 873
 		OpType:       models.COMMENT_ISSUE,
874 874
 		Content:      fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
875
-		RepoID:       ctx.Repo.Repository.Id,
875
+		RepoID:       ctx.Repo.Repository.ID,
876 876
 		RepoUserName: ctx.Repo.Owner.LowerName,
877 877
 		RepoName:     ctx.Repo.Repository.LowerName,
878 878
 		IsPrivate:    ctx.Repo.Repository.IsPrivate,
@@ -927,7 +927,7 @@ func NewLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
927 927
 	}
928 928
 
929 929
 	l := &models.Label{
930
-		RepoId: ctx.Repo.Repository.Id,
930
+		RepoId: ctx.Repo.Repository.ID,
931 931
 		Name:   form.Title,
932 932
 		Color:  form.Color,
933 933
 	}
@@ -960,7 +960,7 @@ func UpdateLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
960 960
 }
961 961
 
962 962
 func DeleteLabel(ctx *middleware.Context) {
963
-	if err := models.DeleteLabel(ctx.Repo.Repository.Id, ctx.QueryInt64("id")); err != nil {
963
+	if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
964 964
 		ctx.Flash.Error("DeleteLabel: " + err.Error())
965 965
 	} else {
966 966
 		ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
@@ -977,7 +977,7 @@ func Milestones(ctx *middleware.Context) {
977 977
 	ctx.Data["PageIsMilestones"] = true
978 978
 
979 979
 	isShowClosed := ctx.Query("state") == "closed"
980
-	openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.Id)
980
+	openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.ID)
981 981
 	ctx.Data["OpenCount"] = openCount
982 982
 	ctx.Data["ClosedCount"] = closedCount
983 983
 
@@ -994,7 +994,7 @@ func Milestones(ctx *middleware.Context) {
994 994
 	}
995 995
 	ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)
996 996
 
997
-	miles, err := models.GetMilestones(ctx.Repo.Repository.Id, page, isShowClosed)
997
+	miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed)
998 998
 	if err != nil {
999 999
 		ctx.Handle(500, "GetMilestones", err)
1000 1000
 		return
@@ -1043,7 +1043,7 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
1043 1043
 	}
1044 1044
 
1045 1045
 	if err = models.NewMilestone(&models.Milestone{
1046
-		RepoID:   ctx.Repo.Repository.Id,
1046
+		RepoID:   ctx.Repo.Repository.ID,
1047 1047
 		Name:     form.Title,
1048 1048
 		Content:  form.Content,
1049 1049
 		Deadline: deadline,

+ 58 - 7
routers/repo/pull.go

@@ -5,26 +5,31 @@
5 5
 package repo
6 6
 
7 7
 import (
8
+	"fmt"
9
+	"strings"
10
+
8 11
 	"github.com/gogits/gogs/models"
9 12
 	"github.com/gogits/gogs/modules/auth"
10 13
 	"github.com/gogits/gogs/modules/base"
14
+	"github.com/gogits/gogs/modules/git"
11 15
 	"github.com/gogits/gogs/modules/log"
12 16
 	"github.com/gogits/gogs/modules/middleware"
13 17
 	"github.com/gogits/gogs/modules/setting"
14 18
 )
15 19
 
16 20
 const (
17
-	FORK  base.TplName = "repo/pulls/fork"
18
-	PULLS base.TplName = "repo/pulls"
21
+	FORK         base.TplName = "repo/pulls/fork"
22
+	COMPARE_PULL base.TplName = "repo/pulls/compare"
23
+	PULLS        base.TplName = "repo/pulls"
19 24
 )
20 25
 
21 26
 func getForkRepository(ctx *middleware.Context) *models.Repository {
22
-	forkRepo, err := models.GetRepositoryById(ctx.ParamsInt64(":repoid"))
27
+	forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
23 28
 	if err != nil {
24 29
 		if models.IsErrRepoNotExist(err) {
25
-			ctx.Handle(404, "GetRepositoryById", nil)
30
+			ctx.Handle(404, "GetRepositoryByID", nil)
26 31
 		} else {
27
-			ctx.Handle(500, "GetRepositoryById", err)
32
+			ctx.Handle(500, "GetRepositoryByID", err)
28 33
 		}
29 34
 		return nil
30 35
 	}
@@ -78,7 +83,7 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
78 83
 		return
79 84
 	}
80 85
 
81
-	repo, has := models.HasForkedRepo(ctxUser.Id, forkRepo.Id)
86
+	repo, has := models.HasForkedRepo(ctxUser.Id, forkRepo.ID)
82 87
 	if has {
83 88
 		ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
84 89
 		return
@@ -110,10 +115,56 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
110 115
 		return
111 116
 	}
112 117
 
113
-	log.Trace("Repository forked[%d]: %s/%s", forkRepo.Id, ctxUser.Name, repo.Name)
118
+	log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
114 119
 	ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
115 120
 }
116 121
 
122
+func CompareAndPullRequest(ctx *middleware.Context) {
123
+	// Get compare information.
124
+	infos := strings.Split(ctx.Params("*"), "...")
125
+	if len(infos) != 2 {
126
+		ctx.Handle(404, "CompareAndPullRequest", nil)
127
+		return
128
+	}
129
+
130
+	baseBranch := infos[0]
131
+	ctx.Data["BaseBranch"] = baseBranch
132
+
133
+	headInfos := strings.Split(infos[1], ":")
134
+	if len(headInfos) != 2 {
135
+		ctx.Handle(404, "CompareAndPullRequest", nil)
136
+		return
137
+	}
138
+	headUser := headInfos[0]
139
+	headBranch := headInfos[1]
140
+	ctx.Data["HeadBranch"] = headBranch
141
+
142
+	// TODO: check if branches are valid.
143
+	fmt.Println(baseBranch, headUser, headBranch)
144
+
145
+	// TODO: add organization support
146
+	// Check if current user has fork of repository.
147
+	headRepo, has := models.HasForkedRepo(ctx.User.Id, ctx.Repo.Repository.ID)
148
+	if !has {
149
+		ctx.Handle(404, "HasForkedRepo", nil)
150
+		return
151
+	}
152
+
153
+	headGitRepo, err := git.OpenRepository(models.RepoPath(ctx.User.Name, headRepo.Name))
154
+	if err != nil {
155
+		ctx.Handle(500, "OpenRepository", err)
156
+		return
157
+	}
158
+	headBranches, err := headGitRepo.GetBranches()
159
+	if err != nil {
160
+		ctx.Handle(500, "GetBranches", err)
161
+		return
162
+	}
163
+	ctx.Data["HeadBranches"] = headBranches
164
+
165
+	ctx.HTML(200, COMPARE_PULL)
166
+}
167
+
117 168
 func Pulls(ctx *middleware.Context) {
118 169
 	ctx.Data["IsRepoToolbarPulls"] = true
119 170
 	ctx.HTML(200, PULLS)

+ 6 - 6
routers/repo/release.go

@@ -29,7 +29,7 @@ func Releases(ctx *middleware.Context) {
29 29
 		return
30 30
 	}
31 31
 
32
-	rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.Id)
32
+	rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.ID)
33 33
 	if err != nil {
34 34
 		ctx.Handle(500, "GetReleasesByRepoId", err)
35 35
 		return
@@ -45,7 +45,7 @@ func Releases(ctx *middleware.Context) {
45 45
 				continue
46 46
 			}
47 47
 			if rel.TagName == rawTag {
48
-				rel.Publisher, err = models.GetUserById(rel.PublisherId)
48
+				rel.Publisher, err = models.GetUserByID(rel.PublisherId)
49 49
 				if err != nil {
50 50
 					ctx.Handle(500, "GetUserById", err)
51 51
 					return
@@ -105,7 +105,7 @@ func Releases(ctx *middleware.Context) {
105 105
 			continue
106 106
 		}
107 107
 
108
-		rel.Publisher, err = models.GetUserById(rel.PublisherId)
108
+		rel.Publisher, err = models.GetUserByID(rel.PublisherId)
109 109
 		if err != nil {
110 110
 			ctx.Handle(500, "GetUserById", err)
111 111
 			return
@@ -185,7 +185,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
185 185
 	}
186 186
 
187 187
 	rel := &models.Release{
188
-		RepoId:       ctx.Repo.Repository.Id,
188
+		RepoId:       ctx.Repo.Repository.ID,
189 189
 		PublisherId:  ctx.User.Id,
190 190
 		Title:        form.Title,
191 191
 		TagName:      form.TagName,
@@ -217,7 +217,7 @@ func EditRelease(ctx *middleware.Context) {
217 217
 	}
218 218
 
219 219
 	tagName := ctx.Params(":tagname")
220
-	rel, err := models.GetRelease(ctx.Repo.Repository.Id, tagName)
220
+	rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
221 221
 	if err != nil {
222 222
 		if err == models.ErrReleaseNotExist {
223 223
 			ctx.Handle(404, "GetRelease", err)
@@ -240,7 +240,7 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) {
240 240
 	}
241 241
 
242 242
 	tagName := ctx.Params(":tagname")
243
-	rel, err := models.GetRelease(ctx.Repo.Repository.Id, tagName)
243
+	rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
244 244
 	if err != nil {
245 245
 		if err == models.ErrReleaseNotExist {
246 246
 			ctx.Handle(404, "GetRelease", err)

+ 7 - 7
routers/repo/repo.go

@@ -33,7 +33,7 @@ func checkContextUser(ctx *middleware.Context, uid int64) *models.User {
33 33
 		return ctx.User
34 34
 	}
35 35
 
36
-	org, err := models.GetUserById(uid)
36
+	org, err := models.GetUserByID(uid)
37 37
 	if models.IsErrUserNotExist(err) {
38 38
 		return ctx.User
39 39
 	}
@@ -112,7 +112,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
112 112
 	}
113 113
 
114 114
 	if repo != nil {
115
-		if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
115
+		if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID, ctxUser.Name); errDelete != nil {
116 116
 			log.Error(4, "DeleteRepository: %v", errDelete)
117 117
 		}
118 118
 	}
@@ -209,7 +209,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
209 209
 	}
210 210
 
211 211
 	if repo != nil {
212
-		if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
212
+		if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID, ctxUser.Name); errDelete != nil {
213 213
 			log.Error(4, "DeleteRepository: %v", errDelete)
214 214
 		}
215 215
 	}
@@ -239,13 +239,13 @@ func Action(ctx *middleware.Context) {
239 239
 	var err error
240 240
 	switch ctx.Params(":action") {
241 241
 	case "watch":
242
-		err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, true)
242
+		err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.ID, true)
243 243
 	case "unwatch":
244
-		err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, false)
244
+		err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.ID, false)
245 245
 	case "star":
246
-		err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.Id, true)
246
+		err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.ID, true)
247 247
 	case "unstar":
248
-		err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.Id, false)
248
+		err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.ID, false)
249 249
 	case "desc":
250 250
 		if !ctx.Repo.IsOwner() {
251 251
 			ctx.Error(404)

+ 7 - 7
routers/repo/setting.go

@@ -160,7 +160,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
160 160
 			return
161 161
 		}
162 162
 
163
-		if err := models.DeleteRepository(ctx.Repo.Owner.Id, ctx.Repo.Repository.Id, ctx.Repo.Owner.Name); err != nil {
163
+		if err := models.DeleteRepository(ctx.Repo.Owner.Id, ctx.Repo.Repository.ID, ctx.Repo.Owner.Name); err != nil {
164 164
 			ctx.Handle(500, "DeleteRepository", err)
165 165
 			return
166 166
 		}
@@ -262,7 +262,7 @@ func Webhooks(ctx *middleware.Context) {
262 262
 		return
263 263
 	}
264 264
 
265
-	ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id)
265
+	ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID)
266 266
 	if err != nil {
267 267
 		ctx.Handle(500, "GetWebhooksByRepoId", err)
268 268
 		return
@@ -569,7 +569,7 @@ func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) {
569 569
 	if _, ok := ctx.Data["RepoLink"]; ok {
570 570
 		return &OrgRepoCtx{
571 571
 			OrgId:       int64(0),
572
-			RepoId:      ctx.Repo.Repository.Id,
572
+			RepoId:      ctx.Repo.Repository.ID,
573 573
 			Link:        ctx.Repo.RepoLink,
574 574
 			NewTemplate: HOOK_NEW,
575 575
 		}, nil
@@ -605,7 +605,7 @@ func TriggerHook(ctx *middleware.Context) {
605 605
 		}
606 606
 		return
607 607
 	}
608
-	models.HookQueue.AddRepoID(repo.Id)
608
+	models.HookQueue.AddRepoID(repo.ID)
609 609
 }
610 610
 
611 611
 func GitHooks(ctx *middleware.Context) {
@@ -663,7 +663,7 @@ func SettingsDeployKeys(ctx *middleware.Context) {
663 663
 	ctx.Data["Title"] = ctx.Tr("repo.settings")
664 664
 	ctx.Data["PageIsSettingsKeys"] = true
665 665
 
666
-	keys, err := models.ListDeployKeys(ctx.Repo.Repository.Id)
666
+	keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
667 667
 	if err != nil {
668 668
 		ctx.Handle(500, "ListDeployKeys", err)
669 669
 		return
@@ -695,7 +695,7 @@ func SettingsDeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
695 695
 		}
696 696
 	}
697 697
 
698
-	if err = models.AddDeployKey(ctx.Repo.Repository.Id, form.Title, content); err != nil {
698
+	if err = models.AddDeployKey(ctx.Repo.Repository.ID, form.Title, content); err != nil {
699 699
 		ctx.Data["HasError"] = true
700 700
 		switch {
701 701
 		case models.IsErrKeyAlreadyExist(err):
@@ -710,7 +710,7 @@ func SettingsDeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
710 710
 		return
711 711
 	}
712 712
 
713
-	log.Trace("Deploy key added: %d", ctx.Repo.Repository.Id)
713
+	log.Trace("Deploy key added: %d", ctx.Repo.Repository.ID)
714 714
 	ctx.Flash.Success(ctx.Tr("repo.settings.add_key_success", form.Title))
715 715
 	ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys")
716 716
 }

+ 6 - 6
routers/user/home.go

@@ -104,7 +104,7 @@ func Dashboard(ctx *middleware.Context) {
104 104
 	for _, act := range actions {
105 105
 		if act.IsPrivate {
106 106
 			// This prevents having to retrieve the repository for each action
107
-			repo := &models.Repository{Id: act.RepoID, IsPrivate: true}
107
+			repo := &models.Repository{ID: act.RepoID, IsPrivate: true}
108 108
 			if act.RepoUserName != ctx.User.LowerName {
109 109
 				if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
110 110
 					continue
@@ -212,7 +212,7 @@ func Profile(ctx *middleware.Context) {
212 212
 					continue
213 213
 				}
214 214
 				// This prevents having to retrieve the repository for each action
215
-				repo := &models.Repository{Id: act.RepoID, IsPrivate: true}
215
+				repo := &models.Repository{ID: act.RepoID, IsPrivate: true}
216 216
 				if act.RepoUserName != ctx.User.LowerName {
217 217
 					if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
218 218
 						continue
@@ -295,21 +295,21 @@ func Issues(ctx *middleware.Context) {
295 295
 			continue
296 296
 		}
297 297
 
298
-		repoIds = append(repoIds, repo.Id)
298
+		repoIds = append(repoIds, repo.ID)
299 299
 		repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
300 300
 		issueStats.AllCount += int64(repo.NumOpenIssues)
301 301
 
302 302
 		if isShowClosed {
303 303
 			if repo.NumClosedIssues > 0 {
304 304
 				if filterMode == models.FM_CREATE {
305
-					repo.NumClosedIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed))
305
+					repo.NumClosedIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.ID, isShowClosed))
306 306
 				}
307 307
 				showRepos = append(showRepos, repo)
308 308
 			}
309 309
 		} else {
310 310
 			if repo.NumOpenIssues > 0 {
311 311
 				if filterMode == models.FM_CREATE {
312
-					repo.NumOpenIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed))
312
+					repo.NumOpenIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.ID, isShowClosed))
313 313
 				}
314 314
 				showRepos = append(showRepos, repo)
315 315
 			}
@@ -350,7 +350,7 @@ func Issues(ctx *middleware.Context) {
350 350
 			}
351 351
 		}
352 352
 
353
-		issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoID)
353
+		issues[i].Repo, err = models.GetRepositoryByID(issues[i].RepoID)
354 354
 		if err != nil {
355 355
 			if models.IsErrRepoNotExist(err) {
356 356
 				log.Warn("GetRepositoryById[%d]: repository not exist", issues[i].RepoID)

+ 2 - 2
templates/admin/repo/list.tmpl

@@ -17,7 +17,7 @@
17 17
 					                <table class="table table-striped">
18 18
 					                    <thead>
19 19
 					                        <tr>
20
-					                            <th>Id</th>
20
+					                            <th>ID</th>
21 21
 					                            <th>{{.i18n.Tr "admin.repos.owner"}}</th>
22 22
 					                            <th>{{.i18n.Tr "admin.repos.name"}}</th>
23 23
 					                            <th>{{.i18n.Tr "admin.repos.private"}}</th>
@@ -30,7 +30,7 @@
30 30
 					                    <tbody>
31 31
 					                        {{range .Repos}}
32 32
 					                        <tr>
33
-					                            <td>{{.Id}}</td>
33
+					                            <td>{{.ID}}</td>
34 34
 					                            <td><a href="{{AppSubUrl}}/{{.Owner.Name}}">{{.Owner.Name}}</a></td>
35 35
                             					<td><a href="{{AppSubUrl}}/{{.Owner.Name}}/{{.Name}}">{{.Name}}</a></td>
36 36
 					                            <td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>

+ 1 - 1
templates/repo/header.tmpl

@@ -7,7 +7,7 @@
7 7
 	  <div class="divider"> / </div>
8 8
 	  <a href="{{$.RepoLink}}">{{.Name}}</a>
9 9
 	  {{if .IsMirror}}<div class="ui label">{{$.i18n.Tr "mirror"}}</div>{{end}}
10
-	  {{if .IsFork}}<div class="fork-flag">{{$.i18n.Tr "repo.forked_from"}} <a href="{{.ForkRepo.RepoLink}}">{{SubStr .ForkRepo.RepoLink 1 -1}}</a></div>{{end}}
10
+	  {{if .IsFork}}<div class="fork-flag">{{$.i18n.Tr "repo.forked_from"}} <a href="{{.BaseRepo.RepoLink}}">{{SubStr .BaseRepo.RepoLink 1 -1}}</a></div>{{end}}
11 11
 		</div>
12 12
 	</h2>
13 13
 	<div class="ui right floated secondary menu">

+ 2 - 2
templates/repo/header_old.tmpl

@@ -7,7 +7,7 @@
7 7
             <span class="divider">/</span>
8 8
             <a class="repo text-bold" href="{{$.RepoLink}}">{{.Name}}</a>
9 9
             {{if .IsMirror}}<span class="label label-gray">{{$.i18n.Tr "mirror"}}</span>{{end}}
10
-            {{if .IsFork}}<span class="fork-flag">forked from <a href="{{.ForkRepo.RepoLink}}">{{SubStr .ForkRepo.RepoLink 1 -1}}</a></span>{{end}}
10
+            {{if .IsFork}}<span class="fork-flag">forked from <a href="{{.BaseRepo.RepoLink}}">{{SubStr .BaseRepo.RepoLink 1 -1}}</a></span>{{end}}
11 11
         </h1>
12 12
         <ul id="repo-header-meta" class="right menu menu-line">
13 13
             <li id="repo-header-download" class="drop">
@@ -49,7 +49,7 @@
49 49
                 </a>
50 50
             </li>
51 51
             <li id="repo-header-fork">
52
-                <a id="repo-header-fork-btn" {{if or (not $.IsRepositoryAdmin) $.Owner.IsOrganization}}href="{{AppSubUrl}}/repo/fork/{{.Id}}"{{end}}>
52
+                <a id="repo-header-fork-btn" {{if or (not $.IsRepositoryAdmin) $.Owner.IsOrganization}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{end}}>
53 53
                     <button class="btn btn-gray text-bold btn-radius">
54 54
                         <i class="octicon octicon-repo-forked"></i>{{$.i18n.Tr "repo.fork"}}
55 55
                         <span class="num">{{.NumForks}}</span>

+ 6 - 3
templates/repo/home.tmpl

@@ -9,11 +9,14 @@
9 9
                 <a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
10 10
             </p>
11 11
             <ul id="repo-file-nav" class="clear menu menu-line">
12
-                <!-- <li>
13
-                    <a href="#">
12
+                {{if and .IsRepositoryAdmin .Repository.BaseRepo}}
13
+                {{ $baseRepo := .Repository.BaseRepo}}
14
+                <li>
15
+                    <a href="{{AppSubUrl}}/{{$baseRepo.Owner.Name}}/{{$baseRepo.Name}}/compare/{{$.BaseDefaultBranch}}...{{$.Owner.Name}}:{{$.BranchName}}">
14 16
                         <button class="btn btn-green btn-small btn-radius" id="repo-compare-btn"><i class="octicon octicon-git-compare"></i></button>
15 17
                     </a>
16
-                </li> -->
18
+                </li>
19
+                {{end}}
17 20
                 <li id="repo-branch-switch" class="down drop">
18 21
                     <a>
19 22
                         <button class="btn btn-gray btn-medium btn-radius">

+ 51 - 0
templates/repo/pulls/compare.tmpl

@@ -0,0 +1,51 @@
1
+{{template "base/head" .}}
2
+<div class="repository compare pull">
3
+	{{template "repo/header" .}}
4
+	<div class="ui middle page grid body">
5
+		<div class="sixteen wide column page grid">
6
+			<h2 class="ui header">
7
+			  {{.i18n.Tr "repo.pulls.compare_changes"}}
8
+			  <div class="sub header">{{.i18n.Tr "repo.pulls.compare_changes_desc"}}</div>
9
+			</h2>
10
+			<div class="ui segment choose branch">
11
+				<span class="octicon octicon-git-compare"></span>
12
+				<div class="ui floating filter dropdown">
13
+					<div class="ui basic small button">
14
+				    <span class="text">base: {{$.BaseBranch}}</span>
15
+					  <i class="dropdown icon"></i>
16
+					</div>
17
+	        <div class="menu">
18
+		        <div class="ui icon search input">
19
+	            <i class="filter icon"></i>
20
+	            <input name="search" placeholder="Filter branch...">
21
+	          </div>
22
+	          <div class="items">
23
+		        	{{range .Branches}}
24
+		          <a class="{{if eq $.BaseBranch .}}active selected{{end}} item" href="{{$.RepoLink}}/compare/{{.}}...{{$.SignedUser.Name}}:{{$.HeadBranch}}">{{.}}</a>
25
+		        	{{end}}
26
+	          </div>
27
+					</div>
28
+			 	</div>
29
+			 	...
30
+				<div class="ui floating filter dropdown">
31
+					<div class="ui basic small button">
32
+				    <span class="text">compare: {{$.HeadBranch}}</span>
33
+					  <i class="dropdown icon"></i>
34
+					</div>
35
+	        <div class="menu">
36
+		        <div class="ui icon search input">
37
+	            <i class="filter icon"></i>
38
+	            <input name="search" placeholder="Filter branch...">
39
+	          </div>
40
+	          <div class="items">
41
+		        	{{range .HeadBranches}}
42
+		          <a class="{{if eq $.HeadBranch .}}active selected{{end}} item" href="{{$.RepoLink}}/compare/{{$.BaseBranch}}...{{$.SignedUser.Name}}:{{.}}">{{.}}</a>
43
+		        	{{end}}
44
+	        	</div>
45
+					</div>
46
+			 	</div>
47
+			</div>
48
+		</div>
49
+	</div>
50
+</div>
51
+{{template "base/footer" .}}