Skip to content

Commit

Permalink
Merge branch 'main' into punit/Showing-archive-label-issue-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
puni9869 authored Sep 17, 2023
2 parents c9516ed + 47b8788 commit 3682eb8
Show file tree
Hide file tree
Showing 37 changed files with 593 additions and 124 deletions.
38 changes: 38 additions & 0 deletions docs/content/usage/blame.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
date: "2023-08-14T00:00:00+00:00"
title: "Blame File View"
slug: "blame"
sidebar_position: 13
toc: false
draft: false
aliases:
- /en-us/blame
menu:
sidebar:
parent: "usage"
name: "Blame"
sidebar_position: 13
identifier: "blame"
---

# Blame File View

Gitea supports viewing the line-by-line revision history for a file also known as blame view.
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.

1. Navigate to and open the file whose line history you want to view.
1. Click the `Blame` button in the file header bar.
1. The new view shows the line-by-line revision history for a file with author and commit information on the left side.
1. To navigate to an older commit, click the ![versions](/octicon-versions.svg) icon.

## Ignore commits in the blame view

All revisions specified in the `.git-blame-ignore-revs` file are hidden from the blame view.
This is especially useful to hide reformatting changes and keep the benefits of `git blame`.
Lines that were changed or added by an ignored commit will be blamed on the previous commit that changed that line or nearby lines.
The `.git-blame-ignore-revs` file must be located in the root directory of the repository.
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).

### Bypassing `.git-blame-ignore-revs` in the blame view

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`.
1 change: 1 addition & 0 deletions docs/static/octicon-versions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions models/git/branch_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type FindBranchOptions struct {
ExcludeBranchNames []string
IsDeletedBranch util.OptionalBool
OrderBy string
Keyword string
}

func (opts *FindBranchOptions) Cond() builder.Cond {
Expand All @@ -84,6 +85,9 @@ func (opts *FindBranchOptions) Cond() builder.Cond {
if !opts.IsDeletedBranch.IsNone() {
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
}
if opts.Keyword != "" {
cond = cond.And(builder.Like{"name", opts.Keyword})
}
return cond
}

Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ var migrations = []Migration{
NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable),
// v275 -> v276
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
// v276 -> v277
NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors),
}

// GetCurrentDBVersion returns the current db version
Expand Down
184 changes: 184 additions & 0 deletions models/migrations/v1_21/v276.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint

import (
"context"
"fmt"
"path/filepath"
"strings"

"code.gitea.io/gitea/modules/git"
giturl "code.gitea.io/gitea/modules/git/url"
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
)

func AddRemoteAddressToMirrors(x *xorm.Engine) error {
type Mirror struct {
RemoteAddress string `xorm:"VARCHAR(2048)"`
}

type PushMirror struct {
RemoteAddress string `xorm:"VARCHAR(2048)"`
}

if err := x.Sync(new(Mirror), new(PushMirror)); err != nil {
return err
}

if err := migratePullMirrors(x); err != nil {
return err
}

return migratePushMirrors(x)
}

func migratePullMirrors(x *xorm.Engine) error {
type Mirror struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
RemoteAddress string `xorm:"VARCHAR(2048)"`
}

sess := x.NewSession()
defer sess.Close()

if err := sess.Begin(); err != nil {
return err
}

limit := setting.Database.IterateBufferSize
if limit <= 0 {
limit = 50
}

start := 0

for {
var mirrors []Mirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
return err
}

if len(mirrors) == 0 {
break
}
start += len(mirrors)

for _, m := range mirrors {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin")
if err != nil {
return err
}

m.RemoteAddress = remoteAddress

if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
return err
}
}

if start%1000 == 0 { // avoid a too big transaction
if err := sess.Commit(); err != nil {
return err
}
if err := sess.Begin(); err != nil {
return err
}
}
}

return sess.Commit()
}

func migratePushMirrors(x *xorm.Engine) error {
type PushMirror struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
RemoteName string
RemoteAddress string `xorm:"VARCHAR(2048)"`
}

sess := x.NewSession()
defer sess.Close()

if err := sess.Begin(); err != nil {
return err
}

limit := setting.Database.IterateBufferSize
if limit <= 0 {
limit = 50
}

start := 0

for {
var mirrors []PushMirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
return err
}

if len(mirrors) == 0 {
break
}
start += len(mirrors)

for _, m := range mirrors {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName)
if err != nil {
return err
}

m.RemoteAddress = remoteAddress

if _, err = sess.ID(m.ID).Cols("remote_address").Update(m); err != nil {
return err
}
}

if start%1000 == 0 { // avoid a too big transaction
if err := sess.Commit(); err != nil {
return err
}
if err := sess.Begin(); err != nil {
return err
}
}
}

return sess.Commit()
}

func getRemoteAddress(sess *xorm.Session, repoID int64, remoteName string) (string, error) {
var ownerName string
var repoName string
has, err := sess.
Table("repository").
Cols("owner_name", "lower_name").
Where("id=?", repoID).
Get(&ownerName, &repoName)
if err != nil {
return "", err
} else if !has {
return "", fmt.Errorf("repository [%v] not found", repoID)
}

repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git")

remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName)
if err != nil {
return "", err
}

u, err := giturl.Parse(remoteURL)
if err != nil {
return "", err
}
u.User = nil

return u.String(), nil
}
2 changes: 1 addition & 1 deletion models/repo/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Mirror struct {
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`

Address string `xorm:"-"`
RemoteAddress string `xorm:"VARCHAR(2048)"`
}

func init() {
Expand Down
10 changes: 6 additions & 4 deletions models/repo/pushmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ var ErrPushMirrorNotExist = util.NewNotExistErrorf("PushMirror does not exist")

// PushMirror represents mirror information of a repository.
type PushMirror struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
Repo *Repository `xorm:"-"`
RemoteName string
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
Repo *Repository `xorm:"-"`
RemoteName string
RemoteAddress string `xorm:"VARCHAR(2048)"`

SyncOnCommit bool `xorm:"NOT NULL DEFAULT true"`
Interval time.Duration
CreatedUnix timeutil.TimeStamp `xorm:"created"`
LastUpdateUnix timeutil.TimeStamp `xorm:"INDEX last_update"`
LastError string `xorm:"text"`
}

type PushMirrorOptions struct {
ID int64
RepoID int64
Expand Down
8 changes: 2 additions & 6 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,8 @@ func (repo *Repository) SanitizedOriginalURL() string {
if repo.OriginalURL == "" {
return ""
}
u, err := url.Parse(repo.OriginalURL)
if err != nil {
return ""
}
u.User = nil
return u.String()
u, _ := util.SanitizeURL(repo.OriginalURL)
return u
}

// text representations to be returned in SizeDetail.Name
Expand Down
Loading

0 comments on commit 3682eb8

Please sign in to comment.