Skip to content

Commit a515ebe

Browse files
SRabbeliergitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d2ec30 commit a515ebe

File tree

2 files changed

+29
-42
lines changed

2 files changed

+29
-42
lines changed

git-remote-testgit.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ def do_capabilities(repo, args):
7272
print "export"
7373
print "refspec refs/heads/*:%s*" % repo.prefix
7474

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+
7586
print # end capabilities
7687

7788

@@ -147,19 +158,6 @@ def do_export(repo, args):
147158
if not repo.gitdir:
148159
die("Need gitdir to export")
149160

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-
163161
update_local_repo(repo)
164162
changed = repo.importer.do_import(repo.gitdir)
165163

transport-helper.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ struct helper_data {
2323
push : 1,
2424
connect : 1,
2525
no_disconnect_req : 1;
26+
char *export_marks;
27+
char *import_marks;
2628
/* These go from remote name (as in "list") to private name */
2729
struct refspec *refspecs;
2830
int refspec_nr;
@@ -184,6 +186,16 @@ static struct child_process *get_helper(struct transport *transport)
184186
refspecs[refspec_nr++] = strdup(capname + strlen("refspec "));
185187
} else if (!strcmp(capname, "connect")) {
186188
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);
187199
} else if (mandatory) {
188200
die("Unknown mandatory capability %s. This remote "
189201
"helper probably needs newer version of Git.\n",
@@ -369,10 +381,9 @@ static int get_importer(struct transport *transport, struct child_process *fasti
369381

370382
static int get_exporter(struct transport *transport,
371383
struct child_process *fastexport,
372-
const char *export_marks,
373-
const char *import_marks,
374384
struct string_list *revlist_args)
375385
{
386+
struct helper_data *data = transport->data;
376387
struct child_process *helper = get_helper(transport);
377388
int argc = 0, i;
378389
memset(fastexport, 0, sizeof(*fastexport));
@@ -383,10 +394,10 @@ static int get_exporter(struct transport *transport,
383394
fastexport->argv = xcalloc(5 + revlist_args->nr, sizeof(*fastexport->argv));
384395
fastexport->argv[argc++] = "fast-export";
385396
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;
390401

391402
for (i = 0; i < revlist_args->nr; i++)
392403
fastexport->argv[argc++] = revlist_args->items[i].string;
@@ -713,34 +724,13 @@ static int push_refs_with_export(struct transport *transport,
713724
struct ref *ref;
714725
struct child_process *helper, exporter;
715726
struct helper_data *data = transport->data;
716-
char *export_marks = NULL, *import_marks = NULL;
717727
struct string_list revlist_args = STRING_LIST_INIT_NODUP;
718728
struct strbuf buf = STRBUF_INIT;
719729

720730
helper = get_helper(transport);
721731

722732
write_constant(helper->in, "export\n");
723733

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-
744734
strbuf_reset(&buf);
745735

746736
for (ref = remote_refs; ref; ref = ref->next) {
@@ -761,8 +751,7 @@ static int push_refs_with_export(struct transport *transport,
761751

762752
}
763753

764-
if (get_exporter(transport, &exporter,
765-
export_marks, import_marks, &revlist_args))
754+
if (get_exporter(transport, &exporter, &revlist_args))
766755
die("Couldn't run fast-export");
767756

768757
if (finish_command(&exporter))

0 commit comments

Comments
 (0)