Skip to content

Conversation

linquize
Copy link
Contributor

git_clone supports init_options

if (!(retcode = git_repository_init(&repo, local_path, normOptions.bare))) {
if (!(retcode = normOptions.init_options
? git_repository_init_ext(&repo, local_path, normOptions.init_options)
: git_repository_init(&repo, local_path, normOptions.bare))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to address this in normalize_options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should clarify a bit. It turns out that git_repository_init is a wrapper around git_repository_init_ext, so let's just use the _ext variant.

This probably means dropping the bare option, in favor of setting the GIT_REPOSITORY_INIT_BARE bit on init_options.flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we have to duplicate the code from git_repository_init(), isn't?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one line of it.

if (!dst->init_options) {
  git_repository_init_options dummy_options = GIT_REPOSITORY_INIT_OPTIONS_INIT;
  opts.flags = GIT_REPOSITORY_INIT_MKPATH;
  dst->init_options = /* allocate and check allocation */;
  memcpy(dst->init_options, &dummy_options, sizeof(git_repository_init_options);
}

If the caller wants a bare repo, they'll provide a valid init_options and set the proper flag. If they don't, they get the default options. The only hitch is that you'll have to track that allocation somehow, and free it later (maybe just a stack variable in do_clone?).

@ben
Copy link
Member

ben commented Sep 15, 2013

I'm definitely 👍 on this. Clone landed before git_repository_init_ext did, so this wasn't possible at the time, but it's the right thing.

@linquize
Copy link
Contributor Author

Commit updated

@ben
Copy link
Member

ben commented Sep 16, 2013

I'm still thinking of 💀ing the bare option, but this PR does what's on the tin. Thanks! 💖

ben added a commit that referenced this pull request Sep 16, 2013
@ben ben merged commit 8821c9a into libgit2:development Sep 16, 2013
@@ -427,6 +427,13 @@ static void normalize_options(git_clone_options *dst, const git_clone_options *s

/* Provide defaults for null pointers */
if (!dst->remote_name) dst->remote_name = "origin";
if (!dst->init_options)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please keep an eye out for brackets and consistency? :)

phatblat pushed a commit to phatblat/libgit2 that referenced this pull request Sep 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants