Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiddharth Asthana <siddharthasthana31@gmail.com>2023-06-18 18:05:55 +0300
committerSiddharth Asthana <siddharthasthana31@gmail.com>2023-07-16 13:03:41 +0300
commit71c41f5573c9062823de625dc58f2268633c7fe4 (patch)
tree7ab006030ee3e88f43b44bc34ad0dc050af99001
parent41b835c4acfd0ca2f8246240af97351cfbba5130 (diff)
Add mailmap support in git-cat-fileissue_4364_add_mailmap_option
Enable mailmap_options feature flag Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com>
-rw-r--r--internal/featureflag/ff_mailmap_options.go9
-rw-r--r--internal/git/catfile/object_content_reader.go5
-rw-r--r--internal/git/catfile/object_content_reader_test.go37
-rw-r--r--internal/git/catfile/object_info_reader.go5
-rw-r--r--internal/git/catfile/object_info_reader_test.go2
-rw-r--r--internal/git/gitpipe/catfile_info.go20
-rw-r--r--internal/git/gitpipe/catfile_info_test.go53
-rw-r--r--internal/testhelper/testhelper.go3
8 files changed, 125 insertions, 9 deletions
diff --git a/internal/featureflag/ff_mailmap_options.go b/internal/featureflag/ff_mailmap_options.go
new file mode 100644
index 000000000..07f7ed3db
--- /dev/null
+++ b/internal/featureflag/ff_mailmap_options.go
@@ -0,0 +1,9 @@
+package featureflag
+
+// MailmapOptions enables the use of mailmap feature in GitLab
+var MailmapOptions = NewFeatureFlag(
+ "mailmap_options",
+ "v16.2.0",
+ "https://gitlab.com/gitlab-org/gitaly/-/issues/5394",
+ true,
+)
diff --git a/internal/git/catfile/object_content_reader.go b/internal/git/catfile/object_content_reader.go
index 0af762077..cae06623d 100644
--- a/internal/git/catfile/object_content_reader.go
+++ b/internal/git/catfile/object_content_reader.go
@@ -9,6 +9,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v16/internal/command"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
)
@@ -59,6 +60,10 @@ func newObjectContentReader(
flags = append(flags, git.Flag{Name: "-Z"})
}
+ if featureflag.MailmapOptions.IsEnabled(ctx) {
+ flags = append([]git.Option{git.Flag{Name: "--use-mailmap"}}, flags...)
+ }
+
batchCmd, err := repo.Exec(ctx,
git.Command{
Name: "cat-file",
diff --git a/internal/git/catfile/object_content_reader_test.go b/internal/git/catfile/object_content_reader_test.go
index 915dc6465..502a68ec6 100644
--- a/internal/git/catfile/object_content_reader_test.go
+++ b/internal/git/catfile/object_content_reader_test.go
@@ -1,6 +1,7 @@
package catfile
import (
+ "context"
"errors"
"fmt"
"io"
@@ -10,6 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/helper/text"
@@ -19,8 +21,12 @@ import (
)
func TestObjectContentReader_reader(t *testing.T) {
- ctx := testhelper.Context(t)
+ t.Parallel()
+
+ testhelper.NewFeatureSets(featureflag.MailmapOptions).Run(t, testObjectContentReader)
+}
+func testObjectContentReader(t *testing.T, ctx context.Context) {
cfg := testcfg.Build(t)
repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
@@ -128,6 +134,35 @@ func TestObjectContentReader_reader(t *testing.T) {
require.NoError(t, err)
}
})
+
+ t.Run("read existing object with mailmap", func(t *testing.T) {
+ mailmapContents := "A U Thor <author@example.com> Scrooge McDuck <scrooge@mcduck.com>"
+
+ commitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: ".mailmap", Mode: "100644", Content: mailmapContents},
+ ),
+ gittest.WithBranch("main"),
+ )
+
+ commitContents := gittest.Exec(t, cfg, "-C", repoPath, "cat-file",
+ "-p", commitID.String())
+
+ if featureflag.MailmapOptions.IsEnabled(ctx) {
+ commitContents = gittest.Exec(t, cfg, "-C", repoPath, "cat-file",
+ "--use-mailmap", "-p", commitID.String())
+ }
+
+ reader, err := newObjectContentReader(ctx, newRepoExecutor(t, cfg, repoProto), nil)
+ require.NoError(t, err)
+
+ object, err := reader.Object(ctx, "refs/heads/main")
+ require.NoError(t, err)
+
+ data, err := io.ReadAll(object)
+ require.NoError(t, err)
+ require.Equal(t, commitContents, data)
+ })
}
func TestObjectContentReader_queue(t *testing.T) {
diff --git a/internal/git/catfile/object_info_reader.go b/internal/git/catfile/object_info_reader.go
index 04fff4947..0df65fd3b 100644
--- a/internal/git/catfile/object_info_reader.go
+++ b/internal/git/catfile/object_info_reader.go
@@ -10,6 +10,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v16/internal/command"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
)
@@ -150,6 +151,10 @@ func newObjectInfoReader(
flags = append(flags, git.Flag{Name: "-Z"})
}
+ if featureflag.MailmapOptions.IsEnabled(ctx) {
+ flags = append([]git.Option{git.Flag{Name: "--use-mailmap"}}, flags...)
+ }
+
batchCmd, err := repo.Exec(ctx,
git.Command{
Name: "cat-file",
diff --git a/internal/git/catfile/object_info_reader_test.go b/internal/git/catfile/object_info_reader_test.go
index ae958c765..0d3b3ad6c 100644
--- a/internal/git/catfile/object_info_reader_test.go
+++ b/internal/git/catfile/object_info_reader_test.go
@@ -131,7 +131,7 @@ func TestObjectInfoReader(t *testing.T) {
require.NoError(t, err)
objectType := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "-t", revision))
- objectContents := gittest.Exec(t, cfg, "-C", repoPath, "cat-file", objectType, revision)
+ objectContents := gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "--use-mailmap", objectType, revision)
oiByRevision[revision] = &ObjectInfo{
Oid: objectID,
diff --git a/internal/git/gitpipe/catfile_info.go b/internal/git/gitpipe/catfile_info.go
index c8d84d5f7..1453a4baa 100644
--- a/internal/git/gitpipe/catfile_info.go
+++ b/internal/git/gitpipe/catfile_info.go
@@ -9,6 +9,7 @@ import (
"io"
"sync/atomic"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
@@ -209,15 +210,20 @@ func CatfileInfoAllObjects(
fmt.Sprintf("=%%(objectname) %%(objecttype) %%(objectsize:disk)")
}
+ options := []git.Option{
+ batchCheckOption,
+ git.Flag{Name: "--batch-all-objects"},
+ git.Flag{Name: "--buffer"},
+ git.Flag{Name: "--unordered"},
+ }
+ if featureflag.MailmapOptions.IsEnabled(ctx) {
+ options = append([]git.Option{git.Flag{Name: "--use-mailmap"}}, options...)
+ }
+
var stderr bytes.Buffer
cmd, err := repo.Exec(ctx, git.Command{
- Name: "cat-file",
- Flags: []git.Option{
- batchCheckOption,
- git.Flag{Name: "--batch-all-objects"},
- git.Flag{Name: "--buffer"},
- git.Flag{Name: "--unordered"},
- },
+ Name: "cat-file",
+ Flags: options,
}, git.WithStderr(&stderr))
if err != nil {
sendCatfileInfoResult(ctx, resultChan, CatfileInfoResult{
diff --git a/internal/git/gitpipe/catfile_info_test.go b/internal/git/gitpipe/catfile_info_test.go
index 7826db62b..8d5cd03d4 100644
--- a/internal/git/gitpipe/catfile_info_test.go
+++ b/internal/git/gitpipe/catfile_info_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
@@ -285,6 +286,58 @@ func TestCatfileInfo(t *testing.T) {
})
}
+func TestCatfileInfoAllObjectsWithMailmap(t *testing.T) {
+ t.Parallel()
+
+ testhelper.NewFeatureSets(featureflag.MailmapOptions).Run(t, testCatfileInfoAllObjectsWithMailmap)
+}
+
+func testCatfileInfoAllObjectsWithMailmap(t *testing.T, ctx context.Context) {
+ cfg := testcfg.Build(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ })
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
+ mailmapContents := "A U Thor <author@example.com> Scrooge McDuck <scrooge@mcduck.com>"
+ blob := gittest.WriteBlob(t, cfg, repoPath, []byte(mailmapContents))
+ tree := gittest.WriteTree(t, cfg, repoPath, []gittest.TreeEntry{
+ {Path: ".mailmap", Mode: "100644", OID: blob},
+ })
+ commit := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithTree(tree),
+ gittest.WithBranch("main"),
+ )
+
+ var actualObjects []CatfileInfoResult
+
+ if featureflag.MailmapOptions.IsEnabled(ctx) {
+ actualObjects = []CatfileInfoResult{
+ {ObjectInfo: &catfile.ObjectInfo{Oid: blob, Type: "blob", Size: 65, Format: gittest.DefaultObjectHash.Format}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: tree, Type: "tree", Size: hashDependentObjectSize(t, 36, 48), Format: gittest.DefaultObjectHash.Format}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: commit, Type: "commit", Size: hashDependentObjectSize(t, 165, 189), Format: gittest.DefaultObjectHash.Format}},
+ }
+ } else {
+ actualObjects = []CatfileInfoResult{
+ {ObjectInfo: &catfile.ObjectInfo{Oid: blob, Type: "blob", Size: 65, Format: gittest.DefaultObjectHash.Format}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: tree, Type: "tree", Size: hashDependentObjectSize(t, 36, 48), Format: gittest.DefaultObjectHash.Format}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: commit, Type: "commit", Size: hashDependentObjectSize(t, 177, 201), Format: gittest.DefaultObjectHash.Format}},
+ }
+ }
+
+ t.Run("successful with mailmap", func(t *testing.T) {
+ it := CatfileInfoAllObjects(ctx, repo)
+
+ var results []CatfileInfoResult
+ for it.Next() {
+ results = append(results, it.Result())
+ }
+ require.NoError(t, it.Err())
+
+ require.ElementsMatch(t, actualObjects, results)
+ })
+}
+
func TestCatfileInfoAllObjects(t *testing.T) {
t.Parallel()
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index c43ef3073..5982339e0 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -191,6 +191,9 @@ func ContextWithoutCancel(opts ...ContextOpt) context.Context {
// information about objects.
ctx = featureflag.ContextWithFeatureFlag(ctx, featureflag.CatfileBatchCommand, rand.Int()%2 == 0)
+ // Randomly enable mailmap
+ ctx = featureflag.ContextWithFeatureFlag(ctx, featureflag.MailmapOptions, rand.Int()%2 == 0)
+
for _, opt := range opts {
ctx = opt(ctx)
}