Git-Raw

 view release on metacpan or  search on metacpan

xs/Remote.xs  view on Meta::CPAN

				pushurl
			);
			git_check_error(rc);
			RETVAL = newSVpv(pushurl, 0);
		} else {
			RETVAL = &PL_sv_undef;
			if ((pushurl = git_remote_pushurl(remote -> remote)))
				RETVAL = newSVpv(pushurl, 0);
		}


	OUTPUT: RETVAL

void
add_fetch(self, spec)
	SV *self
	SV *spec

	PREINIT:
		int rc;

		Remote remote = NULL;

	CODE:
		remote = GIT_SV_TO_PTR(Remote, self);

		rc = git_remote_add_fetch(
			git_remote_owner(remote -> remote),
			git_remote_name(remote -> remote),
			git_ensure_pv(spec, "spec"));
		git_check_error(rc);

void
add_push(self, spec)
	SV *self
	SV *spec

	PREINIT:
		int rc;

		Remote remote = NULL;

	CODE:
		remote = GIT_SV_TO_PTR(Remote, self);

		rc = git_remote_add_push(
			git_remote_owner(remote -> remote),
			git_remote_name(remote -> remote),
			git_ensure_pv(spec, "spec"));
		git_check_error(rc);

void
refspecs(self)
	SV *self

	PREINIT:
		size_t i, count;

		Remote remote_ptr;

	PPCODE:
		remote_ptr = GIT_SV_TO_PTR(Remote, self);

		count = git_remote_refspec_count(remote_ptr -> remote);

		for (i = 0; i < count; ++i) {
			RefSpec spec;
			const git_refspec *s;
			SV *tmp;

			s = git_remote_get_refspec(
				remote_ptr -> remote,
				i
			);

			Newxz(spec, 1, git_raw_refspec);
			spec -> refspec = (git_refspec *)s;
			spec -> owned = 0;

			GIT_NEW_OBJ_WITH_MAGIC(
				tmp, "Git::Raw::RefSpec", spec, SvRV(self)
			);

			mXPUSHs(tmp);
		}

		XSRETURN(count);

SV *
refspec_count(self)
	Remote self

	CODE:
		RETVAL = newSVuv(git_remote_refspec_count(self -> remote));

	OUTPUT: RETVAL

void
fetch(self, ...)
	Remote self

	PREINIT:
		int rc;

		git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
		git_strarray specs = {NULL, 0};
		git_strarray *refspecs = NULL;

	CODE:
		if (items >= 2) {
			HV *opts = git_ensure_hv(ST(1), "fetch_opts");
			git_hv_to_fetch_opts(opts, &fetch_opts);
		}

		if (items >= 3) {
			git_list_to_paths(
				git_ensure_av(ST(2), "refspecs"),
				&specs
			);
			refspecs = &specs;
		}

		rc = git_remote_fetch(self -> remote, refspecs,
			&fetch_opts, NULL
		);
		if (refspecs) {
			Safefree(specs.strings);
		}
		git_check_error(rc);

void
push(self, refspecs, ...)
	Remote self
	SV *refspecs

	PREINIT:
		int rc;

		git_push_options push_opts = GIT_PUSH_OPTIONS_INIT;
		git_strarray specs = {NULL, 0};

	PPCODE:
		git_list_to_paths(
			git_ensure_av(refspecs, "refspecs"),
			&specs
		);

		if (items >= 3) {
			HV *opts = git_ensure_hv(ST(2), "push_opts");
			git_hv_to_push_opts(opts, &push_opts);
		}

		rc = git_remote_push(self -> remote, &specs, &push_opts);
		Safefree(specs.strings);

		if (rc == GIT_OK || rc == GIT_EUSER)
			XSRETURN_YES;
		git_check_error(rc);

void
connect(self, direction, ...)
	Remote self
	SV *direction

	PREINIT:
		int rc;

		const char *dir;
		git_direction direct = GIT_DIRECTION_FETCH;
		git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	CODE:
		dir = git_ensure_pv(direction, "direction");

		if (strcmp(dir, "fetch") == 0)
			direct = GIT_DIRECTION_FETCH;
		else if (strcmp(dir, "push") == 0)
			direct = GIT_DIRECTION_PUSH;
		else
			croak_usage("Invalid direction '%s'. "
				"Valid values: 'fetch' or 'push'", dir);

		if (items >= 3) {
			git_hv_to_remote_callbacks(
				git_ensure_hv(ST(2), "callbacks"),
				&callbacks
			);
		}

		rc = git_remote_connect(self -> remote, direct, &callbacks, NULL, NULL);
		git_check_error(rc);

void
disconnect(self)
	Remote self

	CODE:
		git_remote_disconnect(self -> remote);

void
download(self, ...)
	Remote self

	PREINIT:
		int rc;

		git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
		git_strarray specs = {NULL, 0};
		git_strarray *refspecs = NULL;

	CODE:
		if (items >= 2) {
			HV *opts = git_ensure_hv(ST(1), "fetch_opts");
			git_hv_to_fetch_opts(opts, &fetch_opts);
		}

		if (items >= 3) {
			git_list_to_paths(
				git_ensure_av(ST(2), "refspecs"),
				&specs
			);
			refspecs = &specs;
		}

		rc = git_remote_download(self -> remote, refspecs,
			&fetch_opts
		);
		if (refspecs) {
			Safefree(specs.strings);
		}
		git_check_error(rc);

void
upload(self, refspecs, ...)
	Remote self
	SV *refspecs

	PREINIT:
		int rc;
		git_push_options push_opts = GIT_PUSH_OPTIONS_INIT;
		git_strarray specs = {NULL, 0};

	PPCODE:
		git_list_to_paths(
			git_ensure_av(refspecs, "refspecs"),
			&specs
		);

		if (items >= 3) {
			HV *opts = git_ensure_hv(ST(2), "push_opts");
			git_hv_to_push_opts(opts, &push_opts);
		}

		rc = git_remote_upload(self -> remote, &specs, &push_opts);
		Safefree(specs.strings);

		if (rc == GIT_OK || rc == GIT_EUSER)
			XSRETURN_YES;
		git_check_error(rc);

void
prune(self, ...)
	Remote self

	PREINIT:
		int rc;

		git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	CODE:
		if (items >= 2) {
			git_hv_to_remote_callbacks(
				git_ensure_hv(ST(1), "callbacks"),
				&callbacks
			);
		}

		rc = git_remote_prune(self -> remote, &callbacks);
		git_check_error(rc);

void
update_tips(self, ...)
	Remote self

	PREINIT:
		int rc;

		git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	CODE:
		if (items >= 2) {
			git_hv_to_remote_callbacks(
				git_ensure_hv(ST(1), "callbacks"),
				&callbacks
			);
		}

		rc = git_remote_update_tips(self -> remote, &callbacks,
			1, GIT_REMOTE_DOWNLOAD_TAGS_NONE, NULL
		);
		git_check_error(rc);

SV *



( run in 0.962 second using v1.01-cache-2.11-cpan-5511b514fd6 )