* Initialize 'repo' based on the provided 'gitdir'. * Return 0 upon success and a non-zero value upon failure. */
| 275 | * Return 0 upon success and a non-zero value upon failure. |
| 276 | */ |
| 277 | int repo_init(struct repository *repo, |
| 278 | const char *gitdir, |
| 279 | const char *worktree) |
| 280 | { |
| 281 | struct repository_format format = REPOSITORY_FORMAT_INIT; |
| 282 | struct strbuf err = STRBUF_INIT; |
| 283 | |
| 284 | memset(repo, 0, sizeof(*repo)); |
| 285 | |
| 286 | initialize_repository(repo); |
| 287 | |
| 288 | if (repo_init_gitdir(repo, gitdir)) |
| 289 | goto error; |
| 290 | |
| 291 | if (read_repository_format_from_commondir(&format, repo->commondir)) |
| 292 | goto error; |
| 293 | |
| 294 | if (apply_repository_format(repo, &format, 0, &err) < 0) { |
| 295 | warning("%s", err.buf); |
| 296 | goto error; |
| 297 | } |
| 298 | |
| 299 | if (worktree) |
| 300 | repo_set_worktree(repo, worktree); |
| 301 | |
| 302 | clear_repository_format(&format); |
| 303 | strbuf_release(&err); |
| 304 | return 0; |
| 305 | |
| 306 | error: |
| 307 | clear_repository_format(&format); |
| 308 | strbuf_release(&err); |
| 309 | repo_clear(repo); |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | int repo_submodule_init(struct repository *subrepo, |
| 314 | struct repository *superproject, |