(path string, opts *PlainInitOptions)
| 256 | } |
| 257 | |
| 258 | func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, error) { |
| 259 | if opts == nil { |
| 260 | opts = &PlainInitOptions{} |
| 261 | } |
| 262 | |
| 263 | var wt, dot billy.Filesystem |
| 264 | |
| 265 | if opts.Bare { |
| 266 | dot = osfs.New(path) |
| 267 | } else { |
| 268 | wt = osfs.New(path) |
| 269 | dot, _ = wt.Chroot(GitDirName) |
| 270 | } |
| 271 | |
| 272 | s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault()) |
| 273 | |
| 274 | r, err := InitWithOptions(s, wt, opts.InitOptions) |
| 275 | if err != nil { |
| 276 | return nil, err |
| 277 | } |
| 278 | |
| 279 | cfg, err := r.Config() |
| 280 | if err != nil { |
| 281 | return nil, err |
| 282 | } |
| 283 | |
| 284 | if opts.ObjectFormat != "" { |
| 285 | if opts.ObjectFormat == formatcfg.SHA256 && hash.CryptoType != crypto.SHA256 { |
| 286 | return nil, ErrSHA256NotSupported |
| 287 | } |
| 288 | |
| 289 | cfg.Core.RepositoryFormatVersion = formatcfg.Version_1 |
| 290 | cfg.Extensions.ObjectFormat = opts.ObjectFormat |
| 291 | } |
| 292 | |
| 293 | err = r.Storer.SetConfig(cfg) |
| 294 | if err != nil { |
| 295 | return nil, err |
| 296 | } |
| 297 | |
| 298 | return r, err |
| 299 | } |
| 300 | |
| 301 | // PlainOpen opens a git repository from the given path. It detects if the |
| 302 | // repository is bare or a normal one. If the path doesn't contain a valid |
searching dependent graphs…