Skip to content

Commit 3682eb8

Browse files
authored
Merge branch 'main' into punit/Showing-archive-label-issue-filter
2 parents c9516ed + 47b8788 commit 3682eb8

37 files changed

+593
-124
lines changed

docs/content/usage/blame.en-us.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
date: "2023-08-14T00:00:00+00:00"
3+
title: "Blame File View"
4+
slug: "blame"
5+
sidebar_position: 13
6+
toc: false
7+
draft: false
8+
aliases:
9+
- /en-us/blame
10+
menu:
11+
sidebar:
12+
parent: "usage"
13+
name: "Blame"
14+
sidebar_position: 13
15+
identifier: "blame"
16+
---
17+
18+
# Blame File View
19+
20+
Gitea supports viewing the line-by-line revision history for a file also known as blame view.
21+
You can also use [`git blame`](https://git-scm.com/docs/git-blame) on the command line to view the revision history of lines within a file.
22+
23+
1. Navigate to and open the file whose line history you want to view.
24+
1. Click the `Blame` button in the file header bar.
25+
1. The new view shows the line-by-line revision history for a file with author and commit information on the left side.
26+
1. To navigate to an older commit, click the ![versions](/octicon-versions.svg) icon.
27+
28+
## Ignore commits in the blame view
29+
30+
All revisions specified in the `.git-blame-ignore-revs` file are hidden from the blame view.
31+
This is especially useful to hide reformatting changes and keep the benefits of `git blame`.
32+
Lines that were changed or added by an ignored commit will be blamed on the previous commit that changed that line or nearby lines.
33+
The `.git-blame-ignore-revs` file must be located in the root directory of the repository.
34+
For more information like the file format, see [the `git blame --ignore-revs-file` documentation](https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt).
35+
36+
### Bypassing `.git-blame-ignore-revs` in the blame view
37+
38+
If the blame view for a file shows a message about ignored revisions, you can see the normal blame view by appending the url parameter `?bypass-blame-ignore=true`.

docs/static/octicon-versions.svg

Lines changed: 1 addition & 0 deletions
Loading

models/git/branch_list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type FindBranchOptions struct {
7070
ExcludeBranchNames []string
7171
IsDeletedBranch util.OptionalBool
7272
OrderBy string
73+
Keyword string
7374
}
7475

7576
func (opts *FindBranchOptions) Cond() builder.Cond {
@@ -84,6 +85,9 @@ func (opts *FindBranchOptions) Cond() builder.Cond {
8485
if !opts.IsDeletedBranch.IsNone() {
8586
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
8687
}
88+
if opts.Keyword != "" {
89+
cond = cond.And(builder.Like{"name", opts.Keyword})
90+
}
8791
return cond
8892
}
8993

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ var migrations = []Migration{
532532
NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable),
533533
// v275 -> v276
534534
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
535+
// v276 -> v277
536+
NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors),
535537
}
536538

537539
// GetCurrentDBVersion returns the current db version

models/migrations/v1_21/v276.go

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_21 //nolint
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"path/filepath"
10+
"strings"
11+
12+
"code.gitea.io/gitea/modules/git"
13+
giturl "code.gitea.io/gitea/modules/git/url"
14+
"code.gitea.io/gitea/modules/setting"
15+
16+
"xorm.io/xorm"
17+
)
18+
19+
func AddRemoteAddressToMirrors(x *xorm.Engine) error {
20+
type Mirror struct {
21+
RemoteAddress string `xorm:"VARCHAR(2048)"`
22+
}
23+
24+
type PushMirror struct {
25+
RemoteAddress string `xorm:"VARCHAR(2048)"`
26+
}
27+
28+
if err := x.Sync(new(Mirror), new(PushMirror)); err != nil {
29+
return err
30+
}
31+
32+
if err := migratePullMirrors(x); err != nil {
33+
return err
34+
}
35+
36+
return migratePushMirrors(x)
37+
}
38+
39+
func migratePullMirrors(x *xorm.Engine) error {
40+
type Mirror struct {
41+
ID int64 `xorm:"pk autoincr"`
42+
RepoID int64 `xorm:"INDEX"`
43+
RemoteAddress string `xorm:"VARCHAR(2048)"`
44+
}
45+
46+
sess := x.NewSession()
47+
defer sess.Close()
48+
49+
if err := sess.Begin(); err != nil {
50+
return err
51+
}
52+
53+
limit := setting.Database.IterateBufferSize
54+
if limit <= 0 {
55+
limit = 50
56+
}
57+
58+
start := 0
59+
60+
for {
61+
var mirrors []Mirror
62+
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
63+
return err
64+
}
65+
66+
if len(mirrors) == 0 {
67+
break
68+
}
69+
start += len(mirrors)
70+
71+
for _, m := range mirrors {
72+
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin")
73+
if err != nil {
74+
return err
75+
}
76+
77+
m.RemoteAddress = remoteAddress
78+
79+
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
80+
return err
81+
}
82+
}
83+
84+
if start%1000 == 0 { // avoid a too big transaction
85+
if err := sess.Commit(); err != nil {
86+
return err
87+
}
88+
if err := sess.Begin(); err != nil {
89+
return err
90+
}
91+
}
92+
}
93+
94+
return sess.Commit()
95+
}
96+
97+
func migratePushMirrors(x *xorm.Engine) error {
98+
type PushMirror struct {
99+
ID int64 `xorm:"pk autoincr"`
100+
RepoID int64 `xorm:"INDEX"`
101+
RemoteName string
102+
RemoteAddress string `xorm:"VARCHAR(2048)"`
103+
}
104+
105+
sess := x.NewSession()
106+
defer sess.Close()
107+
108+
if err := sess.Begin(); err != nil {
109+
return err
110+
}
111+
112+
limit := setting.Database.IterateBufferSize
113+
if limit <= 0 {
114+
limit = 50
115+
}
116+
117+
start := 0
118+
119+
for {
120+
var mirrors []PushMirror
121+
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
122+
return err
123+
}
124+
125+
if len(mirrors) == 0 {
126+
break
127+
}
128+
start += len(mirrors)
129+
130+
for _, m := range mirrors {
131+
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName)
132+
if err != nil {
133+
return err
134+
}
135+
136+
m.RemoteAddress = remoteAddress
137+
138+
if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
139+
return err
140+
}
141+
}
142+
143+
if start%1000 == 0 { // avoid a too big transaction
144+
if err := sess.Commit(); err != nil {
145+
return err
146+
}
147+
if err := sess.Begin(); err != nil {
148+
return err
149+
}
150+
}
151+
}
152+
153+
return sess.Commit()
154+
}
155+
156+
func getRemoteAddress(sess *xorm.Session, repoID int64, remoteName string) (string, error) {
157+
var ownerName string
158+
var repoName string
159+
has, err := sess.
160+
Table("repository").
161+
Cols("owner_name", "lower_name").
162+
Where("id=?", repoID).
163+
Get(&ownerName, &repoName)
164+
if err != nil {
165+
return "", err
166+
} else if !has {
167+
return "", fmt.Errorf("repository [%v] not found", repoID)
168+
}
169+
170+
repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git")
171+
172+
remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName)
173+
if err != nil {
174+
return "", err
175+
}
176+
177+
u, err := giturl.Parse(remoteURL)
178+
if err != nil {
179+
return "", err
180+
}
181+
u.User = nil
182+
183+
return u.String(), nil
184+
}

models/repo/mirror.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Mirror struct {
3131
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
3232
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
3333

34-
Address string `xorm:"-"`
34+
RemoteAddress string `xorm:"VARCHAR(2048)"`
3535
}
3636

3737
func init() {

models/repo/pushmirror.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ var ErrPushMirrorNotExist = util.NewNotExistErrorf("PushMirror does not exist")
2020

2121
// PushMirror represents mirror information of a repository.
2222
type PushMirror struct {
23-
ID int64 `xorm:"pk autoincr"`
24-
RepoID int64 `xorm:"INDEX"`
25-
Repo *Repository `xorm:"-"`
26-
RemoteName string
23+
ID int64 `xorm:"pk autoincr"`
24+
RepoID int64 `xorm:"INDEX"`
25+
Repo *Repository `xorm:"-"`
26+
RemoteName string
27+
RemoteAddress string `xorm:"VARCHAR(2048)"`
2728

2829
SyncOnCommit bool `xorm:"NOT NULL DEFAULT true"`
2930
Interval time.Duration
3031
CreatedUnix timeutil.TimeStamp `xorm:"created"`
3132
LastUpdateUnix timeutil.TimeStamp `xorm:"INDEX last_update"`
3233
LastError string `xorm:"text"`
3334
}
35+
3436
type PushMirrorOptions struct {
3537
ID int64
3638
RepoID int64

models/repo/repo.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,8 @@ func (repo *Repository) SanitizedOriginalURL() string {
191191
if repo.OriginalURL == "" {
192192
return ""
193193
}
194-
u, err := url.Parse(repo.OriginalURL)
195-
if err != nil {
196-
return ""
197-
}
198-
u.User = nil
199-
return u.String()
194+
u, _ := util.SanitizeURL(repo.OriginalURL)
195+
return u
200196
}
201197

202198
// text representations to be returned in SizeDetail.Name

0 commit comments

Comments
 (0)