detect unknown repository format extensions (such as sha256 format) ok millert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
diff --git a/include/got_error.h b/include/got_error.h
index 0f3e07a..5fa8ffa 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -144,6 +144,7 @@
#define GOT_ERR_PARSE_CONFIG 127
#define GOT_ERR_NO_CONFIG_FILE 128
#define GOT_ERR_BAD_SYMLINK 129
+#define GOT_ERR_GIT_REPO_EXT 130
static const struct got_error {
int code;
@@ -295,6 +296,7 @@ static const struct got_error {
{ GOT_ERR_NO_CONFIG_FILE, "configuration file doesn't exit" },
{ GOT_ERR_BAD_SYMLINK, "symbolic link points outside of paths under "
"version control" },
+ { GOT_ERR_GIT_REPO_EXT, "unsupported repository format extension" },
};
/*
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index 6c638e9..f4815b5 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -141,6 +141,7 @@ enum got_imsg_type {
/* Messages related to gitconfig files. */
GOT_IMSG_GITCONFIG_PARSE_REQUEST,
GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
+ GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
@@ -460,6 +461,8 @@ const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
int);
const struct got_error *
got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
+ struct imsgbuf *);
const struct got_error *got_privsep_send_gitconfig_author_name_req(
struct imsgbuf *);
const struct got_error *got_privsep_send_gitconfig_author_email_req(
diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index 87f2558..d2a6b78 100644
--- a/lib/got_lib_repository.h
+++ b/lib/got_lib_repository.h
@@ -64,6 +64,8 @@ struct got_repository {
int ngitconfig_remotes;
struct got_remote_repo *gitconfig_remotes;
char *gitconfig_owner;
+ char **extensions;
+ int nextensions;
/* Settings read from got.conf. */
struct got_gotconfig *gotconfig;
diff --git a/lib/privsep.c b/lib/privsep.c
index d15fdd1..55eb3a4 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -1672,6 +1672,19 @@ got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *ibuf)
}
const struct got_error *
+got_privsep_send_gitconfig_repository_extensions_req(struct imsgbuf *ibuf)
+{
+ if (imsg_compose(ibuf,
+ GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST, 0, 0, -1,
+ NULL, 0) == -1)
+ return got_error_from_errno("imsg_compose "
+ "GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST");
+
+ return flush_imsg(ibuf);
+}
+
+
+const struct got_error *
got_privsep_send_gitconfig_author_name_req(struct imsgbuf *ibuf)
{
if (imsg_compose(ibuf,
diff --git a/lib/repository.c b/lib/repository.c
index 036305e..3c8f844 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -377,7 +377,7 @@ static const struct got_error *
parse_gitconfig_file(int *gitconfig_repository_format_version,
char **gitconfig_author_name, char **gitconfig_author_email,
struct got_remote_repo **remotes, int *nremotes,
- char **gitconfig_owner,
+ char **gitconfig_owner, char ***extensions, int *nextensions,
const char *gitconfig_path)
{
const struct got_error *err = NULL, *child_err = NULL;
@@ -387,6 +387,10 @@ parse_gitconfig_file(int *gitconfig_repository_format_version,
struct imsgbuf *ibuf;
*gitconfig_repository_format_version = 0;
+ if (extensions)
+ *extensions = NULL;
+ if (nextensions)
+ *nextensions = 0;
*gitconfig_author_name = NULL;
*gitconfig_author_email = NULL;
if (remotes)
@@ -445,6 +449,32 @@ parse_gitconfig_file(int *gitconfig_repository_format_version,
if (err)
goto done;
+ if (extensions && nextensions) {
+ err = got_privsep_send_gitconfig_repository_extensions_req(
+ ibuf);
+ if (err)
+ goto done;
+ err = got_privsep_recv_gitconfig_int(nextensions, ibuf);
+ if (err)
+ goto done;
+ if (*nextensions > 0) {
+ int i;
+ *extensions = calloc(*nextensions, sizeof(char *));
+ if (*extensions == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+ for (i = 0; i < *nextensions; i++) {
+ char *ext;
+ err = got_privsep_recv_gitconfig_str(&ext,
+ ibuf);
+ if (err)
+ goto done;
+ (*extensions)[i] = ext;
+ }
+ }
+ }
+
err = got_privsep_send_gitconfig_author_name_req(ibuf);
if (err)
goto done;
@@ -509,7 +539,7 @@ read_gitconfig(struct got_repository *repo, const char *global_gitconfig_path)
err = parse_gitconfig_file(&dummy_repo_version,
&repo->global_gitconfig_author_name,
&repo->global_gitconfig_author_email,
- NULL, NULL, NULL, global_gitconfig_path);
+ NULL, NULL, NULL, NULL, NULL, global_gitconfig_path);
if (err)
return err;
}
@@ -522,7 +552,8 @@ read_gitconfig(struct got_repository *repo, const char *global_gitconfig_path)
err = parse_gitconfig_file(&repo->gitconfig_repository_format_version,
&repo->gitconfig_author_name, &repo->gitconfig_author_email,
&repo->gitconfig_remotes, &repo->ngitconfig_remotes,
- &repo->gitconfig_owner, repo_gitconfig_path);
+ &repo->gitconfig_owner, &repo->extensions, &repo->nextensions,
+ repo_gitconfig_path);
if (err)
goto done;
done:
@@ -545,6 +576,13 @@ read_gotconfig(struct got_repository *repo)
return err;
}
+/* Supported repository format extensions. */
+static const char *repo_extensions[] = {
+ "noop", /* Got supports repository format version 1. */
+ "preciousObjects", /* Got has no garbage collection yet. */
+ "worktreeConfig", /* Got does not care about Git work trees. */
+};
+
const struct got_error *
got_repo_open(struct got_repository **repop, const char *path,
const char *global_gitconfig_path)
@@ -626,6 +664,20 @@ got_repo_open(struct got_repository **repop, const char *path,
goto done;
if (repo->gitconfig_repository_format_version != 0)
err = got_error_path(path, GOT_ERR_GIT_REPO_FORMAT);
+ for (i = 0; i < repo->nextensions; i++) {
+ char *ext = repo->extensions[i];
+ int j, supported = 0;
+ for (j = 0; j < nitems(repo_extensions); j++) {
+ if (strcmp(ext, repo_extensions[j]) == 0) {
+ supported = 1;
+ break;
+ }
+ }
+ if (!supported) {
+ err = got_error_path(ext, GOT_ERR_GIT_REPO_EXT);
+ goto done;
+ }
+ }
done:
if (err)
got_repo_close(repo);
@@ -684,6 +736,9 @@ got_repo_close(struct got_repository *repo)
for (i = 0; i < repo->ngitconfig_remotes; i++)
got_repo_free_remote_repo_data(&repo->gitconfig_remotes[i]);
free(repo->gitconfig_remotes);
+ for (i = 0; i < repo->nextensions; i++)
+ free(repo->extensions[i]);
+ free(repo->extensions);
free(repo);
return err;
diff --git a/libexec/got-read-gitconfig/got-read-gitconfig.c b/libexec/got-read-gitconfig/got-read-gitconfig.c
index e24545d..b0457c7 100644
--- a/libexec/got-read-gitconfig/got-read-gitconfig.c
+++ b/libexec/got-read-gitconfig/got-read-gitconfig.c
@@ -159,6 +159,14 @@ send_gitconfig_remotes(struct imsgbuf *ibuf, struct got_remote_repo *remotes,
return NULL;
}
+static int
+get_boolean_val(char *val)
+{
+ return (strcasecmp(val, "true") == 0 ||
+ strcasecmp(val, "on") == 0 ||
+ strcasecmp(val, "yes") == 0 ||
+ strcmp(val, "1") == 0);
+}
static const struct got_error *
gitconfig_remotes_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
@@ -220,11 +228,7 @@ gitconfig_remotes_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
remotes[i].mirror_references = 0;
mirror = got_gitconfig_get_str(gitconfig, node->field,
"mirror");
- if (mirror != NULL &&
- (strcasecmp(mirror, "true") == 0 ||
- strcasecmp(mirror, "on") == 0 ||
- strcasecmp(mirror, "yes") == 0 ||
- strcmp(mirror, "1") == 0))
+ if (mirror != NULL && get_boolean_val(mirror))
remotes[i].mirror_references = 1;
i++;
@@ -254,6 +258,48 @@ gitconfig_owner_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
return send_gitconfig_str(ibuf, value);
}
+static const struct got_error *
+gitconfig_extensions_request(struct imsgbuf *ibuf,
+ struct got_gitconfig *gitconfig)
+{
+ const struct got_error *err = NULL;
+ struct got_gitconfig_list *tags;
+ struct got_gitconfig_list_node *node;
+ int nextensions = 0;
+ char *val;
+
+ if (gitconfig == NULL)
+ return got_error(GOT_ERR_PRIVSEP_MSG);
+
+ tags = got_gitconfig_get_tag_list(gitconfig, "extensions");
+ if (tags == NULL)
+ return send_gitconfig_int(ibuf, 0);
+
+ TAILQ_FOREACH(node, &tags->fields, link) {
+ val = got_gitconfig_get_str(gitconfig, "extensions",
+ node->field);
+ if (get_boolean_val(val))
+ nextensions++;
+ }
+
+ err = send_gitconfig_int(ibuf, nextensions);
+ if (err)
+ goto done;
+
+ TAILQ_FOREACH(node, &tags->fields, link) {
+ val = got_gitconfig_get_str(gitconfig, "extensions",
+ node->field);
+ if (get_boolean_val(val)) {
+ err = send_gitconfig_str(ibuf, node->field);
+ if (err)
+ goto done;
+ }
+ }
+done:
+ got_gitconfig_free_list(tags);
+ return err;
+}
+
int
main(int argc, char *argv[])
{
@@ -321,6 +367,9 @@ main(int argc, char *argv[])
err = gitconfig_num_request(&ibuf, gitconfig, "core",
"repositoryformatversion", 0);
break;
+ case GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST:
+ err = gitconfig_extensions_request(&ibuf, gitconfig);
+ break;
case GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST:
err = gitconfig_str_request(&ibuf, gitconfig, "user",
"name");
diff --git a/regress/cmdline/checkout.sh b/regress/cmdline/checkout.sh
index 5e018f6..0db983c 100755
--- a/regress/cmdline/checkout.sh
+++ b/regress/cmdline/checkout.sh
@@ -756,6 +756,34 @@ test_checkout_symlink_relative_wtpath() {
test_done "$testroot" "$ret"
}
+test_checkout_repo_with_unknown_extension() {
+ local testroot=`test_init checkout_repo_with_unknown_extension`
+
+ (cd $testroot/repo &&
+ git config --add extensions.badExtension true)
+ (cd $testroot/repo &&
+ git config --add extensions.otherBadExtension 0)
+
+ echo "got: badExtension: unsupported repository format extension" \
+ > $testroot/stderr.expected
+ got checkout $testroot/repo $testroot/wt \
+ > $testroot/stdout 2> $testroot/stderr
+
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got checkout command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ fi
+ test_done "$testroot" "$ret"
+}
+
test_parseargs "$@"
run_test test_checkout_basic
run_test test_checkout_dir_exists
@@ -768,3 +796,4 @@ run_test test_checkout_read_only
run_test test_checkout_into_nonempty_dir
run_test test_checkout_symlink
run_test test_checkout_symlink_relative_wtpath
+run_test test_checkout_repo_with_unknown_extension