transport-helper: implement marks location as capability
Now that the gitdir location is exported as an environment variable this can be implemented elegantly without requiring any explicit flushes nor an ad-hoc exchange of values. Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sverre Rabbelier committed
Jul 16, 2011 at 15:03 UTC
a515ebe9f1ac9bc248c12a291dc008570de505ca
2 files changed
+29
-42
git-remote-testgit.py
+11
-13
@@ -72,6 +72,17 @@ def do_capabilities(repo, args):
72
print "export"
73
print "refspec refs/heads/*:%s*" % repo.prefix
74
75
+ dirname = repo.get_base_path(repo.gitdir)
76
+
77
+ if not os.path.exists(dirname):
78
+ os.makedirs(dirname)
79
+
80
+ path = os.path.join(dirname, 'testgit.marks')
81
+
82
+ print "*export-marks %s" % path
83
+ if os.path.exists(path):
84
+ print "*import-marks %s" % path
85
+
86
print # end capabilities
87
88
@@ -147,19 +158,6 @@ def do_export(repo, args):
158
if not repo.gitdir:
159
die("Need gitdir to export")
160
150
- dirname = repo.get_base_path(repo.gitdir)
151
-
152
- if not os.path.exists(dirname):
153
- os.makedirs(dirname)
154
-
155
- path = os.path.join(dirname, 'testgit.marks')
156
- print path
157
- if os.path.exists(path):
158
- print path
159
- else:
160
- print ""
161
- sys.stdout.flush()
162
-
161
update_local_repo(repo)
162
changed = repo.importer.do_import(repo.gitdir)
163
transport-helper.c
+18
-29
@@ -23,6 +23,8 @@ struct helper_data {
23
push : 1,
24
connect : 1,
25
no_disconnect_req : 1;
26
+ char *export_marks;
27
+ char *import_marks;
28
/* These go from remote name (as in "list") to private name */
29
struct refspec *refspecs;
30
int refspec_nr;
@@ -184,6 +186,16 @@ static struct child_process *get_helper(struct transport *transport)
186
refspecs[refspec_nr++] = strdup(capname + strlen("refspec "));
187
} else if (!strcmp(capname, "connect")) {
188
data->connect = 1;
189
+ } else if (!prefixcmp(capname, "export-marks ")) {
190
+ struct strbuf arg = STRBUF_INIT;
191
+ strbuf_addstr(&arg, "--export-marks=");
192
+ strbuf_addstr(&arg, capname + strlen("export-marks "));
193
+ data->export_marks = strbuf_detach(&arg, NULL);
194
+ } else if (!prefixcmp(capname, "import-marks")) {
195
+ struct strbuf arg = STRBUF_INIT;
196
+ strbuf_addstr(&arg, "--import-marks=");
197
+ strbuf_addstr(&arg, capname + strlen("import-marks "));
198
+ data->import_marks = strbuf_detach(&arg, NULL);
199
} else if (mandatory) {
200
die("Unknown mandatory capability %s. This remote "
201
"helper probably needs newer version of Git.\n",
@@ -369,10 +381,9 @@ static int get_importer(struct transport *transport, struct child_process *fasti
381
382
static int get_exporter(struct transport *transport,
383
struct child_process *fastexport,
372
- const char *export_marks,
373
- const char *import_marks,
384
struct string_list *revlist_args)
385
{
386
+ struct helper_data *data = transport->data;
387
struct child_process *helper = get_helper(transport);
388
int argc = 0, i;
389
memset(fastexport, 0, sizeof(*fastexport));
@@ -383,10 +394,10 @@ static int get_exporter(struct transport *transport,
394
fastexport->argv = xcalloc(5 + revlist_args->nr, sizeof(*fastexport->argv));
395
fastexport->argv[argc++] = "fast-export";
396
fastexport->argv[argc++] = "--use-done-feature";
386
- if (export_marks)
387
- fastexport->argv[argc++] = export_marks;
388
- if (import_marks)
389
- fastexport->argv[argc++] = import_marks;
397
+ if (data->export_marks)
398
+ fastexport->argv[argc++] = data->export_marks;
399
+ if (data->import_marks)
400
+ fastexport->argv[argc++] = data->import_marks;
401
402
for (i = 0; i < revlist_args->nr; i++)
403
fastexport->argv[argc++] = revlist_args->items[i].string;
@@ -713,7 +724,6 @@ static int push_refs_with_export(struct transport *transport,
724
struct ref *ref;
725
struct child_process *helper, exporter;
726
struct helper_data *data = transport->data;
716
- char *export_marks = NULL, *import_marks = NULL;
727
struct string_list revlist_args = STRING_LIST_INIT_NODUP;
728
struct strbuf buf = STRBUF_INIT;
729
@@ -721,26 +731,6 @@ static int push_refs_with_export(struct transport *transport,
731
732
write_constant(helper->in, "export\n");
733
724
- recvline(data, &buf);
725
- if (debug)
726
- fprintf(stderr, "Debug: Got export_marks '%s'\n", buf.buf);
727
- if (buf.len) {
728
- struct strbuf arg = STRBUF_INIT;
729
- strbuf_addstr(&arg, "--export-marks=");
730
- strbuf_addbuf(&arg, &buf);
731
- export_marks = strbuf_detach(&arg, NULL);
732
- }
733
-
734
- recvline(data, &buf);
735
- if (debug)
736
- fprintf(stderr, "Debug: Got import_marks '%s'\n", buf.buf);
737
- if (buf.len) {
738
- struct strbuf arg = STRBUF_INIT;
739
- strbuf_addstr(&arg, "--import-marks=");
740
- strbuf_addbuf(&arg, &buf);
741
- import_marks = strbuf_detach(&arg, NULL);
742
- }
743
-
734
strbuf_reset(&buf);
735
736
for (ref = remote_refs; ref; ref = ref->next) {
@@ -761,8 +751,7 @@ static int push_refs_with_export(struct transport *transport,
751
752
}
753
764
- if (get_exporter(transport, &exporter,
765
- export_marks, import_marks, &revlist_args))
754
+ if (get_exporter(transport, &exporter, &revlist_args))
755
die("Couldn't run fast-export");
756
757
if (finish_command(&exporter))