{"thread":{"id":"13690","subject":"setup_git_directory_gently contract question?","startedAt":"2008-05-27T14:10:42Z","lastAt":"2008-05-28T07:14:15Z","messageCount":5,"participants":["Ciprian Dorin Craciun","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"77860","messageId":"8e04b5820805270710v3a06e5c2if2dcf3b94ef40c1f@mail.gmail.com","threadId":"13690","inReplyTo":null,"subject":"setup_git_directory_gently contract question?","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-05-27T14:10:42Z","receivedAt":"2008-05-27T14:10:42Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Is the function setup_git_directory_gently supposed to change the\ncurrent working directory, or should it keep the initial one?\n    What is the meaning of nongit_ok?\n\n    Because if I use nongit_ok != NULL, but *nongit_ok == 1, this\nfunction changes the current working directory to the top of the\nworktree directory.\n\n    Thanks,\n    Ciprian Craciun.\n"},{"id":"77863","messageId":"8e04b5820805270735m24ae4966x932ae610606d6e64@mail.gmail.com","threadId":"13690","inReplyTo":"8e04b5820805270710v3a06e5c2if2dcf3b94ef40c1f@mail.gmail.com","subject":"Re: setup_git_directory_gently contract question?","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-05-27T14:35:49Z","receivedAt":"2008-05-27T14:35:49Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Or another question: how can I obtain the git directory (.git)\n(absolute) path without updating the current working directory?\n\n    Thanks,\n    Ciprian Craciun.\n\n\nOn Tue, May 27, 2008 at 5:10 PM, Ciprian Dorin Craciun\n<ciprian.craciun@gmail.com> wrote:\n>    Is the function setup_git_directory_gently supposed to change the\n> current working directory, or should it keep the initial one?\n>    What is the meaning of nongit_ok?\n>\n>    Because if I use nongit_ok != NULL, but *nongit_ok == 1, this\n> function changes the current working directory to the top of the\n> worktree directory.\n>\n>    Thanks,\n>    Ciprian Craciun.\n"},{"id":"77868","messageId":"fcaeb9bf0805270832lc779a37gd9e58d0790981788@mail.gmail.com","threadId":"13690","inReplyTo":"8e04b5820805270710v3a06e5c2if2dcf3b94ef40c1f@mail.gmail.com","subject":"Re: setup_git_directory_gently contract question?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-05-27T15:32:41Z","receivedAt":"2008-05-27T15:32:41Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, May 27, 2008 at 9:10 PM, Ciprian Dorin Craciun\n<ciprian.craciun@gmail.com> wrote:\n>    Is the function setup_git_directory_gently supposed to change the\n> current working directory, or should it keep the initial one?\n\nIt will change if it finds a worktree.\n\n>    What is the meaning of nongit_ok?\n\nSetting it to a non null pointer prevents git from die() when no git\nrepository can be found.\n\n>    Because if I use nongit_ok != NULL, but *nongit_ok == 1, this\n> function changes the current working directory to the top of the\n> worktree directory.\n\nIt returns a directory prefix so that you can still know the original\ncurrent working directory. You can do as following to have current\ndirectory \"unchanged\"\n\nprefix = setup_git_directory_gently(&nongit_ok);\nif (prefix) chdir(prefix)\n\n>    Thanks,\n>    Ciprian Craciun.\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n\n\n\n-- \nDuy\n"},{"id":"77898","messageId":"7vmymbz7on.fsf@gitster.siamese.dyndns.org","threadId":"13690","inReplyTo":"8e04b5820805270710v3a06e5c2if2dcf3b94ef40c1f@mail.gmail.com","subject":"Re: setup_git_directory_gently contract question?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-27T22:46:48Z","receivedAt":"2008-05-27T22:46:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ciprian Dorin Craciun\" <ciprian.craciun@gmail.com> writes:\n\n>     Is the function setup_git_directory_gently supposed to change the\n> current working directory, or should it keep the initial one?\n>     What is the meaning of nongit_ok?\n\nMost commands that work from subdirectory use setup_git_directory()\ninterface, because major parts of the guts of the git internal want you to\nbe at the top of the work tree (e.g. so that you grab a path out of the\nindex, and be able to open(2) or lstat(2) that path).  A normal sequence\nfor a command is: (1) use setup_git_directory() to learn \"prefix\", (2) use\nget_pathspec() and/or prefix_path() to add \"prefix\" to the paths given\nfrom the command to make it a path relative to the work tree, (3) do its\nthing.  setup_git_directory() chdir's up to the top of the work tree for\nthis reason.\n\nSome commands can optionally work from even outside a git repository, but\nthey would want to operate the same way as other comands, when they are\nstarted within a git repository.  In such a case, you use \"gently\"\nvariant, and give a pointer to int to store an additional return value to\nsignal you if you are inside a git repository or outside.\n\n * When NULL is given as nongit_ok to gently(), it does not behave gentle\n   at all.  Outside a git repository it dies loudly.\n\n * If you are inside a git repository, it behaves pretty much the same as\n   setup_git_directory().  \"*nongit_ok\" is set to zero to signal that you\n   are inside a git repository.\n\n * If you are outside a git repository, *nongit_ok is set to non-zero so\n   that the caller can tell that it is not in any git repository's work\n   tree.  There is no need to chdir (nor a sensible place to chdir to) in\n   this case, so it doesn't.\n\nThe caller thinks of the parameter as \"are we operating in non-git mode?\"\nboolean, and the callee (i.e. setup_git_directory_gently()) thinks of it\nas \"is it ok to be called outside a git repository?\" (if it is NULL, the\ncaller expects to be inside a repository and wants it to barf otherwise).\nThat is why caller's variable are often called \"int nongit\", and the\ncallee's parameter is called \"int *nongit_ok\".\n"},{"id":"77916","messageId":"8e04b5820805280014m6fc635tf91ae20d9b9a5c91@mail.gmail.com","threadId":"13690","inReplyTo":"7vmymbz7on.fsf@gitster.siamese.dyndns.org","subject":"Re: setup_git_directory_gently contract question?","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-05-28T07:14:15Z","receivedAt":"2008-05-28T07:14:15Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, May 28, 2008 at 1:46 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ciprian Dorin Craciun\" <ciprian.craciun@gmail.com> writes:\n>\n>>     Is the function setup_git_directory_gently supposed to change the\n>> current working directory, or should it keep the initial one?\n>>     What is the meaning of nongit_ok?\n>\n> Most commands that work from subdirectory use setup_git_directory()\n> interface, because major parts of the guts of the git internal want you to\n> be at the top of the work tree (e.g. so that you grab a path out of the\n> index, and be able to open(2) or lstat(2) that path).  A normal sequence\n> for a command is: (1) use setup_git_directory() to learn \"prefix\", (2) use\n> get_pathspec() and/or prefix_path() to add \"prefix\" to the paths given\n> from the command to make it a path relative to the work tree, (3) do its\n> thing.  setup_git_directory() chdir's up to the top of the work tree for\n> this reason.\n>\n> Some commands can optionally work from even outside a git repository, but\n> they would want to operate the same way as other comands, when they are\n> started within a git repository.  In such a case, you use \"gently\"\n> variant, and give a pointer to int to store an additional return value to\n> signal you if you are inside a git repository or outside.\n>\n>  * When NULL is given as nongit_ok to gently(), it does not behave gentle\n>   at all.  Outside a git repository it dies loudly.\n>\n>  * If you are inside a git repository, it behaves pretty much the same as\n>   setup_git_directory().  \"*nongit_ok\" is set to zero to signal that you\n>   are inside a git repository.\n>\n>  * If you are outside a git repository, *nongit_ok is set to non-zero so\n>   that the caller can tell that it is not in any git repository's work\n>   tree.  There is no need to chdir (nor a sensible place to chdir to) in\n>   this case, so it doesn't.\n>\n> The caller thinks of the parameter as \"are we operating in non-git mode?\"\n> boolean, and the callee (i.e. setup_git_directory_gently()) thinks of it\n> as \"is it ok to be called outside a git repository?\" (if it is NULL, the\n> caller expects to be inside a repository and wants it to barf otherwise).\n> That is why caller's variable are often called \"int nongit\", and the\n> callee's parameter is called \"int *nongit_ok\".\n\n    Thank you for your complete answer.\n\n    I would propose that these comments to be added to the\nDocumentation/technical/... directory, (or in the setup.c file), so\nthat further developers will have this information.\n\n    Thanks again,\n    Ciprian.\n"}]}