* setup_git_directory_gently contract question? @ 2008-05-27 14:10 Ciprian Dorin Craciun 2008-05-27 14:35 ` Ciprian Dorin Craciun ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Ciprian Dorin Craciun @ 2008-05-27 14:10 UTC (permalink / raw) To: git Is the function setup_git_directory_gently supposed to change the current working directory, or should it keep the initial one? What is the meaning of nongit_ok? Because if I use nongit_ok != NULL, but *nongit_ok == 1, this function changes the current working directory to the top of the worktree directory. Thanks, Ciprian Craciun. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: setup_git_directory_gently contract question? 2008-05-27 14:10 setup_git_directory_gently contract question? Ciprian Dorin Craciun @ 2008-05-27 14:35 ` Ciprian Dorin Craciun 2008-05-27 15:32 ` Nguyen Thai Ngoc Duy 2008-05-27 22:46 ` Junio C Hamano 2 siblings, 0 replies; 5+ messages in thread From: Ciprian Dorin Craciun @ 2008-05-27 14:35 UTC (permalink / raw) To: git Or another question: how can I obtain the git directory (.git) (absolute) path without updating the current working directory? Thanks, Ciprian Craciun. On Tue, May 27, 2008 at 5:10 PM, Ciprian Dorin Craciun <ciprian.craciun@gmail.com> wrote: > Is the function setup_git_directory_gently supposed to change the > current working directory, or should it keep the initial one? > What is the meaning of nongit_ok? > > Because if I use nongit_ok != NULL, but *nongit_ok == 1, this > function changes the current working directory to the top of the > worktree directory. > > Thanks, > Ciprian Craciun. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: setup_git_directory_gently contract question? 2008-05-27 14:10 setup_git_directory_gently contract question? Ciprian Dorin Craciun 2008-05-27 14:35 ` Ciprian Dorin Craciun @ 2008-05-27 15:32 ` Nguyen Thai Ngoc Duy 2008-05-27 22:46 ` Junio C Hamano 2 siblings, 0 replies; 5+ messages in thread From: Nguyen Thai Ngoc Duy @ 2008-05-27 15:32 UTC (permalink / raw) To: Ciprian Dorin Craciun; +Cc: git On Tue, May 27, 2008 at 9:10 PM, Ciprian Dorin Craciun <ciprian.craciun@gmail.com> wrote: > Is the function setup_git_directory_gently supposed to change the > current working directory, or should it keep the initial one? It will change if it finds a worktree. > What is the meaning of nongit_ok? Setting it to a non null pointer prevents git from die() when no git repository can be found. > Because if I use nongit_ok != NULL, but *nongit_ok == 1, this > function changes the current working directory to the top of the > worktree directory. It returns a directory prefix so that you can still know the original current working directory. You can do as following to have current directory "unchanged" prefix = setup_git_directory_gently(&nongit_ok); if (prefix) chdir(prefix) > Thanks, > Ciprian Craciun. > -- > To unsubscribe from this list: send the line "unsubscribe git" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Duy ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: setup_git_directory_gently contract question? 2008-05-27 14:10 setup_git_directory_gently contract question? Ciprian Dorin Craciun 2008-05-27 14:35 ` Ciprian Dorin Craciun 2008-05-27 15:32 ` Nguyen Thai Ngoc Duy @ 2008-05-27 22:46 ` Junio C Hamano 2008-05-28 7:14 ` Ciprian Dorin Craciun 2 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2008-05-27 22:46 UTC (permalink / raw) To: Ciprian Dorin Craciun; +Cc: git "Ciprian Dorin Craciun" <ciprian.craciun@gmail.com> writes: > Is the function setup_git_directory_gently supposed to change the > current working directory, or should it keep the initial one? > What is the meaning of nongit_ok? Most commands that work from subdirectory use setup_git_directory() interface, because major parts of the guts of the git internal want you to be at the top of the work tree (e.g. so that you grab a path out of the index, and be able to open(2) or lstat(2) that path). A normal sequence for a command is: (1) use setup_git_directory() to learn "prefix", (2) use get_pathspec() and/or prefix_path() to add "prefix" to the paths given from the command to make it a path relative to the work tree, (3) do its thing. setup_git_directory() chdir's up to the top of the work tree for this reason. Some commands can optionally work from even outside a git repository, but they would want to operate the same way as other comands, when they are started within a git repository. In such a case, you use "gently" variant, and give a pointer to int to store an additional return value to signal you if you are inside a git repository or outside. * When NULL is given as nongit_ok to gently(), it does not behave gentle at all. Outside a git repository it dies loudly. * If you are inside a git repository, it behaves pretty much the same as setup_git_directory(). "*nongit_ok" is set to zero to signal that you are inside a git repository. * If you are outside a git repository, *nongit_ok is set to non-zero so that the caller can tell that it is not in any git repository's work tree. There is no need to chdir (nor a sensible place to chdir to) in this case, so it doesn't. The caller thinks of the parameter as "are we operating in non-git mode?" boolean, and the callee (i.e. setup_git_directory_gently()) thinks of it as "is it ok to be called outside a git repository?" (if it is NULL, the caller expects to be inside a repository and wants it to barf otherwise). That is why caller's variable are often called "int nongit", and the callee's parameter is called "int *nongit_ok". ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: setup_git_directory_gently contract question? 2008-05-27 22:46 ` Junio C Hamano @ 2008-05-28 7:14 ` Ciprian Dorin Craciun 0 siblings, 0 replies; 5+ messages in thread From: Ciprian Dorin Craciun @ 2008-05-28 7:14 UTC (permalink / raw) To: Junio C Hamano; +Cc: git On Wed, May 28, 2008 at 1:46 AM, Junio C Hamano <gitster@pobox.com> wrote: > "Ciprian Dorin Craciun" <ciprian.craciun@gmail.com> writes: > >> Is the function setup_git_directory_gently supposed to change the >> current working directory, or should it keep the initial one? >> What is the meaning of nongit_ok? > > Most commands that work from subdirectory use setup_git_directory() > interface, because major parts of the guts of the git internal want you to > be at the top of the work tree (e.g. so that you grab a path out of the > index, and be able to open(2) or lstat(2) that path). A normal sequence > for a command is: (1) use setup_git_directory() to learn "prefix", (2) use > get_pathspec() and/or prefix_path() to add "prefix" to the paths given > from the command to make it a path relative to the work tree, (3) do its > thing. setup_git_directory() chdir's up to the top of the work tree for > this reason. > > Some commands can optionally work from even outside a git repository, but > they would want to operate the same way as other comands, when they are > started within a git repository. In such a case, you use "gently" > variant, and give a pointer to int to store an additional return value to > signal you if you are inside a git repository or outside. > > * When NULL is given as nongit_ok to gently(), it does not behave gentle > at all. Outside a git repository it dies loudly. > > * If you are inside a git repository, it behaves pretty much the same as > setup_git_directory(). "*nongit_ok" is set to zero to signal that you > are inside a git repository. > > * If you are outside a git repository, *nongit_ok is set to non-zero so > that the caller can tell that it is not in any git repository's work > tree. There is no need to chdir (nor a sensible place to chdir to) in > this case, so it doesn't. > > The caller thinks of the parameter as "are we operating in non-git mode?" > boolean, and the callee (i.e. setup_git_directory_gently()) thinks of it > as "is it ok to be called outside a git repository?" (if it is NULL, the > caller expects to be inside a repository and wants it to barf otherwise). > That is why caller's variable are often called "int nongit", and the > callee's parameter is called "int *nongit_ok". Thank you for your complete answer. I would propose that these comments to be added to the Documentation/technical/... directory, (or in the setup.c file), so that further developers will have this information. Thanks again, Ciprian. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-05-28 7:15 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-05-27 14:10 setup_git_directory_gently contract question? Ciprian Dorin Craciun 2008-05-27 14:35 ` Ciprian Dorin Craciun 2008-05-27 15:32 ` Nguyen Thai Ngoc Duy 2008-05-27 22:46 ` Junio C Hamano 2008-05-28 7:14 ` Ciprian Dorin Craciun
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).