git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 04/16] worktree setup: call set_git_dir explicitly
Date: Sat, 20 Mar 2010 15:10:46 +0700	[thread overview]
Message-ID: <fcaeb9bf1003200110w721903e7v7a5823cb312cbc71@mail.gmail.com> (raw)
In-Reply-To: <fcaeb9bf1003111645p54f42aaetbb622f8bde0ec8ad@mail.gmail.com>

Hmm.. I did not notice I did not sent this to git@vger.

On 3/12/10, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On 3/12/10, Junio C Hamano <gitster@pobox.com> wrote:
>  > Yes, you have more calls to set_git_dir() than before.  But it is not
>  >  explained why "calling set_git_dir explicitly" is a good thing anywhere in
>  >  the series.
>
>
> OK. Let me try in mail first.
>
>  Goal: do not rely on setup_git_env() to set git_dir to ".git". That
>  means set_git_dir() explicitly.
>
>
>  >   - Definition.
>  >
>  >    The following state variables belong to the setup system:
>  >
>  >    - git_dir: holds the location of $GIT_DIR as a path relative to cwd
>  >    - is_bare_repository(): returns foo;
>  >    - is_inside_working_tree(): returns bar;
>  >    - ...
>
>
> Best described in 7/16 and 14/16, function unset_git_directory() and
>  unset_git_env():
>
>   - git_dir and other git_*_dir in environment.c for object store path...
>   - shared_repository, is_bare_repository_cfg, git_work_tree_cfg,
>  repository_format:  initial configuration used during setup.
>   - is_inside_work_tree: whether cwd is inside a working directory
>   - is_inside_git_dir: whether cwd is inside $GIT_DIR
>   - startup_info->prefix: relative path from new cwd to original cwd
>  when main() is called
>   - startup_info->have_repository: whether a repository is found by setup system
>   - current working directory: directory base for git_dir, work_tree
>  and stuff if they are relative
>
>
>  >   - Rule for the callers of the setup system:
>
>
> Once main() starts. startup_info should be pointed to a struct. This
>  struct will be used by various part of libgit. If startup_info is
>  NULL, everything works like before.
>
>  Since startup_info initialization until calling setup functions,
>  access to repository will not be allowed, patch 16/16. "access to
>  repository" is everything that calls git_path() and friends.
>
>  One of the setup functions is called. These functions are
>  setup_git_directory*, enter_repo() or init_db(). Only one setup call
>  can be made for the rest of program's life time. unset_git_directory()
>  can be called to undo setup and allow setup functions to be called
>  once more. But it should be avoided.
>
>  If setup system fails to find a useable repository, all involved
>  states are restored. Refer to definition part for those states.
>
>  After setup function is called:
>
>   - git_path() and friends are allowed if startup_info->have_repository is true.
>
>   - Current directory directory may be moved. Programs need to be aware
>  of "prefix" (**) to calculate original cwd.
>
>   - Changing cwd is not allowed, as some directory settings may be
>  relative to cwd.
>
>   - The current working directory may or may not be at worktree's top
>  directory (*). If a command needs worktree, it must call
>  setup_work_tree() to move cwd (and adjust prefix along the way).
>  enter_repo() will never set worktree.
>
>  (*) setup_git_directory() does the setup_work_tree()-equivalent part
>  automatically. Users of setup_git_directory_gently() must call
>  setup_work_tree().
>
>  (**) The implicit rule of prefix is, it does not contain any "../". So
>  if original cwd is outside worktree, using this prefix alone is not
>  enough to get files from command line arguments.
>
>
>  >   - Rule for the implementation of the setup system:
>  >
>  >    Upon the first call the caller makes into the setup system:
>
>
> This is hard. Let's see. Prerequisites for entering setup system:
>
>   - No setup function has been called.
>
>  The main rule is, when a repo candidate is found, these must be done in order:
>   - setup is_inside_work_tree and is_inside_git_dir
>   - check_repo_format_gently(), if fails, call unset_git_dir and finish.
>   - set_git_dir()
>   - calculate prefix, then finish.
>
>  Setup procedure:
>
>   1. Check for GIT_DIR and GIT_WORK_TREE environment variables, if these are set:
>    1.1. if GIT_WORK_TREE is not set (only GIT_DIR is set), make cwd
>  GIT_WORK_TREE
>    1.2. adjust is_inside_work_tree and is_inside_git_dir accordingly
>    1.3. check repository config for repo format version, if
>  incompatible format is found, roll back using unset_git_directory and
>  return.
>    1.4. set_git_dir() to save GIT_DIR (this is irreversible, until patch 14/16)
>    1.5. calculate prefix, set startup_info->have_repository, finish.
>
>  2. Get current working directory, check whether $(cwd)/.git or $(cwd)
>  looks like a repository, going up until GIT_CEILING_DIRECTORIES (or /)
>  is reached, then finish.
>
>    2.1. If one dir looks like a repository:
>       2.1.1. adjust is_inside_work_tree and is_inside_git_dir accordingly
>       2.1.2. check repository config for repo format version, if
>  incompatible format is found, roll back using unset_git_directory and
>  return.
>       2.1.3. set_git_dir() to save GIT_DIR
>       2.1.4. calculate prefix, set ->have_repository, finish.
>
>    2.2. If no repository is found and GIT_CEILING_DIRECTORIES is
>  reached, moving back to original cwd, finish.
>
>  During setup procedure, normal access to repository is not allowed.
>  Though in theory, it could be allowed after set_git_dir() step.
>   --
>
> Duy
>


-- 
Duy

  parent reply	other threads:[~2010-03-20  8:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-11 13:22 [PATCH 00/16] nd/setup part two Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 01/16] Move enter_repo() to setup.c Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 02/16] enter_repo(): initialize other variables as setup_git_directory_gently() does Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 03/16] rev-parse --git-dir: print relative gitdir correctly Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 04/16] worktree setup: call set_git_dir explicitly Nguyễn Thái Ngọc Duy
2010-03-11 21:24   ` Junio C Hamano
     [not found]     ` <fcaeb9bf1003111645p54f42aaetbb622f8bde0ec8ad@mail.gmail.com>
2010-03-20  8:10       ` Nguyen Thai Ngoc Duy [this message]
2010-03-11 13:22 ` [PATCH 05/16] Add git_config_early() Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 06/16] Use git_config_early() instead of git_config() during repo setup Nguyễn Thái Ngọc Duy
2010-03-12  3:35   ` Nguyen Thai Ngoc Duy
2010-03-11 13:22 ` [PATCH 07/16] worktree setup: restore original state when things go wrong Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 08/16] init/clone: turn on startup->have_repository properly Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 09/16] git_config(): do not read .git/config if there is no repository Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 10/16] Do not read .git/info/exclude " Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 11/16] Do not read .git/info/attributes " Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 12/16] apply: do not check sha1 when repository has not been found Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 13/16] config: do not read .git/config if there is no repository Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 14/16] Allow to undo setup_git_directory_gently() gracefully (and fix alias code) Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 15/16] alias: keep repository found while collecting aliases as long as possible Nguyễn Thái Ngọc Duy
2010-03-11 13:22 ` [PATCH 16/16] Guard unallowed access to repository when it's not set up Nguyễn Thái Ngọc Duy

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=fcaeb9bf1003200110w721903e7v7a5823cb312cbc71@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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).