aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-04-11 21:00:47 +0100
committerGitHub <noreply@github.com>2023-04-11 21:00:47 +0100
commitd5b1afd3cc786e56a90cec910b79815ed3b23cc7 (patch)
tree4e0b93ea480fdea37761d2e879a073ce6f5c1747 /config
parentce62f3e9ff86270538a514a68d3bd5563a733e3b (diff)
parent8e8281008ee98e9864fa9597be3e16aaecdf9891 (diff)
downloadgo-git-d5b1afd3cc786e56a90cec910b79815ed3b23cc7.tar.gz
Merge pull request #707 from pjbgf/experimental-sha256
*: Add support for initializing SHA256 repositories
Diffstat (limited to 'config')
-rw-r--r--config/config.go73
1 files changed, 51 insertions, 22 deletions
diff --git a/config/config.go b/config/config.go
index 8051bc1..83629fc 100644
--- a/config/config.go
+++ b/config/config.go
@@ -59,6 +59,8 @@ type Config struct {
// CommentChar is the character indicating the start of a
// comment for commands like commit and tag
CommentChar string
+ // RepositoryFormatVersion identifies the repository format and layout version.
+ RepositoryFormatVersion format.RepositoryFormatVersion
}
User struct {
@@ -96,6 +98,17 @@ type Config struct {
DefaultBranch string
}
+ Extensions struct {
+ // ObjectFormat specifies the hash algorithm to use. The
+ // acceptable values are sha1 and sha256. If not specified,
+ // sha1 is assumed. It is an error to specify this key unless
+ // core.repositoryFormatVersion is 1.
+ //
+ // This setting must not be changed after repository initialization
+ // (e.g. clone or init).
+ ObjectFormat format.ObjectFormat
+ }
+
// Remotes list of repository remotes, the key of the map is the name
// of the remote, should equal to RemoteConfig.Name.
Remotes map[string]*RemoteConfig
@@ -226,28 +239,31 @@ func (c *Config) Validate() error {
}
const (
- remoteSection = "remote"
- submoduleSection = "submodule"
- branchSection = "branch"
- coreSection = "core"
- packSection = "pack"
- userSection = "user"
- authorSection = "author"
- committerSection = "committer"
- initSection = "init"
- urlSection = "url"
- fetchKey = "fetch"
- urlKey = "url"
- bareKey = "bare"
- worktreeKey = "worktree"
- commentCharKey = "commentChar"
- windowKey = "window"
- mergeKey = "merge"
- rebaseKey = "rebase"
- nameKey = "name"
- emailKey = "email"
- descriptionKey = "description"
- defaultBranchKey = "defaultBranch"
+ remoteSection = "remote"
+ submoduleSection = "submodule"
+ branchSection = "branch"
+ coreSection = "core"
+ packSection = "pack"
+ userSection = "user"
+ authorSection = "author"
+ committerSection = "committer"
+ initSection = "init"
+ urlSection = "url"
+ extensionsSection = "extensions"
+ fetchKey = "fetch"
+ urlKey = "url"
+ bareKey = "bare"
+ worktreeKey = "worktree"
+ commentCharKey = "commentChar"
+ windowKey = "window"
+ mergeKey = "merge"
+ rebaseKey = "rebase"
+ nameKey = "name"
+ emailKey = "email"
+ descriptionKey = "description"
+ defaultBranchKey = "defaultBranch"
+ repositoryFormatVersionKey = "repositoryformatversion"
+ objectFormat = "objectformat"
// DefaultPackWindow holds the number of previous objects used to
// generate deltas. The value 10 is the same used by git command.
@@ -391,6 +407,7 @@ func (c *Config) unmarshalInit() {
// Marshal returns Config encoded as a git-config file.
func (c *Config) Marshal() ([]byte, error) {
c.marshalCore()
+ c.marshalExtensions()
c.marshalUser()
c.marshalPack()
c.marshalRemotes()
@@ -410,12 +427,24 @@ func (c *Config) Marshal() ([]byte, error) {
func (c *Config) marshalCore() {
s := c.Raw.Section(coreSection)
s.SetOption(bareKey, fmt.Sprintf("%t", c.Core.IsBare))
+ if string(c.Core.RepositoryFormatVersion) != "" {
+ s.SetOption(repositoryFormatVersionKey, string(c.Core.RepositoryFormatVersion))
+ }
if c.Core.Worktree != "" {
s.SetOption(worktreeKey, c.Core.Worktree)
}
}
+func (c *Config) marshalExtensions() {
+ // Extensions are only supported on Version 1, therefore
+ // ignore them otherwise.
+ if c.Core.RepositoryFormatVersion == format.Version_1 {
+ s := c.Raw.Section(extensionsSection)
+ s.SetOption(objectFormat, string(c.Extensions.ObjectFormat))
+ }
+}
+
func (c *Config) marshalUser() {
s := c.Raw.Section(userSection)
if c.User.Name != "" {