From: Patryk Obara <patryk.obara@gmail.com>
To: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"Jeff King" <peff@peff.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: Johannes.Schindelin@gmx.de, sbeller@google.com,
"brian m . carlson" <sandals@crustytoothpaste.net>
Subject: [PATCH v2 1/1] setup: recognise extensions.objectFormat
Date: Sun, 28 Jan 2018 01:36:17 +0100 [thread overview]
Message-ID: <e430ad029facdd6209927d352f0e7545cdd0e435.1517098675.git.patryk.obara@gmail.com> (raw)
In-Reply-To: <cover.1517098675.git.patryk.obara@gmail.com>
In-Reply-To: <cover.1517098675.git.patryk.obara@gmail.com>
This extension selects which hashing algorithm from vtable should be
used for reading and writing objects in the object store. At the moment
supports only single value (sha-1).
In case value of objectFormat is an unknown hashing algorithm, Git
command will fail with following message:
fatal: unknown repository extensions found:
objectformat = <value>
To indicate, that this specific objectFormat value is not recognised.
The objectFormat extension is not allowed in repository marked as
version 0 to prevent any possibility of accidentally writing a NewHash
object in the sha-1 object store. This extension behaviour is different
than preciousObjects extension (which is allowed in repo version 0).
Add tests and documentation note about new extension.
Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
---
Documentation/technical/repository-version.txt | 12 ++++++++++++
setup.c | 27 ++++++++++++++++++++++++++
t/t1302-repo-version.sh | 15 ++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/Documentation/technical/repository-version.txt b/Documentation/technical/repository-version.txt
index 00ad37986e..7e2b832603 100644
--- a/Documentation/technical/repository-version.txt
+++ b/Documentation/technical/repository-version.txt
@@ -86,3 +86,15 @@ for testing format-1 compatibility.
When the config key `extensions.preciousObjects` is set to `true`,
objects in the repository MUST NOT be deleted (e.g., by `git-prune` or
`git repack -d`).
+
+`objectFormat`
+~~~~~~~~~~~~~~
+
+This extension instructs Git to use a specific algorithm for addressing
+and interpreting objects in the object store. Currently, the only
+supported object format is `sha-1`. At the moment, the primary purpose
+of this option is to enable Git developers to experiment with different
+hashing algorithms without re-compilation of git client.
+
+See `hash-function-transition.txt` document for more detailed explanation.
+
diff --git a/setup.c b/setup.c
index 8cc34186ce..9b9993a14e 100644
--- a/setup.c
+++ b/setup.c
@@ -405,6 +405,31 @@ void setup_work_tree(void)
initialized = 1;
}
+static int find_object_format(const char *value)
+{
+ int i;
+ for (i = GIT_HASH_SHA1; i < GIT_HASH_NALGOS; ++i) {
+ if (strcmp(value, hash_algos[i].name) == 0)
+ return i;
+ }
+ return GIT_HASH_UNKNOWN;
+}
+
+static void detect_object_format(struct repository_format *data,
+ const char *value)
+{
+ if (data->version == 0)
+ die(_("invalid repository format version '%d'"), data->version);
+
+ data->hash_algo = find_object_format(value);
+ if (data->hash_algo == GIT_HASH_UNKNOWN) {
+ struct strbuf object_format = STRBUF_INIT;
+ strbuf_addf(&object_format, "objectformat = %s", value);
+ string_list_append(&data->unknown_extensions, object_format.buf);
+ strbuf_release(&object_format);
+ }
+}
+
static int check_repo_format(const char *var, const char *value, void *vdata)
{
struct repository_format *data = vdata;
@@ -422,6 +447,8 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
;
else if (!strcmp(ext, "preciousobjects"))
data->precious_objects = git_config_bool(var, value);
+ else if (!strcmp(ext, "objectformat"))
+ detect_object_format(data, value);
else
string_list_append(&data->unknown_extensions, ext);
} else if (strcmp(var, "core.bare") == 0) {
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index ce4cff13bb..227b397ff2 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -107,4 +107,19 @@ test_expect_success 'gc runs without complaint' '
git gc
'
+test_expect_success 'object-format not allowed in repo version=0' '
+ mkconfig 0 "objectFormat = sha-1" >.git/config &&
+ check_abort
+'
+
+test_expect_success 'object-format=sha-1 allowed' '
+ mkconfig 1 "objectFormat = sha-1" >.git/config &&
+ check_allow
+'
+
+test_expect_success 'object-format=foo unsupported' '
+ mkconfig 1 "objectFormat = foo" >.git/config &&
+ check_abort
+'
+
test_done
--
2.14.3
next prev parent reply other threads:[~2018-01-28 0:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <af22d7feb8a8448fa3953c66e69a8257460bff07.1516800711.git.patryk.obara@gmail.com>
2018-01-28 0:36 ` [PATCH v2 0/1] setup: recognise extensions.objectFormat Patryk Obara
2018-01-28 0:36 ` Patryk Obara [this message]
2018-01-28 15:40 ` [PATCH v2 1/1] " brian m. carlson
2018-01-30 1:38 ` Jeff King
2018-01-30 16:30 ` Patryk Obara
2018-01-30 16:41 ` Jeff King
2018-01-30 20:53 ` Junio C Hamano
2018-01-29 15:59 ` [PATCH v3 0/1] " Patryk Obara
2018-01-29 15:59 ` [PATCH v3 1/1] " Patryk Obara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e430ad029facdd6209927d352f0e7545cdd0e435.1517098675.git.patryk.obara@gmail.com \
--to=patryk.obara@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).