{"thread":{"id":"8932","subject":"[PATCH] Make fetch-pack a builtin with an internal API","startedAt":"2007-07-08T19:57:01Z","lastAt":"2007-07-08T23:12:18Z","messageCount":3,"participants":["Daniel Barkalow","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46783","messageId":"Pine.LNX.4.64.0707081551120.6977@iabervon.org","threadId":"8932","inReplyTo":null,"subject":"[PATCH] Make fetch-pack a builtin with an internal API","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-07-08T19:57:01Z","receivedAt":"2007-07-08T19:57:01Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"In addition to making fetch-pack a builtin, this allows it to be called \ndirectly from other built-in code without generating and parsing argument \nlists, which will be useful for builtin-fetch.\n\nIncidently, it makes git-fetch-pack not output lists of what it fetched \nwhen it fails.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n Makefile                             |    1 +\n fetch-pack.c => builtin-fetch-pack.c |   99 ++++++++++++++++++++++++++--------\n builtin.h                            |    1 +\n fetch-pack.h                         |   15 +++++\n git.c                                |    1 +\n 5 files changed, 95 insertions(+), 22 deletions(-)\n rename fetch-pack.c => builtin-fetch-pack.c (92%)\n create mode 100644 fetch-pack.h\n\ndiff --git a/Makefile b/Makefile\nindex 4ea5e45..da750f8 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -342,6 +342,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-diff-files.o \\\n \tbuiltin-diff-index.o \\\n \tbuiltin-diff-tree.o \\\n+\tbuiltin-fetch-pack.o \\\n \tbuiltin-fetch--tool.o \\\n \tbuiltin-fmt-merge-msg.o \\\n \tbuiltin-for-each-ref.o \\\ndiff --git a/fetch-pack.c b/builtin-fetch-pack.c\nsimilarity index 92%\nrename from fetch-pack.c\nrename to builtin-fetch-pack.c\nindex 9c81305..828ae24 100644\n--- a/fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -6,6 +6,7 @@\n #include \"exec_cmd.h\"\n #include \"pack.h\"\n #include \"sideband.h\"\n+#include \"fetch-pack.h\"\n \n static int keep_pack;\n static int transfer_unpack_limit = -1;\n@@ -573,7 +574,7 @@ static int get_pack(int xd[2])\n \tdie(\"%s died of unnatural causes %d\", argv[0], status);\n }\n \n-static int fetch_pack(int fd[2], int nr_match, char **match)\n+static struct ref *do_fetch_pack(int fd[2], int nr_match, char **match)\n {\n \tstruct ref *ref;\n \tunsigned char sha1[20];\n@@ -615,12 +616,7 @@ static int fetch_pack(int fd[2], int nr_match, char **match)\n \t\tdie(\"git-fetch-pack: fetch failed.\");\n \n  all_done:\n-\twhile (ref) {\n-\t\tprintf(\"%s %s\\n\",\n-\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n-\t\tref = ref->next;\n-\t}\n-\treturn 0;\n+\treturn ref;\n }\n \n static int remove_duplicates(int nr_heads, char **heads)\n@@ -663,15 +659,42 @@ static int fetch_pack_config(const char *var, const char *value)\n \n static struct lock_file lock;\n \n-int main(int argc, char **argv)\n+void setup_fetch_pack(const char *_uploadpack,\n+\t\t      int _quiet,\n+\t\t      int _keep_pack,\n+\t\t      int _use_thin_pack,\n+\t\t      int _fetch_all,\n+\t\t      int _verbose,\n+\t\t      int _depth,\n+\t\t      int _no_progress)\n+{\n+\tuploadpack = _uploadpack;\n+\tquiet = _quiet;\n+\tkeep_pack = _keep_pack;\n+\tif (keep_pack)\n+\t\tunpack_limit = 0;\n+\tuse_thin_pack = _use_thin_pack;\n+\tfetch_all = _fetch_all;\n+\tverbose = _verbose;\n+\tdepth = _depth;\n+\tno_progress = _no_progress;\n+\n+#if 0\n+\tgit_config(fetch_pack_config);\n+\n+\tif (0 <= transfer_unpack_limit)\n+\t\tunpack_limit = transfer_unpack_limit;\n+\telse if (0 <= fetch_unpack_limit)\n+\t\tunpack_limit = fetch_unpack_limit;\n+#endif\n+}\n+\n+int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n {\n \tint i, ret, nr_heads;\n+\tstruct ref *ref;\n \tchar *dest = NULL, **heads;\n-\tint fd[2];\n-\tpid_t pid;\n-\tstruct stat st;\n \n-\tsetup_git_directory();\n \tgit_config(fetch_pack_config);\n \n \tif (0 <= transfer_unpack_limit)\n@@ -682,7 +705,7 @@ int main(int argc, char **argv)\n \tnr_heads = 0;\n \theads = NULL;\n \tfor (i = 1; i < argc; i++) {\n-\t\tchar *arg = argv[i];\n+\t\tconst char *arg = argv[i];\n \n \t\tif (*arg == '-') {\n \t\t\tif (!prefixcmp(arg, \"--upload-pack=\")) {\n@@ -716,8 +739,6 @@ int main(int argc, char **argv)\n \t\t\t}\n \t\t\tif (!prefixcmp(arg, \"--depth=\")) {\n \t\t\t\tdepth = strtol(arg + 8, NULL, 0);\n-\t\t\t\tif (stat(git_path(\"shallow\"), &st))\n-\t\t\t\t\tst.st_mtime = 0;\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(\"--no-progress\", arg)) {\n@@ -726,22 +747,53 @@ int main(int argc, char **argv)\n \t\t\t}\n \t\t\tusage(fetch_pack_usage);\n \t\t}\n-\t\tdest = arg;\n-\t\theads = argv + i + 1;\n+\t\tdest = (char *)arg;\n+\t\theads = (char **)(argv + i + 1);\n \t\tnr_heads = argc - i - 1;\n \t\tbreak;\n \t}\n \tif (!dest)\n \t\tusage(fetch_pack_usage);\n-\tpid = git_connect(fd, dest, uploadpack, verbose ? CONNECT_VERBOSE : 0);\n+\n+\tref = fetch_pack(dest, nr_heads, heads);\n+\n+\tret = !ref;\n+\n+\twhile (ref) {\n+\t\tprintf(\"%s %s\\n\",\n+\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n+\t\tref = ref->next;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+struct ref *fetch_pack(const char *dest, int nr_heads, char **heads)\n+{\n+\tint i, ret;\n+\tint fd[2];\n+\tpid_t pid;\n+\tstruct ref *ref;\n+\tstruct stat st;\n+\n+\tif (depth > 0) {\n+\t\tif (stat(git_path(\"shallow\"), &st))\n+\t\t\tst.st_mtime = 0;\n+\t}\n+\n+\n+\tprintf(\"connect to %s\\n\", dest);\n+\n+\tpid = git_connect(fd, (char *)dest, uploadpack,\n+                          verbose ? CONNECT_VERBOSE : 0);\n \tif (pid < 0)\n-\t\treturn 1;\n+\t\treturn NULL;\n \tif (heads && nr_heads)\n \t\tnr_heads = remove_duplicates(nr_heads, heads);\n-\tret = fetch_pack(fd, nr_heads, heads);\n+\tref = do_fetch_pack(fd, nr_heads, heads);\n \tclose(fd[0]);\n \tclose(fd[1]);\n-\tret |= finish_connect(pid);\n+\tret = finish_connect(pid);\n \n \tif (!ret && nr_heads) {\n \t\t/* If the heads to pull were given, we should have\n@@ -785,5 +837,8 @@ int main(int argc, char **argv)\n \t\t}\n \t}\n \n-\treturn !!ret;\n+\tif (ret)\n+\t\tref = NULL;\n+\n+\treturn ref;\n }\ndiff --git a/builtin.h b/builtin.h\nindex 661a92f..8fa38d4 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -31,6 +31,7 @@ extern int cmd_diff_files(int argc, const char **argv, const char *prefix);\n extern int cmd_diff_index(int argc, const char **argv, const char *prefix);\n extern int cmd_diff(int argc, const char **argv, const char *prefix);\n extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);\n+extern int cmd_fetch_pack(int argc, const char **argv, const char *prefix);\n extern int cmd_fetch__tool(int argc, const char **argv, const char *prefix);\n extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);\n extern int cmd_for_each_ref(int argc, const char **argv, const char *prefix);\ndiff --git a/fetch-pack.h b/fetch-pack.h\nnew file mode 100644\nindex 0000000..a317b70\n--- /dev/null\n+++ b/fetch-pack.h\n@@ -0,0 +1,15 @@\n+#ifndef FETCH_PACK_API\n+#define FETCH_PACK_API\n+\n+void setup_fetch_pack(const char *_uploadpack,\n+\t\t      int _quiet,\n+\t\t      int _keep_pack,\n+\t\t      int _use_thin_pack,\n+\t\t      int _fetch_all,\n+\t\t      int _verbose,\n+\t\t      int _depth,\n+\t\t      int _no_progress);\n+\n+struct ref *fetch_pack(const char *dest, int nr_heads, char **heads);\n+\n+#endif\ndiff --git a/git.c b/git.c\nindex b949cbb..df45161 100644\n--- a/git.c\n+++ b/git.c\n@@ -307,6 +307,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"diff-files\", cmd_diff_files },\n \t\t{ \"diff-index\", cmd_diff_index, RUN_SETUP },\n \t\t{ \"diff-tree\", cmd_diff_tree, RUN_SETUP },\n+\t\t{ \"fetch-pack\", cmd_fetch_pack, RUN_SETUP },\n \t\t{ \"fetch--tool\", cmd_fetch__tool, RUN_SETUP },\n \t\t{ \"fmt-merge-msg\", cmd_fmt_merge_msg, RUN_SETUP },\n \t\t{ \"for-each-ref\", cmd_for_each_ref, RUN_SETUP },\n-- \n1.5.2.2.1399.g097d5-dirty\n"},{"id":"46804","messageId":"7vsl7yzfkg.fsf@assigned-by-dhcp.cox.net","threadId":"8932","inReplyTo":"Pine.LNX.4.64.0707081551120.6977@iabervon.org","subject":"Re: [PATCH] Make fetch-pack a builtin with an internal API","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-08T22:38:39Z","receivedAt":"2007-07-08T22:38:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> In addition to making fetch-pack a builtin, this allows it to be called \n> directly from other built-in code without generating and parsing argument \n> lists, which will be useful for builtin-fetch.\n>\n> Incidently, it makes git-fetch-pack not output lists of what it fetched \n> when it fails.\n\nThat sounds sensible.\n\nHmmm.  incidentally it seems to do a bit more than that.\n\n> @@ -663,15 +659,42 @@ static int fetch_pack_config(const char *var, const char *value)\n>  \n>  static struct lock_file lock;\n>  \n> -int main(int argc, char **argv)\n> +void setup_fetch_pack(const char *_uploadpack,\n> ...\n> +#if 0\n> +\tgit_config(fetch_pack_config);\n> +\n> +\tif (0 <= transfer_unpack_limit)\n> +\t\tunpack_limit = transfer_unpack_limit;\n> +\telse if (0 <= fetch_unpack_limit)\n> +\t\tunpack_limit = fetch_unpack_limit;\n> +#endif\n> +}\n\nThis has been moved elsewhere?  I do not see how the code now\nhonors the configuration.\n"},{"id":"46806","messageId":"Pine.LNX.4.64.0707081841160.6977@iabervon.org","threadId":"8932","inReplyTo":"7vsl7yzfkg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make fetch-pack a builtin with an internal API","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-07-08T23:12:18Z","receivedAt":"2007-07-08T23:12:18Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sun, 8 Jul 2007, Junio C Hamano wrote:\n\n> Daniel Barkalow <barkalow@iabervon.org> writes:\n> \n> > In addition to making fetch-pack a builtin, this allows it to be called \n> > directly from other built-in code without generating and parsing argument \n> > lists, which will be useful for builtin-fetch.\n> >\n> > Incidently, it makes git-fetch-pack not output lists of what it fetched \n> > when it fails.\n> \n> That sounds sensible.\n> \n> Hmmm.  incidentally it seems to do a bit more than that.\n> \n> > @@ -663,15 +659,42 @@ static int fetch_pack_config(const char *var, const char *value)\n> >  \n> >  static struct lock_file lock;\n> >  \n> > -int main(int argc, char **argv)\n> > +void setup_fetch_pack(const char *_uploadpack,\n> > ...\n> > +#if 0\n> > +\tgit_config(fetch_pack_config);\n> > +\n> > +\tif (0 <= transfer_unpack_limit)\n> > +\t\tunpack_limit = transfer_unpack_limit;\n> > +\telse if (0 <= fetch_unpack_limit)\n> > +\t\tunpack_limit = fetch_unpack_limit;\n> > +#endif\n> > +}\n> \n> This has been moved elsewhere?  I do not see how the code now\n> honors the configuration.\n\nIt's at the beginning of cmd_fetch_pack() for the case of running it from \nthe command line, but it should probably also be an argument to \nsetup_fetch_pack(). Got it added to my revisions, and I'll send out a new \nversion once people have looked over this further.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}