{"thread":{"id":"10615","subject":"[PATCH 2/3] Use setup_work_tree() in builtin-ls-files.c","startedAt":"2007-11-03T11:23:11Z","lastAt":"2007-11-08T23:34:50Z","messageCount":6,"participants":["Mike Hommey","Johannes Schindelin","Miles Bader","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"58100","messageId":"1194088993-25692-1-git-send-email-mh@glandium.org","threadId":"10615","inReplyTo":null,"subject":"[PATCH 1/3] Refactor working tree setup","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-11-03T11:23:11Z","receivedAt":"2007-11-03T11:23:11Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Create a setup_work_tree() that can be used from any command requiring\na working tree conditionally.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\nThis kind of implements what Dscho suggested in\nhttp://article.gmane.org/gmane.comp.version-control.git/62487\n\n cache.h |    1 +\n git.c   |   11 +++--------\n setup.c |    9 +++++++++\n 3 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex bfffa05..497b9f9 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -222,6 +222,7 @@ extern const char *get_git_work_tree(void);\n #define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\n \n extern const char **get_pathspec(const char *prefix, const char **pathspec);\n+extern void setup_work_tree(void);\n extern const char *setup_git_directory_gently(int *);\n extern const char *setup_git_directory(void);\n extern const char *prefix_path(const char *prefix, int len, const char *path);\ndiff --git a/git.c b/git.c\nindex 4e10581..eb31c93 100644\n--- a/git.c\n+++ b/git.c\n@@ -249,14 +249,9 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)\n \t\tprefix = setup_git_directory();\n \tif (p->option & USE_PAGER)\n \t\tsetup_pager();\n-\tif (p->option & NEED_WORK_TREE) {\n-\t\tconst char *work_tree = get_git_work_tree();\n-\t\tconst char *git_dir = get_git_dir();\n-\t\tif (!is_absolute_path(git_dir))\n-\t\t\tset_git_dir(make_absolute_path(git_dir));\n-\t\tif (!work_tree || chdir(work_tree))\n-\t\t\tdie(\"%s must be run in a work tree\", p->cmd);\n-\t}\n+\tif (p->option & NEED_WORK_TREE)\n+\t\tsetup_work_tree();\n+\n \ttrace_argv_printf(argv, argc, \"trace: built-in: git\");\n \n \tstatus = p->fn(argc, argv, prefix);\ndiff --git a/setup.c b/setup.c\nindex 145eca5..df006d9 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -206,6 +206,15 @@ static const char *set_work_tree(const char *dir)\n \treturn NULL;\n }\n \n+void setup_work_tree(void) {\n+\tconst char *work_tree = get_git_work_tree();\n+\tconst char *git_dir = get_git_dir();\n+\tif (!is_absolute_path(git_dir))\n+\t\tset_git_dir(make_absolute_path(git_dir));\n+\tif (!work_tree || chdir(work_tree))\n+\t\tdie(\"This operation must be run in a work tree\");\n+}\n+\n /*\n  * We cannot decide in this function whether we are in the work tree or\n  * not, since the config can only be read _after_ this function was called.\n-- \n1.5.3.5\n"},{"id":"58099","messageId":"1194088993-25692-2-git-send-email-mh@glandium.org","threadId":"10615","inReplyTo":"1194088993-25692-1-git-send-email-mh@glandium.org","subject":"[PATCH 2/3] Use setup_work_tree() in builtin-ls-files.c","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-11-03T11:23:12Z","receivedAt":"2007-11-03T11:23:12Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n builtin-ls-files.c |    7 ++-----\n 1 files changed, 2 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex b70da18..e0b856f 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -525,11 +525,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\tbreak;\n \t}\n \n-\tif (require_work_tree && !is_inside_work_tree()) {\n-\t\tconst char *work_tree = get_git_work_tree();\n-\t\tif (!work_tree || chdir(work_tree))\n-\t\t\tdie(\"This operation must be run in a work tree\");\n-\t}\n+\tif (require_work_tree && !is_inside_work_tree())\n+\t\tsetup_work_tree();\n \n \tpathspec = get_pathspec(prefix, argv + i);\n \n-- \n1.5.3.5\n"},{"id":"58101","messageId":"1194088993-25692-3-git-send-email-mh@glandium.org","threadId":"10615","inReplyTo":"1194088993-25692-2-git-send-email-mh@glandium.org","subject":"[PATCH 3/3] Don't always require working tree for git-rm","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-11-03T11:23:13Z","receivedAt":"2007-11-03T11:23:13Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"This allows to do git rm --cached -r directory, instead of\ngit ls-files -z directory | git update-index --remove -z --stdin.\nThis can be particularly useful for git-filter-branch users.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\nThis replaces the patch from\nhttp://article.gmane.org/gmane.comp.version-control.git/63227\n\n builtin-rm.c |    3 +++\n git.c        |    2 +-\n 2 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex bca2bd9..a3d25e6 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -155,6 +155,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \tif (!argc)\n \t\tusage_with_options(builtin_rm_usage, builtin_rm_options);\n \n+\tif (!index_only)\n+\t\tsetup_work_tree();\n+\n \tpathspec = get_pathspec(prefix, argv);\n \tseen = NULL;\n \tfor (i = 0; pathspec[i] ; i++)\ndiff --git a/git.c b/git.c\nindex eb31c93..4a250f7 100644\n--- a/git.c\n+++ b/git.c\n@@ -340,7 +340,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"rev-list\", cmd_rev_list, RUN_SETUP },\n \t\t{ \"rev-parse\", cmd_rev_parse, RUN_SETUP },\n \t\t{ \"revert\", cmd_revert, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"rm\", cmd_rm, RUN_SETUP | NEED_WORK_TREE },\n+\t\t{ \"rm\", cmd_rm, RUN_SETUP },\n \t\t{ \"runstatus\", cmd_runstatus, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"shortlog\", cmd_shortlog, RUN_SETUP | USE_PAGER },\n \t\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n-- \n1.5.3.5\n"},{"id":"58109","messageId":"Pine.LNX.4.64.0711031205390.4362@racer.site","threadId":"10615","inReplyTo":"1194088993-25692-1-git-send-email-mh@glandium.org","subject":"Re: [PATCH 1/3] Refactor working tree setup","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-03T12:06:13Z","receivedAt":"2007-11-03T12:06:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 3 Nov 2007, Mike Hommey wrote:\n\n> Create a setup_work_tree() that can be used from any command requiring a \n> working tree conditionally.\n\nAll three patches look fine to me.\n\nCiao,\nDscho\n"},{"id":"58948","messageId":"87bqa4gy2h.fsf@catnip.gol.com","threadId":"10615","inReplyTo":"1194088993-25692-1-git-send-email-mh@glandium.org","subject":"Re: [PATCH 1/3] Refactor working tree setup","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2007-11-08T22:41:10Z","receivedAt":"2007-11-08T22:41:10Z","isPatch":true,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"Mike Hommey <mh@glandium.org> writes:\n> Create a setup_work_tree() that can be used from any command requiring\n> a working tree conditionally.\n...\n> +void setup_work_tree(void) {\n> +\tconst char *work_tree = get_git_work_tree();\n\nHi, could you please not use this \"function begin brace at EOL\" style?\n\nIt's inconsistent with the rest of the source, makes the code harder to\nread, and confuses Emacs in some cases[1].  Also it's an abomination\nunto God, but I imagine it's the first of these reasons that you'll care\nabout the most... :-)\n\nThanks,\n\n-Miles\n\n\n[1] Until quite recently, Emacs c-mode couldn't find the beginning of\nsuch functions (recent versions of c-mode seem OK though).\n\n-- \nThe secret to creativity is knowing how to hide your sources.\n  --Albert Einstein\n"},{"id":"58957","messageId":"7vr6j0z4yt.fsf@gitster.siamese.dyndns.org","threadId":"10615","inReplyTo":"87bqa4gy2h.fsf@catnip.gol.com","subject":"Re: [PATCH 1/3] Refactor working tree setup","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-08T23:34:50Z","receivedAt":"2007-11-08T23:34:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miles Bader <miles@gnu.org> writes:\n\n> Mike Hommey <mh@glandium.org> writes:\n>> Create a setup_work_tree() that can be used from any command requiring\n>> a working tree conditionally.\n> ...\n>> +void setup_work_tree(void) {\n>> +\tconst char *work_tree = get_git_work_tree();\n>\n> Hi, could you please not use this \"function begin brace at EOL\" style?\n\nHmm.  I should have been more careful.\n\n-- >8 --\n[PATCH] Style: place opening brace of a function definition at column 1\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n bundle.c    |    3 ++-\n daemon.c    |    6 ++++--\n dir.c       |    3 ++-\n help.c      |    3 ++-\n quote.c     |    3 ++-\n setup.c     |    3 ++-\n transport.c |    6 ++++--\n utf8.c      |    3 ++-\n 8 files changed, 20 insertions(+), 10 deletions(-)\n\ndiff --git a/bundle.c b/bundle.c\nindex 0869fcf..e4d60cd 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -23,7 +23,8 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,\n }\n \n /* returns an fd */\n-int read_bundle_header(const char *path, struct bundle_header *header) {\n+int read_bundle_header(const char *path, struct bundle_header *header)\n+{\n \tchar buffer[1024];\n \tint fd;\n \tlong fpos;\ndiff --git a/daemon.c b/daemon.c\nindex b8df980..41a60af 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -406,7 +406,8 @@ static struct daemon_service daemon_service[] = {\n \t{ \"receive-pack\", \"receivepack\", receive_pack, 0, 1 },\n };\n \n-static void enable_service(const char *name, int ena) {\n+static void enable_service(const char *name, int ena)\n+{\n \tint i;\n \tfor (i = 0; i < ARRAY_SIZE(daemon_service); i++) {\n \t\tif (!strcmp(daemon_service[i].name, name)) {\n@@ -417,7 +418,8 @@ static void enable_service(const char *name, int ena) {\n \tdie(\"No such service %s\", name);\n }\n \n-static void make_service_overridable(const char *name, int ena) {\n+static void make_service_overridable(const char *name, int ena)\n+{\n \tint i;\n \tfor (i = 0; i < ARRAY_SIZE(daemon_service); i++) {\n \t\tif (!strcmp(daemon_service[i].name, name)) {\ndiff --git a/dir.c b/dir.c\nindex 5bcc764..01790ab 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -298,7 +298,8 @@ int excluded(struct dir_struct *dir, const char *pathname)\n \treturn 0;\n }\n \n-static struct dir_entry *dir_entry_new(const char *pathname, int len) {\n+static struct dir_entry *dir_entry_new(const char *pathname, int len)\n+{\n \tstruct dir_entry *ent;\n \n \tent = xmalloc(sizeof(*ent) + len + 1);\ndiff --git a/help.c b/help.c\nindex 855aeef..8217d97 100644\n--- a/help.c\n+++ b/help.c\n@@ -79,7 +79,8 @@ static void uniq(struct cmdnames *cmds)\n \tcmds->cnt = j;\n }\n \n-static void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) {\n+static void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)\n+{\n \tint ci, cj, ei;\n \tint cmp;\n \ndiff --git a/quote.c b/quote.c\nindex 919d092..0455783 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -131,7 +131,8 @@ static signed char const sq_lookup[256] = {\n \t/* 0x80 */ /* set to 0 */\n };\n \n-static inline int sq_must_quote(char c) {\n+static inline int sq_must_quote(char c)\n+{\n \treturn sq_lookup[(unsigned char)c] + quote_path_fully > 0;\n }\n \ndiff --git a/setup.c b/setup.c\nindex df006d9..1e2c55d 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -206,7 +206,8 @@ static const char *set_work_tree(const char *dir)\n \treturn NULL;\n }\n \n-void setup_work_tree(void) {\n+void setup_work_tree(void)\n+{\n \tconst char *work_tree = get_git_work_tree();\n \tconst char *git_dir = get_git_dir();\n \tif (!is_absolute_path(git_dir))\ndiff --git a/transport.c b/transport.c\nindex d44fe7c..fa5cfbb 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -380,7 +380,8 @@ static int disconnect_walker(struct transport *transport)\n }\n \n #ifndef NO_CURL\n-static int curl_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags) {\n+static int curl_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags)\n+{\n \tconst char **argv;\n \tint argc;\n \tint err;\n@@ -646,7 +647,8 @@ static int fetch_refs_via_pack(struct transport *transport,\n \treturn 0;\n }\n \n-static int git_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags) {\n+static int git_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags)\n+{\n \tstruct git_transport_data *data = transport->data;\n \tconst char **argv;\n \tchar *rem;\ndiff --git a/utf8.c b/utf8.c\nindex 4efef6f..8095a71 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -11,7 +11,8 @@ struct interval {\n };\n \n /* auxiliary function for binary search in interval table */\n-static int bisearch(ucs_char_t ucs, const struct interval *table, int max) {\n+static int bisearch(ucs_char_t ucs, const struct interval *table, int max)\n+{\n \tint min = 0;\n \tint mid;\n \n"}]}