Skip to content

Commit 44cbc8d

Browse files
committed
wip
1 parent 57f45e7 commit 44cbc8d

File tree

4 files changed

+128
-233
lines changed

4 files changed

+128
-233
lines changed

include/git2/push.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ typedef struct {
3434
* to create. The default value is 1.
3535
*/
3636
unsigned int pb_parallelism;
37+
/**
38+
* The refspecs to use for this push. Leave empty to use the
39+
* base refspecs.
40+
*/
41+
git_strarray refspecs;
42+
/**
43+
* Identity to use to update the reflog.
44+
*/
45+
git_signature *signature;
46+
/**
47+
* The message to insert into the reflogs.
48+
*/
49+
char *reflog_message;
3750
} git_push_options;
3851

3952
#define GIT_PUSH_OPTIONS_VERSION 1

include/git2/remote.h

Lines changed: 71 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,6 @@ GIT_EXTERN(int) git_remote_create_anonymous(
9797
*/
9898
GIT_EXTERN(int) git_remote_lookup(git_remote **out, git_repository *repo, const char *name);
9999

100-
/**
101-
* Save a remote to its repository's configuration
102-
*
103-
* One can't save a in-memory remote. Doing so will
104-
* result in a GIT_EINVALIDSPEC being returned.
105-
*
106-
* @param remote the remote to save to config
107-
* @return 0, GIT_EINVALIDSPEC or an error code
108-
*/
109-
GIT_EXTERN(int) git_remote_save(const git_remote *remote);
110-
111100
/**
112101
* Create a copy of an existing remote. All internal strings are also
113102
* duplicated. Callbacks are not duplicated.
@@ -317,7 +306,7 @@ GIT_EXTERN(int) git_remote_ls(const git_remote_head ***out, size_t *size, git_r
317306
* download. Use NULL or an empty array to use the base refspecs
318307
* @return 0 or an error code
319308
*/
320-
GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_strarray *refspecs);
309+
GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_remote_callbacks *callbacks, const git_strarray *refspecs);
321310

322311
/**
323312
* Create a packfile and send it to the server
@@ -330,7 +319,7 @@ GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_strarray *refs
330319
* upload. Use NULL or an empty array to use the base refspecs
331320
* @return 0 or an error code
332321
*/
333-
GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts);
322+
GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_remote_callbacks *callbacks, const git_push_options *opts);
334323

335324
/**
336325
* Check whether the remote is connected
@@ -395,42 +384,91 @@ GIT_EXTERN(int) git_remote_update_tips(
395384
*/
396385
GIT_EXTERN(int) git_remote_prune(git_remote *remote);
397386

387+
/**
388+
* Automatic tag following option
389+
*
390+
* Lets us select the --tags option to use.
391+
*/
392+
typedef enum {
393+
GIT_REMOTE_DOWNLOAD_TAGS_AUTO = 0,
394+
GIT_REMOTE_DOWNLOAD_TAGS_NONE = 1,
395+
GIT_REMOTE_DOWNLOAD_TAGS_ALL = 2
396+
} git_remote_autotag_option_t;
397+
398+
typedef struct {
399+
unsigned int version;
400+
/**
401+
* Whether to update FETCH_HEAD setting. By default,
402+
* FETCH_HEAD will be updated on every fetch. Set to 0 to
403+
* disable.
404+
*/
405+
unsigned int update_fetchhead;
406+
/**
407+
* Set to true to prune stale references after fetching
408+
*/
409+
unsigned int prune;
410+
/**
411+
* The tag auto-follow setting
412+
*/
413+
git_remote_autotag_option_t autotag;
414+
/**
415+
* The refspecs to use for this fetch. Leave empty to use the
416+
* base refspecs.
417+
*/
418+
git_strarray refspecs;
419+
/**
420+
* Identity to use to update the reflog.
421+
*/
422+
const git_signature *signature;
423+
/**
424+
* The message to insert into the reflogs. If NULL, the default is "fetch".
425+
*/
426+
const char *reflog_message;
427+
} git_fetch_options;
428+
429+
#define GIT_FETCH_OPTIONS_VERSION 1
430+
#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, 1 }
431+
432+
/**
433+
* Initializes a `git_fetch_options` with default values. Equivalent to
434+
* creating an instance with GIT_FETCH_OPTIONS_INIT.
435+
*
436+
* @param opts the `git_fetch_options` instance to initialize.
437+
* @param version the version of the struct; you should pass
438+
* `GIT_FETCH_OPTIONS_VERSION` here.
439+
* @return Zero on success; -1 on failure.
440+
*/
441+
GIT_EXTERN(int) git_fetch_init_options(
442+
git_fetch_options *opts,
443+
unsigned int version);
444+
398445
/**
399446
* Download new data and update tips
400447
*
401448
* Convenience function to connect to a remote, download the data,
402449
* disconnect and update the remote-tracking branches.
403450
*
404451
* @param remote the remote to fetch from
405-
* @param refspecs the refspecs to use for this fetch. Pass NULL or an
406-
* empty array to use the base refspecs.
407-
* @param signature The identity to use when updating reflogs
408-
* @param reflog_message The message to insert into the reflogs. If NULL, the
409-
* default is "fetch"
452+
* @param opts configuration to use for this fetch
410453
* @return 0 or an error code
411454
*/
412455
GIT_EXTERN(int) git_remote_fetch(
413-
git_remote *remote,
414-
const git_strarray *refspecs,
415-
const git_signature *signature,
416-
const char *reflog_message);
456+
git_remote *remote,
457+
const git_remote_callbacks *callbacks,
458+
const git_fetch_options *opts);
417459

418460
/**
419461
* Perform a push
420462
*
421463
* Peform all the steps from a push.
422464
*
423465
* @param remote the remote to push to
424-
* @param refspecs the refspecs to use for pushing. If none are
425-
* passed, the configured refspecs will be used
426-
* @param opts the options
427-
* @param signature signature to use for the reflog of updated references
428-
* @param reflog_message message to use for the reflog of upated references
466+
* @param opts the options to use for this push
429467
*/
430-
GIT_EXTERN(int) git_remote_push(git_remote *remote,
431-
const git_strarray *refspecs,
432-
const git_push_options *opts,
433-
const git_signature *signature, const char *reflog_message);
468+
GIT_EXTERN(int) git_remote_push(
469+
git_remote *remote,
470+
const git_remote_callbacks *callbacks,
471+
const git_push_options *opts);
434472

435473
/**
436474
* Get a list of the configured remotes for a repo
@@ -548,45 +586,11 @@ GIT_EXTERN(int) git_remote_init_callbacks(
548586
git_remote_callbacks *opts,
549587
unsigned int version);
550588

551-
/**
552-
* Set the callbacks for a remote
553-
*
554-
* Note that the remote keeps its own copy of the data and you need to
555-
* call this function again if you want to change the callbacks.
556-
*
557-
* @param remote the remote to configure
558-
* @param callbacks a pointer to the user's callback settings
559-
* @return 0 or an error code
560-
*/
561-
GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks);
562-
563-
/**
564-
* Retrieve the current callback structure
565-
*
566-
* This provides read access to the callbacks structure as the remote
567-
* sees it.
568-
*
569-
* @param remote the remote to query
570-
* @return a pointer to the callbacks structure
571-
*/
572-
GIT_EXTERN(const git_remote_callbacks *) git_remote_get_callbacks(git_remote *remote);
573-
574589
/**
575590
* Get the statistics structure that is filled in by the fetch operation.
576591
*/
577592
GIT_EXTERN(const git_transfer_progress *) git_remote_stats(git_remote *remote);
578593

579-
/**
580-
* Automatic tag following option
581-
*
582-
* Lets us select the --tags option to use.
583-
*/
584-
typedef enum {
585-
GIT_REMOTE_DOWNLOAD_TAGS_AUTO = 0,
586-
GIT_REMOTE_DOWNLOAD_TAGS_NONE = 1,
587-
GIT_REMOTE_DOWNLOAD_TAGS_ALL = 2
588-
} git_remote_autotag_option_t;
589-
590594
/**
591595
* Retrieve the tag auto-follow setting
592596
*
@@ -595,16 +599,6 @@ typedef enum {
595599
*/
596600
GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(const git_remote *remote);
597601

598-
/**
599-
* Set the tag auto-follow setting
600-
*
601-
* @param remote the remote to configure
602-
* @param value a GIT_REMOTE_DOWNLOAD_TAGS value
603-
*/
604-
GIT_EXTERN(void) git_remote_set_autotag(
605-
git_remote *remote,
606-
git_remote_autotag_option_t value);
607-
608602
/**
609603
* Retrieve the ref-prune setting
610604
*
@@ -624,7 +618,7 @@ GIT_EXTERN(int) git_remote_prune_refs(const git_remote *remote);
624618
*
625619
* No loaded instances of a the remote with the old name will change
626620
* their name or their list of refspecs.
627-
*
621+
*a
628622
* @param problems non-default refspecs cannot be renamed and will be
629623
* stored here for further processing by the caller. Always free this
630624
* strarray on successful return.
@@ -646,16 +640,7 @@ GIT_EXTERN(int) git_remote_rename(
646640
* @return the update FETCH_HEAD setting
647641
*/
648642
GIT_EXTERN(int) git_remote_update_fetchhead(git_remote *remote);
649-
650-
/**
651-
* Sets the update FETCH_HEAD setting. By default, FETCH_HEAD will be
652-
* updated on every fetch. Set to 0 to disable.
653-
*
654-
* @param remote the remote to configure
655-
* @param value 0 to disable updating FETCH_HEAD
656-
*/
657-
GIT_EXTERN(void) git_remote_set_update_fetchhead(git_remote *remote, int value);
658-
643+
659644
/**
660645
* Ensure the remote name is well-formed.
661646
*

src/clone.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static int default_remote_create(
250250
if ((error = git_remote_create(out, repo, name, url)) < 0)
251251
return error;
252252

253-
return git_remote_set_callbacks(*out, callbacks);
253+
return 0;
254254
}
255255

256256
/*
@@ -335,6 +335,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_check
335335
int error;
336336
git_buf reflog_message = GIT_BUF_INIT;
337337
git_remote *remote;
338+
git_fetch_options fetch_options = GIT_FETCH_OPTIONS_INIT;
338339
const git_remote_callbacks *callbacks;
339340

340341
assert(repo && _remote);
@@ -347,18 +348,15 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_check
347348
if ((error = git_remote_dup(&remote, _remote)) < 0)
348349
return error;
349350

350-
callbacks = git_remote_get_callbacks(_remote);
351-
if (!giterr__check_version(callbacks, 1, "git_remote_callbacks") &&
352-
(error = git_remote_set_callbacks(remote, callbacks)) < 0)
353-
goto cleanup;
354-
355351
if ((error = git_remote_add_fetch(remote, "refs/tags/*:refs/tags/*")) < 0)
356352
goto cleanup;
357353

358-
git_remote_set_update_fetchhead(remote, 0);
359354
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
360355

361-
if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
356+
fetch_options.signature = signature;
357+
fetch_options.reflog_message = git_buf_cstr(&reflog_message);
358+
fetch_options.update_fetchhead = 0;
359+
if ((error = git_remote_fetch(remote, &_remote->callbacks, &fetch_options)) != 0)
362360
goto cleanup;
363361

364362
error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
@@ -512,6 +510,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
512510
{
513511
int error, flags;
514512
git_repository *src;
513+
git_fetch_options fetch_options = GIT_FETCH_OPTIONS_INIT;
515514
git_buf src_odb = GIT_BUF_INIT, dst_odb = GIT_BUF_INIT, src_path = GIT_BUF_INIT;
516515
git_buf reflog_message = GIT_BUF_INIT;
517516

@@ -553,7 +552,9 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
553552

554553
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
555554

556-
if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
555+
fetch_options.signature = signature;
556+
fetch_options.reflog_message = git_buf_cstr(&reflog_message);
557+
if ((error = git_remote_fetch(remote, NULL, &fetch_options)) != 0)
557558
goto cleanup;
558559

559560
error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));

0 commit comments

Comments
 (0)