Skip to content

Commit 5e32010

Browse files
committed
...
1 parent c183443 commit 5e32010

2 files changed

Lines changed: 71 additions & 10 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ CPPFLAGS := -Igit
1616

1717
all: git-remote-incrypt man
1818

19+
COMPILER_FEATURES := $(shell git/detect-compiler $(CC))
20+
include git/config.mak.dev
21+
CFLAGS += $(DEVELOPER_CFLAGS)
22+
1923
ifndef NODOC
2024
man: man1/git-incrypt.1
2125
testman: man

incrypt.c

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8 -*- */
2+
13
#define USE_THE_REPOSITORY_VARIABLE
24

35
#include "git-compat-util.h"
@@ -8,7 +10,7 @@
810
#include "setup.h"
911
#include "trace2.h"
1012

11-
static struct remote* remote;
13+
static struct remote *remote;
1214
static const char* url;
1315

1416
struct options {
@@ -23,19 +25,21 @@ static int set_option(const char *name, size_t namelen, const char *value)
2325
if (!strncmp(name, "verbosity", namelen)) {
2426
char *end;
2527
int v = strtol(value, &end, 10);
26-
if (end == value || *end)
28+
if (value == end || *end)
2729
return -1;
2830
options.verbosity = v;
2931
return 0;
30-
} else if (!strncmp(name, "progress", namelen)) {
32+
}
33+
else if (!strncmp(name, "progress", namelen)) {
3134
if (!strcmp(value, "true"))
3235
options.progress = 1;
3336
else if (!strcmp(value, "false"))
3437
options.progress = 0;
3538
else
3639
return -1;
3740
return 0;
38-
} else if (!strncmp(name, "followtags", namelen)) {
41+
}
42+
else if (!strncmp(name, "followtags", namelen)) {
3943
return 0;
4044
} else if (!strncmp(name, "atomic", namelen)) {
4145
if (!strcmp(value, "true"))
@@ -46,12 +50,34 @@ static int set_option(const char *name, size_t namelen, const char *value)
4650
return -1;
4751
return 0;
4852
} else {
49-
return 1;
53+
return 1 /* unsupported */;
54+
}
55+
}
56+
57+
static struct ref *get_refs(void)
58+
{
59+
return NULL;
60+
}
61+
62+
static void output_refs(struct ref *refs)
63+
{
64+
struct ref *posn;
65+
for (posn = refs; posn; posn = posn->next) {
66+
if (posn->symref)
67+
printf("@%s %s\n", posn->symref, posn->name);
68+
else
69+
printf("%s %s\n", hash_to_hex_algop(posn->old_oid.hash,
70+
&hash_algos[GIT_HASH_SHA1]),
71+
posn->name);
5072
}
73+
printf("\n");
74+
fflush(stdout);
5175
}
5276

5377
static int fetch(int nr_heads, struct ref **to_fetch)
5478
{
79+
(void)nr_heads;
80+
(void)to_fetch;
5581
return 0;
5682
}
5783

@@ -77,7 +103,7 @@ static void parse_fetch(struct strbuf *buf)
77103
else if (!*q)
78104
name = "";
79105
else
80-
die(_("protocol error: expected sha/ref, got '%s'"), q);
106+
die(_("protocol error: expected sha/ref, got '%s'"), p);
81107

82108
ref = alloc_ref(name);
83109
oidcpy(&ref->old_oid, &old_oid);
@@ -89,7 +115,7 @@ static void parse_fetch(struct strbuf *buf)
89115
to_fetch[nr_heads++] = ref;
90116
}
91117
else
92-
die(_("inctypt does not support %s"), buf->buf);
118+
die(_("remote-inctypt does not support %s"), buf->buf);
93119

94120
strbuf_reset(buf);
95121
if (strbuf_getline_lf(buf, stdin) == EOF)
@@ -99,7 +125,7 @@ static void parse_fetch(struct strbuf *buf)
99125
} while (1);
100126

101127
if (fetch(nr_heads, to_fetch))
102-
exit(128);
128+
exit(128); /* error already reported */
103129
free_refs(list_head);
104130
free(to_fetch);
105131

@@ -108,7 +134,15 @@ static void parse_fetch(struct strbuf *buf)
108134
strbuf_reset(buf);
109135
}
110136

111-
int cmd_main(int argc, const char **argv)
137+
static int tool_main(int argc, const char **argv)
138+
{
139+
(void)argc;
140+
(void)argv;
141+
error(_("tool not implemented"));
142+
return 1;
143+
}
144+
145+
static int remote_main(int argc, const char **argv)
112146
{
113147
struct strbuf buf = STRBUF_INIT;
114148
int nongit;
@@ -151,13 +185,16 @@ int cmd_main(int argc, const char **argv)
151185
}
152186
parse_fetch(&buf);
153187

188+
} else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
189+
output_refs(get_refs());
190+
154191
} else if (skip_prefix(buf.buf, "option ", &arg)) {
155192
const char *value = strchrnul(arg, ' ');
156193
size_t arglen = value - arg;
157194
int result;
158195

159196
if (*value)
160-
value++;
197+
value++; /* skip over SP */
161198
else
162199
value = "true";
163200

@@ -183,6 +220,26 @@ int cmd_main(int argc, const char **argv)
183220
strbuf_reset(&buf);
184221
} while (1);
185222

223+
ret = 0;
186224
cleanup:
225+
strbuf_release(&buf);
226+
187227
return ret;
188228
}
229+
230+
int cmd_main(int argc, const char **argv)
231+
{
232+
const char* base = strrchr(argv[0], '/');
233+
if (base)
234+
++base;
235+
else
236+
base = argv[0];
237+
if (!strcmp(base, "git-remote-incrypt"))
238+
return remote_main(argc, argv);
239+
else if (!strcmp(base, "git-incrypt"))
240+
return tool_main(argc, argv);
241+
else {
242+
error(_("command not implemented: %s"), base);
243+
return 1;
244+
}
245+
}

0 commit comments

Comments
 (0)