From 19028303b1810e3eef61614ea267ebd05d17b918 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Thu, 5 Jun 2025 15:42:43 +0000
Subject: [PATCH 01/14] Use git log instead of git rev-list
---
modules/git/repo_commit.go | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 4066a1ca7ba1f..9a59994c25fdc 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -6,6 +6,7 @@ package git
import (
"bytes"
+ "fmt"
"io"
"os"
"strconv"
@@ -232,7 +233,9 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
go func() {
stderr := strings.Builder{}
- gitCmd := NewCommand("rev-list").
+ gitCmd := NewCommand(repo.Ctx, "--no-pager", "log").
+ AddOptionFormat("--follow").
+ AddOptionFormat("--pretty=format:%%H").
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
gitCmd.AddDynamicArguments(opts.Revision)
@@ -248,12 +251,15 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}
gitCmd.AddDashesAndList(opts.File)
+ fmt.Print(gitCmd)
+ fmt.Fprint(os.Stdout, "")
err := gitCmd.Run(repo.Ctx, &RunOpts{
Dir: repo.Path,
Stdout: stdoutWriter,
Stderr: &stderr,
})
- if err != nil {
+ fmt.Print("1 ", err)
+ if err != nil && err != io.ErrUnexpectedEOF {
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
} else {
_ = stdoutWriter.Close()
@@ -261,6 +267,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
objectFormat, err := repo.GetObjectFormat()
+ fmt.Print("object", err)
if err != nil {
return nil, err
}
@@ -270,8 +277,9 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
shaline := make([]byte, length+1)
for {
n, err := io.ReadFull(stdoutReader, shaline)
+ fmt.Print("io", err)
if err != nil || n < length {
- if err == io.EOF {
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
err = nil
}
return commits, err
From 22f63d918f4e68429e8b28d1f5b5ee8fe153922b Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 10:04:01 +0000
Subject: [PATCH 02/14] Fix last commit discarded
---
modules/git/repo_commit.go | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 9a59994c25fdc..99a3db8276bf7 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -6,7 +6,6 @@ package git
import (
"bytes"
- "fmt"
"io"
"os"
"strconv"
@@ -251,14 +250,11 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}
gitCmd.AddDashesAndList(opts.File)
- fmt.Print(gitCmd)
- fmt.Fprint(os.Stdout, "")
err := gitCmd.Run(repo.Ctx, &RunOpts{
Dir: repo.Path,
Stdout: stdoutWriter,
Stderr: &stderr,
})
- fmt.Print("1 ", err)
if err != nil && err != io.ErrUnexpectedEOF {
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
} else {
@@ -267,7 +263,6 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
objectFormat, err := repo.GetObjectFormat()
- fmt.Print("object", err)
if err != nil {
return nil, err
}
@@ -277,9 +272,8 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
shaline := make([]byte, length+1)
for {
n, err := io.ReadFull(stdoutReader, shaline)
- fmt.Print("io", err)
- if err != nil || n < length {
- if err == io.EOF || err == io.ErrUnexpectedEOF {
+ if (err != nil && err != io.ErrUnexpectedEOF) || n < length {
+ if err == io.EOF {
err = nil
}
return commits, err
From 88d70d305b371fc0c2e9cac05187b539717890dc Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 10:04:44 +0000
Subject: [PATCH 03/14] Fixed commit count
---
modules/git/commit.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 1c1648eb8b85f..54898e6dc05f4 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -172,7 +172,7 @@ type CommitsCountOptions struct {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
- cmd := NewCommand("rev-list", "--count")
+ cmd := NewCommand(ctx, "--no-pager", "log", "--pretty=format:%H")
cmd.AddDynamicArguments(opts.Revision...)
@@ -181,6 +181,7 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
}
if len(opts.RelPath) > 0 {
+ cmd.AddOptionValues("--follow")
cmd.AddDashesAndList(opts.RelPath...)
}
@@ -188,8 +189,7 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
if err != nil {
return 0, err
}
-
- return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
+ return int64(len(strings.Split(stdout, "\n"))), nil
}
// CommitsCount returns number of total commits of until current revision.
From 8de55d67c1a643127268bda03621aa2df252dda0 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 17:25:06 +0200
Subject: [PATCH 04/14] Added checkbox to follow renames in history
---
modules/git/commit.go | 17 +++++++++-------
modules/git/repo_commit.go | 31 +++++++++++++++++++-----------
routers/web/repo/commit.go | 11 +++++++----
templates/repo/commits_table.tmpl | 4 ++++
web_src/js/features/repo-commit.ts | 24 +++++++++++++++++++++++
5 files changed, 65 insertions(+), 22 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 54898e6dc05f4..289e35951d000 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -162,12 +162,13 @@ func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, file
// CommitsCountOptions the options when counting commits
type CommitsCountOptions struct {
- RepoPath string
- Not string
- Revision []string
- RelPath []string
- Since string
- Until string
+ RepoPath string
+ Not string
+ Revision []string
+ RelPath []string
+ Since string
+ Until string
+ FollowRename bool
}
// CommitsCount returns number of total commits of until given revision.
@@ -181,7 +182,9 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
}
if len(opts.RelPath) > 0 {
- cmd.AddOptionValues("--follow")
+ if opts.FollowRename {
+ cmd.AddOptionValues("--follow")
+ }
cmd.AddDashesAndList(opts.RelPath...)
}
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 99a3db8276bf7..61662e8053788 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -205,22 +205,29 @@ func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bo
}
// FileCommitsCount return the number of files at a revision
-func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
+func (repo *Repository) FileCommitsCount(revision, file string, followRename ...bool) (int64, error) {
+ _followRename := false
+ if len(followRename) > 0 {
+ _followRename = followRename[0]
+ }
+
return CommitsCount(repo.Ctx,
CommitsCountOptions{
- RepoPath: repo.Path,
- Revision: []string{revision},
- RelPath: []string{file},
+ RepoPath: repo.Path,
+ Revision: []string{revision},
+ RelPath: []string{file},
+ FollowRename: _followRename,
})
}
type CommitsByFileAndRangeOptions struct {
- Revision string
- File string
- Not string
- Page int
- Since string
- Until string
+ Revision string
+ File string
+ Not string
+ Page int
+ Since string
+ Until string
+ FollowRename bool
}
// CommitsByFileAndRange return the commits according revision file and the page
@@ -233,10 +240,12 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
go func() {
stderr := strings.Builder{}
gitCmd := NewCommand(repo.Ctx, "--no-pager", "log").
- AddOptionFormat("--follow").
AddOptionFormat("--pretty=format:%%H").
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
+ if opts.FollowRename {
+ gitCmd.AddOptionValues("--follow")
+ }
gitCmd.AddDynamicArguments(opts.Revision)
if opts.Not != "" {
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index b3af138461c01..5a57d64496215 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -213,12 +213,14 @@ func SearchCommits(ctx *context.Context) {
// FileHistory show a file's reversions
func FileHistory(ctx *context.Context) {
+ followRename := strings.Contains(ctx.Req.RequestURI, "history_follow_rename=true")
+
if ctx.Repo.TreePath == "" {
Commits(ctx)
return
}
- commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefFullName.ShortName(), ctx.Repo.TreePath)
+ commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefFullName.ShortName(), ctx.Repo.TreePath, followRename)
if err != nil {
ctx.ServerError("FileCommitsCount", err)
return
@@ -231,9 +233,10 @@ func FileHistory(ctx *context.Context) {
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
git.CommitsByFileAndRangeOptions{
- Revision: ctx.Repo.RefFullName.ShortName(), // FIXME: legacy code used ShortName
- File: ctx.Repo.TreePath,
- Page: page,
+ Revision: ctx.Repo.RefFullName.ShortName(), // FIXME: legacy code used ShortName
+ File: ctx.Repo.TreePath,
+ Page: page,
+ FollowRename: followRename,
})
if err != nil {
ctx.ServerError("CommitsByFileAndRange", err)
diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl
index a0c5eacdd4b00..7cf5106192625 100644
--- a/templates/repo/commits_table.tmpl
+++ b/templates/repo/commits_table.tmpl
@@ -8,6 +8,10 @@
{{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}}
{{end}}
+
+
+
+
{{if .IsDiffCompare}}
{{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}}
diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts
index 98ec2328ec5f4..4c473d04e9999 100644
--- a/web_src/js/features/repo-commit.ts
+++ b/web_src/js/features/repo-commit.ts
@@ -1,6 +1,7 @@
import {createTippy} from '../modules/tippy.ts';
import {toggleElem} from '../utils/dom.ts';
import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts';
+import $ from 'jquery';
export function initRepoEllipsisButton() {
registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => {
@@ -24,3 +25,26 @@ export function initCommitStatuses() {
});
});
}
+
+window.addEventListener("DOMContentLoaded", function () {
+ console.log("hello");
+ $("input[name=history-enable-follow-renames]").prop("checked", location.toString().includes("history_follow_rename=true"))
+})
+
+$("input[name=history-enable-follow-renames]").on("change", function() {
+ const checked = $(this).is(":checked");
+ let url = location.toString();
+
+ url = url.replaceAll(/history_follow_rename=(true|false)&*/g, "");
+ if (url.slice(-1) === '?') {
+ url = url.slice(0, url.length - 1);
+ }
+ if (url.includes("?")) {
+ url += "&";
+ } else {
+ url += "?";
+ }
+
+ url += `history_follow_rename=${checked}`;
+ window.location.href = url;
+})
From 8c9518c130f96480570e1ed3cdf02f2dd8b65146 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 17:54:59 +0200
Subject: [PATCH 05/14] Fixed command creation
---
modules/git/commit.go | 2 +-
modules/git/repo_commit.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 289e35951d000..47e19d301dd23 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -173,7 +173,7 @@ type CommitsCountOptions struct {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
- cmd := NewCommand(ctx, "--no-pager", "log", "--pretty=format:%H")
+ cmd := NewCommand("--no-pager", "log", "--pretty=format:%H")
cmd.AddDynamicArguments(opts.Revision...)
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 61662e8053788..6cdcab7d6db76 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -239,7 +239,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
go func() {
stderr := strings.Builder{}
- gitCmd := NewCommand(repo.Ctx, "--no-pager", "log").
+ gitCmd := NewCommand("--no-pager", "log").
AddOptionFormat("--pretty=format:%%H").
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
From 5684f5e7077f5e48a0c1cc22f633c40cdfd07948 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 21:38:07 +0200
Subject: [PATCH 06/14] Localized history follow rename checkbox
---
options/locale/locale_en-US.ini | 1 +
templates/repo/commits_table.tmpl | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 78ffe1c61846f..7b250ff2bef4b 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1408,6 +1408,7 @@ editor.fork_branch_exists = Branch "%s" already exists in your fork, please choo
commits.desc = Browse source code change history.
commits.commits = Commits
+commits.history_follow_rename = Include renames
commits.no_commits = No commits in common. "%s" and "%s" have entirely different histories.
commits.nothing_to_compare = These branches are equal.
commits.search.tooltip = You can prefix keywords with "author:", "committer:", "after:", or "before:", e.g. "revert author:Alice before:2019-01-13".
diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl
index 7cf5106192625..aa9e7ebcc64d5 100644
--- a/templates/repo/commits_table.tmpl
+++ b/templates/repo/commits_table.tmpl
@@ -10,7 +10,7 @@
-
+
{{if .IsDiffCompare}}
From 6c62a513e88077992b3d4330c03cfadc64df7544 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 22:28:47 +0200
Subject: [PATCH 07/14] Add small spacing between checkbox and label
---
templates/repo/commits_table.tmpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl
index aa9e7ebcc64d5..6ffe25a56dcab 100644
--- a/templates/repo/commits_table.tmpl
+++ b/templates/repo/commits_table.tmpl
@@ -9,7 +9,7 @@
{{end}}
-
+
{{if .IsDiffCompare}}
From 8cef3d3217b5673c6ced8de2a08ddb93c4a6143c Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Tue, 10 Jun 2025 23:07:08 +0200
Subject: [PATCH 08/14] Fixed linting
---
web_src/js/features/repo-commit.ts | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts
index 4c473d04e9999..eb430d27f4dd1 100644
--- a/web_src/js/features/repo-commit.ts
+++ b/web_src/js/features/repo-commit.ts
@@ -26,25 +26,24 @@ export function initCommitStatuses() {
});
}
-window.addEventListener("DOMContentLoaded", function () {
- console.log("hello");
- $("input[name=history-enable-follow-renames]").prop("checked", location.toString().includes("history_follow_rename=true"))
-})
+window.addEventListener('DOMContentLoaded', () => {
+ ($('input[name=history-enable-follow-renames]')[0] as HTMLInputElement).checked = location.toString().includes('history_follow_rename=true');
+});
-$("input[name=history-enable-follow-renames]").on("change", function() {
- const checked = $(this).is(":checked");
+$('input[name=history-enable-follow-renames]').on('change', function() {
+ const checked = ($(this)[0] as HTMLInputElement).matches(':checked');
let url = location.toString();
- url = url.replaceAll(/history_follow_rename=(true|false)&*/g, "");
- if (url.slice(-1) === '?') {
- url = url.slice(0, url.length - 1);
+ url = url.replaceAll(/history_follow_rename=(true|false)&*/g, '');
+ if (url.endsWith('?')) {
+ url = url.slice(0, -1);
}
- if (url.includes("?")) {
- url += "&";
+ if (url.includes('?')) {
+ url += '&';
} else {
- url += "?";
+ url += '?';
}
url += `history_follow_rename=${checked}`;
window.location.href = url;
-})
+});
From bb6778500f5be44ca8bb4ae58fcb77004998ad95 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 09:45:58 +0200
Subject: [PATCH 09/14] Removed jquery
---
web_src/js/features/repo-commit.ts | 41 ++++++++++++++++--------------
web_src/js/index.ts | 3 ++-
2 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts
index eb430d27f4dd1..4fce931753602 100644
--- a/web_src/js/features/repo-commit.ts
+++ b/web_src/js/features/repo-commit.ts
@@ -1,7 +1,6 @@
import {createTippy} from '../modules/tippy.ts';
import {toggleElem} from '../utils/dom.ts';
import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts';
-import $ from 'jquery';
export function initRepoEllipsisButton() {
registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => {
@@ -26,24 +25,28 @@ export function initCommitStatuses() {
});
}
-window.addEventListener('DOMContentLoaded', () => {
- ($('input[name=history-enable-follow-renames]')[0] as HTMLInputElement).checked = location.toString().includes('history_follow_rename=true');
-});
+export function initCommitFileHistoryFollowRename() {
+ const checkbox : HTMLInputElement | null = document.querySelector('input[name=history-enable-follow-renames]');
-$('input[name=history-enable-follow-renames]').on('change', function() {
- const checked = ($(this)[0] as HTMLInputElement).matches(':checked');
- let url = location.toString();
-
- url = url.replaceAll(/history_follow_rename=(true|false)&*/g, '');
- if (url.endsWith('?')) {
- url = url.slice(0, -1);
- }
- if (url.includes('?')) {
- url += '&';
- } else {
- url += '?';
+ if (!checkbox) {
+ return;
}
+ checkbox.checked = location.toString().includes('history_follow_rename=true');
+
+ checkbox.addEventListener('change', () => {
+ let url = location.toString();
- url += `history_follow_rename=${checked}`;
- window.location.href = url;
-});
+ url = url.replaceAll(/history_follow_rename=(true|false)&*/g, '');
+ if (url.endsWith('?')) {
+ url = url.slice(0, -1);
+ }
+ if (url.includes('?')) {
+ url += '&';
+ } else {
+ url += '?';
+ }
+
+ url += `history_follow_rename=${checkbox.checked}`;
+ window.location.href = url;
+ });
+}
diff --git a/web_src/js/index.ts b/web_src/js/index.ts
index 7e84773bc18fa..603d2718fdc0f 100644
--- a/web_src/js/index.ts
+++ b/web_src/js/index.ts
@@ -22,7 +22,7 @@ import {initMarkupContent} from './markup/content.ts';
import {initPdfViewer} from './render/pdf.ts';
import {initUserAuthOauth2, initUserCheckAppUrl} from './features/user-auth.ts';
import {initRepoPullRequestAllowMaintainerEdit, initRepoPullRequestReview, initRepoIssueSidebarDependency, initRepoIssueFilterItemLabel} from './features/repo-issue.ts';
-import {initRepoEllipsisButton, initCommitStatuses} from './features/repo-commit.ts';
+import {initRepoEllipsisButton, initCommitStatuses, initCommitFileHistoryFollowRename} from './features/repo-commit.ts';
import {initRepoTopicBar} from './features/repo-home.ts';
import {initAdminCommon} from './features/admin/common.ts';
import {initRepoCodeView} from './features/repo-code.ts';
@@ -151,6 +151,7 @@ onDomReady(() => {
initRepoRecentCommits,
initCommitStatuses,
+ initCommitFileHistoryFollowRename,
initCaptcha,
initUserCheckAppUrl,
From 2acc230cf091bc81c26b5f209ba818030539ce91 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 10:36:16 +0200
Subject: [PATCH 10/14] Updated URL search params manipulation
---
web_src/js/features/repo-commit.ts | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts
index 4fce931753602..3a481229e3301 100644
--- a/web_src/js/features/repo-commit.ts
+++ b/web_src/js/features/repo-commit.ts
@@ -31,22 +31,13 @@ export function initCommitFileHistoryFollowRename() {
if (!checkbox) {
return;
}
- checkbox.checked = location.toString().includes('history_follow_rename=true');
+ const url = new URL(window.location.toString());
+ checkbox.checked = url.searchParams.has('history_follow_rename', 'true');
checkbox.addEventListener('change', () => {
- let url = location.toString();
+ const url = new URL(location.toString());
- url = url.replaceAll(/history_follow_rename=(true|false)&*/g, '');
- if (url.endsWith('?')) {
- url = url.slice(0, -1);
- }
- if (url.includes('?')) {
- url += '&';
- } else {
- url += '?';
- }
-
- url += `history_follow_rename=${checkbox.checked}`;
- window.location.href = url;
+ url.searchParams.set('history_follow_rename', `${checkbox.checked}`);
+ window.location.replace(url);
});
}
From 308119f1c7e0cb056352fb254923e1e15bfb1e61 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 11:23:38 +0200
Subject: [PATCH 11/14] Uses git rev-list when no rename follow
---
modules/git/commit.go | 16 ++++++++++++++--
modules/git/repo_commit.go | 22 ++++++++++++++--------
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 47e19d301dd23..89a60d4269967 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -173,7 +173,15 @@ type CommitsCountOptions struct {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
- cmd := NewCommand("--no-pager", "log", "--pretty=format:%H")
+ var cmd *Command
+ cmd = nil
+ followRename := len(opts.RelPath) > 0 && opts.FollowRename
+
+ if followRename {
+ cmd = NewCommand("--no-pager", "log", "--pretty=format:%H")
+ } else {
+ cmd = NewCommand("rev-list", "--count")
+ }
cmd.AddDynamicArguments(opts.Revision...)
@@ -192,7 +200,11 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
if err != nil {
return 0, err
}
- return int64(len(strings.Split(stdout, "\n"))), nil
+ if followRename {
+ return int64(len(strings.Split(stdout, "\n"))), nil
+ } else {
+ return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
+ }
}
// CommitsCount returns number of total commits of until current revision.
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 6cdcab7d6db76..dd4987aa97e3e 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -239,13 +239,18 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
go func() {
stderr := strings.Builder{}
- gitCmd := NewCommand("--no-pager", "log").
- AddOptionFormat("--pretty=format:%%H").
- AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
- AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
- if opts.FollowRename {
- gitCmd.AddOptionValues("--follow")
+ var gitCmd *Command
+
+ if !opts.FollowRename {
+ gitCmd = NewCommand("rev-list")
+ } else {
+ gitCmd = NewCommand("--no-pager", "log").
+ AddOptionFormat("--pretty=format:%%H").
+ AddOptionFormat("--follow")
}
+ gitCmd.AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
+ AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
+
gitCmd.AddDynamicArguments(opts.Revision)
if opts.Not != "" {
@@ -264,7 +269,8 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
Stdout: stdoutWriter,
Stderr: &stderr,
})
- if err != nil && err != io.ErrUnexpectedEOF {
+
+ if err != nil && !(opts.FollowRename && err == io.ErrUnexpectedEOF) {
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
} else {
_ = stdoutWriter.Close()
@@ -281,7 +287,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
shaline := make([]byte, length+1)
for {
n, err := io.ReadFull(stdoutReader, shaline)
- if (err != nil && err != io.ErrUnexpectedEOF) || n < length {
+ if (err != nil && !(opts.FollowRename && err == io.ErrUnexpectedEOF)) || n < length {
if err == io.EOF {
err = nil
}
From a9d4c149f612d1a70cf343a2dd5ab8313cbc18b9 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 12:11:55 +0200
Subject: [PATCH 12/14] Fixed go linting
---
modules/git/commit.go | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 89a60d4269967..0046200448f9d 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -174,7 +174,6 @@ type CommitsCountOptions struct {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
var cmd *Command
- cmd = nil
followRename := len(opts.RelPath) > 0 && opts.FollowRename
if followRename {
@@ -202,9 +201,8 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
}
if followRename {
return int64(len(strings.Split(stdout, "\n"))), nil
- } else {
- return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}
+ return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}
// CommitsCount returns number of total commits of until current revision.
From 0991eb3839f3d1f8316d8176a341949395089968 Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 11:27:40 +0000
Subject: [PATCH 13/14] Replace location by window.location + removed useless
.toString()
Co-authored-by: silverwind
---
web_src/js/features/repo-commit.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts
index 3a481229e3301..81ba3f5784cb4 100644
--- a/web_src/js/features/repo-commit.ts
+++ b/web_src/js/features/repo-commit.ts
@@ -35,7 +35,7 @@ export function initCommitFileHistoryFollowRename() {
checkbox.checked = url.searchParams.has('history_follow_rename', 'true');
checkbox.addEventListener('change', () => {
- const url = new URL(location.toString());
+ const url = new URL(window.location);
url.searchParams.set('history_follow_rename', `${checkbox.checked}`);
window.location.replace(url);
From 0bbfaef053a0e40924c70baec8ff4f43630a0a1a Mon Sep 17 00:00:00 2001
From: Thomas Sayen <69324626+Chi-Iroh@users.noreply.github.com>
Date: Wed, 11 Jun 2025 19:41:39 +0000
Subject: [PATCH 14/14] Use tailwind style instead of inline style
Co-authored-by: silverwind
---
templates/repo/commits_table.tmpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl
index 6ffe25a56dcab..e6be1d40c03d1 100644
--- a/templates/repo/commits_table.tmpl
+++ b/templates/repo/commits_table.tmpl
@@ -9,7 +9,7 @@
{{end}}
-
+
{{if .IsDiffCompare}}