git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/6] Add check_repo_format check for all major operations.

From
Junio C Hamano <junkio@cox.net>
Date
Nov 23, 2005, 00:57 UTC
Message-ID
<7v8xvg89li.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vd5ksefth.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
> Yes, although that is exactly what I said "this does not quite
> feel right" ;-).  Is it hard to arrange things so that a process
> does exactly one check_repo_format() during its lifetime?

Let's back up a bit. I'll deal with only low-level commands here.

First, the easiest group. The following commands do not look at the repository (.git directory) at all.

    check-ref-format get-tar-commit-id git index-pack mailinfo
    mailsplit patch-id shell show-index stripspace verify-pack
We do not need to do anything special about them.

The following three use enter_repo() to the given path (either from the end user at the command line or over the network):

    daemon receive-pack upload-pack

The repo format check should be done at the same place as we make sure enter_repo() finds the given directory a satisfactory path. That is, just before putenv(GIT_DIR=.) in enter_repo().

The following use setup_git_directory(), which chdir()s to the toplevel unless GIT_DIR is set.

    cat-file config-set diff-files diff-index diff-stages diff-tree
    ls-files name-rev rev-list rev-parse show-branch symbolic-ref
    update-index update-ref

Maybe we can have a thin wrapper around setup_git_directory() and after it returns check "${GIT_DIR-.git}" for repository format mismatch. What to do when GIT_DIR is set? Then we can just use it to read the config from "$GIT_DIR/config" and check the version.

The following commands implicitly assume that they are either run from the toplevel or GIT_DIR environment tells them where the .git/ directory is:

    apply checkout-index clone-pack commit-tree convert-objects
    fetch-pack fsck-objects hash-object http-fetch http-push init-db
    local-fetch ls-tree merge-base merge-index mktag pack-objects
    pack-redundant peek-remote prune-packed read-tree send-pack
    ssh-fetch ssh-upload tar-tree unpack-file unpack-objects
    update-server-info var write-tree

With some exceptions, they are pretty much repository wide commands, so I think it is OK for them to assume they start at the toplevel (the Porcelain would chdir to the top for them otherwise). The ones that take paths, namely, checkout-index, hash-object and ls-tree, may want to use setup_git_directory() and do the path prefixing.

That means we would need to have some way for the rest of the commands to check if "${GIT_DIR-.git}" is of the right format version, and call that *once* per process invocation, perferrably at the beginning of the main().

We need an access to .git/config file to do the repository format check anyway, which means we need setup_git_directory() if we ever want to run them from subdirectories. And running setup_git_directory() from the toplevel would not hurt, so perhaps if we add setup_git_directory() at the beginning of main() for the "implicity toplevel" class, and rewrite setup_git_directory() like this:

        static const char *setup_git_directory_main(void)
        {
                /* current setup_git_driectory() */
        }
	const char *setup_git_directory(void)
        {
        	const char *retval = setup_git_directory_main();
                check_repository_format_version(); /* dies on mismatch */
		return retval;
	}
it _might_ be good enough.

I said "it _might_" here, because we need to be careful. Right now, if you run the "implicitly toplevel" commands from a subdirectory, they fail. Some Porcelains and scripts may be relying on that and there will be consequences if things suddenly start not to fail but do something unexpected in higher directories.

Previous: Junio C HamanoNext: Martin Atukunda
Message 9 of 12 in “Git Future Proofing”
  1. Martin AtukundaNov 22, 2005
  2. 2/6 Make init-db check repo format version if copying a config file.Martin Atukunda, Nov 22, 2005
  3. 3/6 Make get_git_dir take a flag that makes it re-read the env. variablesMartin Atukunda, Nov 22, 2005
  4. 1/6 Add GIT_REPO_VERSION, and repository_format_versionMartin Atukunda, Nov 22, 2005
  5. 4/6 Add check_repo_format check for all major operations.Martin Atukunda, Nov 22, 2005
  6. Junio C HamanoNov 22, 2005
  7. Martin AtukundaNov 22, 2005
  8. Junio C HamanoNov 22, 2005
  9. Junio C HamanoNov 23, 2005
  10. 5/6 Allow Specification of the conf file to read for git_config operationsMartin Atukunda, Nov 22, 2005
  11. 6/6 Add check for downgrading of repo format version via init-dbMartin Atukunda, Nov 22, 2005
  12. Junio C HamanoNov 22, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.