Add support for an LFS repository format version

We've had several proposals to change how data is stored on disk, such
as by compressing files when stored inside the .git directory.
Unfortunately, those proposals are incompatible with how data is stored
now and we would likely break older clients if we implemented them.

To make it possible for us to implement them in the future, let's do
what Git does and add support for a repository format version.  We read
the configuration option lfs.repositoryFormatVersion from the local
configuration, and if it is nonzero, we exit with an error.  We also
assume that if the value is not set, then it is implicitly 0 and set it
if possible.  We ignore any errors when writing to allow working with
read-only repositories in the limited circumstances where that can be
valuable.

The plan in the future is to support repository format v1, which, like
Git's, will be the same but for a set of lfs.repositoryextension.* keys
which denote extensions.  Such extensions will be ignored in v0, but
will be mandatory to understand in v1; unknown keys will cause Git LFS
to abort.  The implementation of this functionality is left to the
future, however.
This commit is contained in:
brian m. carlson 2021-06-22 19:51:52 +00:00
parent d4d8d68da1
commit 6b5f740a00
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
2 changed files with 44 additions and 0 deletions

@ -328,15 +328,28 @@ func setupRepository() {
ExitWithError(errors.Wrap(
err, "fatal: could not determine bareness"))
}
verifyRepositoryVersion()
if !bare {
changeToWorkingCopy()
}
}
func verifyRepositoryVersion() {
key := "lfs.repositoryformatversion"
val := cfg.FindGitLocalKey(key)
if val == "" {
cfg.SetGitLocalKey(key, "0")
} else if val != "0" {
Print("Unknown repository format version: %s", val)
os.Exit(128)
}
}
func setupWorkingCopy() {
requireInRepo()
requireWorkingCopy()
verifyRepositoryVersion()
changeToWorkingCopy()
}

31
t/t-repo-format.sh Executable file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "repository format version"
(
set -e
reponame="lfs-repo-version"
git init $reponame
cd $reponame
[ -z "$(git config --local lfs.repositoryFormatVersion)" ]
git lfs track '*.dat'
[ "$(git config --local lfs.repositoryFormatVersion)" = "0" ]
git config --local lfs.repositoryFormatVersion 1
git lfs track '*.bin' >output 2>&1 && exit 1
cat output
grep "Unknown repository format version: 1" output
git config --local --unset lfs.repositoryFormatVersion
# Verify that global settings are ignored.
git config --global lfs.repositoryFormatVersion 1
git lfs track '*.bin'
)
end_test