From 9f8d7a9e73193a92650f97c1d7ce4eced51dfc0c Mon Sep 17 00:00:00 2001 From: hiifong Date: Fri, 13 Dec 2024 01:16:01 +0800 Subject: [PATCH 1/5] Fix lfs migration --- modules/lfs/http_client.go | 1 + modules/lfs/shared.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/lfs/http_client.go b/modules/lfs/http_client.go index 3060e25754cc5..50f0e7a8d88a6 100644 --- a/modules/lfs/http_client.go +++ b/modules/lfs/http_client.go @@ -236,6 +236,7 @@ func createRequest(ctx context.Context, method, url string, headers map[string]s req.Header.Set(key, value) } req.Header.Set("Accept", AcceptHeader) + req.Header.Set("User-Agent", UserAgentHeader) return req, nil } diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go index a4326b57b2f55..40ad789c1d9e8 100644 --- a/modules/lfs/shared.go +++ b/modules/lfs/shared.go @@ -15,7 +15,8 @@ const ( // MediaType contains the media type for LFS server requests MediaType = "application/vnd.git-lfs+json" // Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served - AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" + AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" + UserAgentHeader = "git-lfs" ) // BatchRequest contains multiple requests processed in one batch operation. From 56c23cbc88e10347fd9623cf5432686b1dfe0864 Mon Sep 17 00:00:00 2001 From: hiifong Date: Fri, 13 Dec 2024 22:08:55 +0800 Subject: [PATCH 2/5] Add User-Agent for gitea's self-implemented lfs client. --- modules/lfs/shared.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go index 40ad789c1d9e8..a70d41e19eb1e 100644 --- a/modules/lfs/shared.go +++ b/modules/lfs/shared.go @@ -6,8 +6,10 @@ package lfs import ( "errors" "fmt" + "runtime" "time" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) @@ -15,10 +17,12 @@ const ( // MediaType contains the media type for LFS server requests MediaType = "application/vnd.git-lfs+json" // Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served - AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" - UserAgentHeader = "git-lfs" + AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" ) +// UserAgentHeader Add User-Agent for gitea's self-implemented lfs client. Some lfs servers will check this +var UserAgentHeader = fmt.Sprintf("git-lfs/%s (Gitea; %s %s; %s)", setting.AppVer, runtime.GOOS, runtime.GOARCH, runtime.Version()) + // BatchRequest contains multiple requests processed in one batch operation. // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests type BatchRequest struct { From 221934a1e582ee1daea47d511b9c6149592ceee6 Mon Sep 17 00:00:00 2001 From: hiifong Date: Sat, 14 Dec 2024 00:54:15 +0800 Subject: [PATCH 3/5] Update --- modules/lfs/shared.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go index a70d41e19eb1e..5dfaf2d806ed6 100644 --- a/modules/lfs/shared.go +++ b/modules/lfs/shared.go @@ -9,19 +9,20 @@ import ( "runtime" "time" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) const ( // MediaType contains the media type for LFS server requests MediaType = "application/vnd.git-lfs+json" - // Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served + // AcceptHeader Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" ) -// UserAgentHeader Add User-Agent for gitea's self-implemented lfs client. Some lfs servers will check this -var UserAgentHeader = fmt.Sprintf("git-lfs/%s (Gitea; %s %s; %s)", setting.AppVer, runtime.GOOS, runtime.GOARCH, runtime.Version()) +// UserAgentHeader Add User-Agent for gitea's self-implemented lfs client, +// and the version is consistent with the latest version of git lfs can be avoided incompatibilities. +// Some lfs servers will check this +var UserAgentHeader = fmt.Sprintf("git-lfs/3.6.0 (Gitea; %s %s; %s)", runtime.GOOS, runtime.GOARCH, runtime.Version()) // BatchRequest contains multiple requests processed in one batch operation. // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests From 3411891fa2c1b4ae1445730156cf430350b3deca Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 14 Dec 2024 11:03:29 +0800 Subject: [PATCH 4/5] Update modules/lfs/shared.go Co-authored-by: wxiaoguang --- modules/lfs/shared.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go index 5dfaf2d806ed6..2563240d342af 100644 --- a/modules/lfs/shared.go +++ b/modules/lfs/shared.go @@ -22,7 +22,7 @@ const ( // UserAgentHeader Add User-Agent for gitea's self-implemented lfs client, // and the version is consistent with the latest version of git lfs can be avoided incompatibilities. // Some lfs servers will check this -var UserAgentHeader = fmt.Sprintf("git-lfs/3.6.0 (Gitea; %s %s; %s)", runtime.GOOS, runtime.GOARCH, runtime.Version()) +var UserAgentHeader = "git-lfs/3.6.0 (Gitea)" // BatchRequest contains multiple requests processed in one batch operation. // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests From 644367a132b7bd3fab89b6ccf68f804e2518a09f Mon Sep 17 00:00:00 2001 From: hiifong Date: Sat, 14 Dec 2024 11:06:34 +0800 Subject: [PATCH 5/5] Update --- modules/lfs/shared.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go index 5dfaf2d806ed6..cd9488e3dbfdd 100644 --- a/modules/lfs/shared.go +++ b/modules/lfs/shared.go @@ -6,7 +6,6 @@ package lfs import ( "errors" "fmt" - "runtime" "time" "code.gitea.io/gitea/modules/util" @@ -17,13 +16,12 @@ const ( MediaType = "application/vnd.git-lfs+json" // AcceptHeader Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8" + // UserAgentHeader Add User-Agent for gitea's self-implemented lfs client, + // and the version is consistent with the latest version of git lfs can be avoided incompatibilities. + // Some lfs servers will check this + UserAgentHeader = "git-lfs/3.6.0 (Gitea)" ) -// UserAgentHeader Add User-Agent for gitea's self-implemented lfs client, -// and the version is consistent with the latest version of git lfs can be avoided incompatibilities. -// Some lfs servers will check this -var UserAgentHeader = fmt.Sprintf("git-lfs/3.6.0 (Gitea; %s %s; %s)", runtime.GOOS, runtime.GOARCH, runtime.Version()) - // BatchRequest contains multiple requests processed in one batch operation. // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests type BatchRequest struct {