git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4] Build-in send-pack, with an API for other programs to call.
@ 2007-10-30  1:05 Daniel Barkalow
  2007-10-30  1:14 ` Shawn O. Pearce
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Barkalow @ 2007-10-30  1:05 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Also marks some more things as const, as needed.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 Makefile                           |    1 +
 send-pack.c => builtin-send-pack.c |   40 +++++++++++++++++++++++++----------
 builtin.h                          |    1 +
 git.c                              |    1 +
 send-pack.h                        |   18 ++++++++++++++++
 5 files changed, 49 insertions(+), 12 deletions(-)
 rename send-pack.c => builtin-send-pack.c (93%)
 create mode 100644 send-pack.h

diff --git a/Makefile b/Makefile
index 64ad297..8b0c8cd 100644
--- a/Makefile
+++ b/Makefile
@@ -359,6 +359,7 @@ BUILTIN_OBJS = \
 	builtin-push.o \
 	builtin-read-tree.o \
 	builtin-reflog.o \
+	builtin-send-pack.o \
 	builtin-config.o \
 	builtin-rerere.o \
 	builtin-reset.o \
diff --git a/send-pack.c b/builtin-send-pack.c
similarity index 93%
rename from send-pack.c
rename to builtin-send-pack.c
index fe56617..931f994 100644
--- a/send-pack.c
+++ b/builtin-send-pack.c
@@ -5,6 +5,7 @@
 #include "pkt-line.h"
 #include "run-command.h"
 #include "remote.h"
+#include "send-pack.h"
 
 static const char send_pack_usage[] =
 "git-send-pack [--all] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
@@ -178,7 +179,7 @@ static int receive_status(int in)
 	return ret;
 }
 
-static int send_pack(int in, int out, struct remote *remote, int nr_refspec, const char **refspec)
+static int do_send_pack(int in, int out, struct remote *remote, int nr_refspec, const char **refspec)
 {
 	struct ref *ref;
 	int new_refs;
@@ -360,22 +361,27 @@ static void verify_remote_names(int nr_heads, const char **heads)
 	}
 }
 
-int main(int argc, char **argv)
+void setup_send_pack(struct send_pack_args *args)
+{
+	receivepack = args->receivepack;
+	verbose = args->verbose;
+	send_all = args->send_all;
+	force_update = args->force_update;
+	use_thin_pack = args->use_thin_pack;
+	dry_run = args->dry_run;
+}
+
+int cmd_send_pack(int argc, const char **argv, const char *prefix)
 {
 	int i, nr_heads = 0;
-	char *dest = NULL;
 	const char **heads = NULL;
-	int fd[2], ret;
-	pid_t pid;
-	char *remote_name = NULL;
+	const char *remote_name = NULL;
 	struct remote *remote = NULL;
-
-	setup_git_directory();
-	git_config(git_default_config);
+	const char *dest = NULL;
 
 	argv++;
 	for (i = 1; i < argc; i++, argv++) {
-		char *arg = *argv;
+		const char *arg = *argv;
 
 		if (*arg == '-') {
 			if (!prefixcmp(arg, "--receive-pack=")) {
@@ -424,7 +430,6 @@ int main(int argc, char **argv)
 		usage(send_pack_usage);
 	if (heads && send_all)
 		usage(send_pack_usage);
-	verify_remote_names(nr_heads, heads);
 
 	if (remote_name) {
 		remote = remote_get(remote_name);
@@ -434,10 +439,21 @@ int main(int argc, char **argv)
 		}
 	}
 
+	return send_pack(dest, remote, nr_heads, heads);
+}
+
+int send_pack(const char *dest, struct remote *remote,
+	      int nr_heads, const char **heads)
+{
+	int fd[2], ret;
+	pid_t pid;
+
+	verify_remote_names(nr_heads, heads);
+
 	pid = git_connect(fd, dest, receivepack, verbose ? CONNECT_VERBOSE : 0);
 	if (pid < 0)
 		return 1;
-	ret = send_pack(fd[0], fd[1], remote, nr_heads, heads);
+	ret = do_send_pack(fd[0], fd[1], remote, nr_heads, heads);
 	close(fd[0]);
 	close(fd[1]);
 	ret |= finish_connect(pid);
diff --git a/builtin.h b/builtin.h
index ff84835..51747c7 100644
--- a/builtin.h
+++ b/builtin.h
@@ -69,6 +69,7 @@ extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
 extern int cmd_revert(int argc, const char **argv, const char *prefix);
 extern int cmd_rm(int argc, const char **argv, const char *prefix);
 extern int cmd_runstatus(int argc, const char **argv, const char *prefix);
+extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
 extern int cmd_show(int argc, const char **argv, const char *prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 1b182e2..4893a85 100644
--- a/git.c
+++ b/git.c
@@ -370,6 +370,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
 		{ "rm", cmd_rm, RUN_SETUP | NEED_WORK_TREE },
 		{ "runstatus", cmd_runstatus, RUN_SETUP | NEED_WORK_TREE },
+		{ "send-pack", cmd_send_pack, RUN_SETUP },
 		{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
 		{ "show-branch", cmd_show_branch, RUN_SETUP },
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
diff --git a/send-pack.h b/send-pack.h
new file mode 100644
index 0000000..22b0624
--- /dev/null
+++ b/send-pack.h
@@ -0,0 +1,18 @@
+#ifndef SEND_PACK_H
+#define SEND_PACK_H
+
+struct send_pack_args {
+	const char *receivepack;
+	int verbose;
+	int send_all;
+	int force_update;
+	int use_thin_pack;
+	int dry_run;
+};
+
+void setup_send_pack(struct send_pack_args *args);
+
+int send_pack(const char *dest, struct remote *remote,
+	      int nr_heads, const char **heads);
+
+#endif
-- 
1.5.3.4.1206.g5f96

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/4] Build-in send-pack, with an API for other programs to call.
  2007-10-30  1:05 [PATCH 3/4] Build-in send-pack, with an API for other programs to call Daniel Barkalow
@ 2007-10-30  1:14 ` Shawn O. Pearce
  2007-10-30  1:18   ` Shawn O. Pearce
  2007-10-30  1:19   ` Daniel Barkalow
  0 siblings, 2 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2007-10-30  1:14 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Junio C Hamano, git

Daniel Barkalow <barkalow@iabervon.org> wrote:
> -int main(int argc, char **argv)
> +void setup_send_pack(struct send_pack_args *args)
> +{
> +	receivepack = args->receivepack;
> +	verbose = args->verbose;
> +	send_all = args->send_all;
> +	force_update = args->force_update;
> +	use_thin_pack = args->use_thin_pack;
> +	dry_run = args->dry_run;
> +}
...
> +struct send_pack_args {
> +	const char *receivepack;
> +	int verbose;
> +	int send_all;
> +	int force_update;
> +	int use_thin_pack;
> +	int dry_run;
> +};
> +

Ick.  How about doing what I did with builtin-fetch-pack.c which
was to copy the args into a global "static struct fetch_pack_args"
and make the struct a bitfield with these boolean items as ":1"
rather than a full int?

-- 
Shawn.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/4] Build-in send-pack, with an API for other programs to call.
  2007-10-30  1:14 ` Shawn O. Pearce
@ 2007-10-30  1:18   ` Shawn O. Pearce
  2007-10-30  1:19   ` Daniel Barkalow
  1 sibling, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2007-10-30  1:18 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Junio C Hamano, git

"Shawn O. Pearce" <spearce@spearce.org> wrote:
> Daniel Barkalow <barkalow@iabervon.org> wrote:
> > -int main(int argc, char **argv)
> > +void setup_send_pack(struct send_pack_args *args)
> > +{
> > +	receivepack = args->receivepack;
> > +	verbose = args->verbose;
> > +	send_all = args->send_all;
> > +	force_update = args->force_update;
> > +	use_thin_pack = args->use_thin_pack;
> > +	dry_run = args->dry_run;
> > +}
> ...
> > +struct send_pack_args {
> > +	const char *receivepack;
> > +	int verbose;
> > +	int send_all;
> > +	int force_update;
> > +	int use_thin_pack;
> > +	int dry_run;
> > +};
> > +
> 
> Ick.  How about doing what I did with builtin-fetch-pack.c [...]

To be more precise please refer to the following fetch-pack changes:

  fa74052922: Always obtain fetch-pack arguments from struct fetch_pack_args
  bbaf458428: Use 'unsigned:1' when we mean boolean options

-- 
Shawn.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/4] Build-in send-pack, with an API for other programs to call.
  2007-10-30  1:14 ` Shawn O. Pearce
  2007-10-30  1:18   ` Shawn O. Pearce
@ 2007-10-30  1:19   ` Daniel Barkalow
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Barkalow @ 2007-10-30  1:19 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git

On Mon, 29 Oct 2007, Shawn O. Pearce wrote:

> Daniel Barkalow <barkalow@iabervon.org> wrote:
> > -int main(int argc, char **argv)
> > +void setup_send_pack(struct send_pack_args *args)
> > +{
> > +	receivepack = args->receivepack;
> > +	verbose = args->verbose;
> > +	send_all = args->send_all;
> > +	force_update = args->force_update;
> > +	use_thin_pack = args->use_thin_pack;
> > +	dry_run = args->dry_run;
> > +}
> ...
> > +struct send_pack_args {
> > +	const char *receivepack;
> > +	int verbose;
> > +	int send_all;
> > +	int force_update;
> > +	int use_thin_pack;
> > +	int dry_run;
> > +};
> > +
> 
> Ick.  How about doing what I did with builtin-fetch-pack.c which
> was to copy the args into a global "static struct fetch_pack_args"
> and make the struct a bitfield with these boolean items as ":1"
> rather than a full int?

Yeah, that's better. I'll respin parts 3 and 4 that way.

	-Daniel
*This .sig left intentionally blank*

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-30  1:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-30  1:05 [PATCH 3/4] Build-in send-pack, with an API for other programs to call Daniel Barkalow
2007-10-30  1:14 ` Shawn O. Pearce
2007-10-30  1:18   ` Shawn O. Pearce
2007-10-30  1:19   ` Daniel Barkalow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).