Adjust object format interface (#28469)
- Remove `ObjectFormatID` - Remove function `ObjectFormatFromID`. - Use `Sha1ObjectFormat` directly but not a pointer because it's an empty struct. - Store `ObjectFormatName` in `repository` struct
This commit is contained in:
parent
7fb6b51470
commit
408a484224
54 changed files with 191 additions and 203 deletions
|
@ -90,7 +90,7 @@ func GetObjectFormatOfRepo(ctx context.Context, repoPath string) (ObjectFormat,
|
|||
}
|
||||
|
||||
// InitRepository initializes a new Git repository.
|
||||
func InitRepository(ctx context.Context, repoPath string, bare bool, objectFormat ObjectFormat) error {
|
||||
func InitRepository(ctx context.Context, repoPath string, bare bool, objectFormatName string) error {
|
||||
err := os.MkdirAll(repoPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -98,7 +98,13 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
|
|||
|
||||
cmd := NewCommand(ctx, "init")
|
||||
if SupportHashSha256 {
|
||||
cmd.AddOptionValues("--object-format", objectFormat.String())
|
||||
if objectFormatName == "" {
|
||||
objectFormatName = Sha1ObjectFormat.Name()
|
||||
}
|
||||
if !IsValidObjectFormat(objectFormatName) {
|
||||
return fmt.Errorf("invalid object format: %s", objectFormatName)
|
||||
}
|
||||
cmd.AddOptionValues("--object-format", objectFormatName)
|
||||
}
|
||||
if bare {
|
||||
cmd.AddArguments("--bare")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue