Browse Source

Call setup_git_directory() much earlier

This changes the calling convention of built-in commands and
passes the "prefix" (i.e. pathname of $PWD relative to the
project root level) down to them.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Linus Torvalds 19 years ago committed by Junio C Hamano
parent
commit
a633fca0c0
  1. 3
      builtin-add.c
  2. 2
      builtin-apply.c
  3. 3
      builtin-cat-file.c
  4. 2
      builtin-check-ref-format.c
  5. 4
      builtin-commit-tree.c
  6. 2
      builtin-count.c
  7. 4
      builtin-diff-files.c
  8. 4
      builtin-diff-index.c
  9. 3
      builtin-diff-stages.c
  10. 4
      builtin-diff-tree.c
  11. 5
      builtin-diff.c
  12. 3
      builtin-fmt-merge-msg.c
  13. 3
      builtin-grep.c
  14. 4
      builtin-help.c
  15. 2
      builtin-init-db.c
  16. 25
      builtin-log.c
  17. 3
      builtin-ls-files.c
  18. 8
      builtin-ls-tree.c
  19. 2
      builtin-mailinfo.c
  20. 2
      builtin-mailsplit.c
  21. 4
      builtin-prune.c
  22. 2
      builtin-push.c
  23. 3
      builtin-read-tree.c
  24. 4
      builtin-rev-list.c
  25. 3
      builtin-rev-parse.c
  26. 3
      builtin-rm.c
  27. 3
      builtin-show-branch.c
  28. 2
      builtin-stripspace.c
  29. 9
      builtin-tar-tree.c
  30. 3
      builtin-update-index.c
  31. 3
      builtin-update-ref.c
  32. 2
      builtin-upload-tar.c
  33. 4
      builtin-write-tree.c
  34. 76
      builtin.h
  35. 63
      git.c

3
builtin-add.c

@ -123,11 +123,10 @@ static int add_file_to_index(const char *path, int verbose)


static struct lock_file lock_file; static struct lock_file lock_file;


int cmd_add(int argc, const char **argv, char **envp) int cmd_add(int argc, const char **argv, const char *prefix)
{ {
int i, newfd; int i, newfd;
int verbose = 0, show_only = 0; int verbose = 0, show_only = 0;
const char *prefix = setup_git_directory();
const char **pathspec; const char **pathspec;
struct dir_struct dir; struct dir_struct dir;



2
builtin-apply.c

@ -2268,7 +2268,7 @@ static int git_apply_config(const char *var, const char *value)
} }




int cmd_apply(int argc, const char **argv, char **envp) int cmd_apply(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
int read_stdin = 1; int read_stdin = 1;

3
builtin-cat-file.c

@ -94,7 +94,7 @@ static int pprint_tag(const unsigned char *sha1, const char *buf, unsigned long
return 0; return 0;
} }


int cmd_cat_file(int argc, const char **argv, char **envp) int cmd_cat_file(int argc, const char **argv, const char *prefix)
{ {
unsigned char sha1[20]; unsigned char sha1[20];
char type[20]; char type[20];
@ -102,7 +102,6 @@ int cmd_cat_file(int argc, const char **argv, char **envp)
unsigned long size; unsigned long size;
int opt; int opt;


setup_git_directory();
git_config(git_default_config); git_config(git_default_config);
if (argc != 3) if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>"); usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");

2
builtin-check-ref-format.c

@ -6,7 +6,7 @@
#include "refs.h" #include "refs.h"
#include "builtin.h" #include "builtin.h"


int cmd_check_ref_format(int argc, const char **argv, char **envp) int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
{ {
if (argc != 2) if (argc != 2)
usage("git check-ref-format refname"); usage("git check-ref-format refname");

4
builtin-commit-tree.c

@ -77,7 +77,7 @@ static int new_parent(int idx)
return 1; return 1;
} }


int cmd_commit_tree(int argc, const char **argv, char **envp) int cmd_commit_tree(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
int parents = 0; int parents = 0;
@ -88,8 +88,6 @@ int cmd_commit_tree(int argc, const char **argv, char **envp)
unsigned int size; unsigned int size;


setup_ident(); setup_ident();
setup_git_directory();

git_config(git_default_config); git_config(git_default_config);


if (argc < 2) if (argc < 2)

2
builtin-count.c

@ -67,7 +67,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
} }
} }


int cmd_count_objects(int ac, const char **av, char **ep) int cmd_count_objects(int ac, const char **av, const char *prefix)
{ {
int i; int i;
int verbose = 0; int verbose = 0;

4
builtin-diff-files.c

@ -13,12 +13,12 @@ static const char diff_files_usage[] =
"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]" "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;


int cmd_diff_files(int argc, const char **argv, char **envp) int cmd_diff_files(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
int silent = 0; int silent = 0;


init_revisions(&rev, setup_git_directory()); init_revisions(&rev, prefix);
git_config(git_default_config); /* no "diff" UI options */ git_config(git_default_config); /* no "diff" UI options */
rev.abbrev = 0; rev.abbrev = 0;



4
builtin-diff-index.c

@ -9,13 +9,13 @@ static const char diff_cache_usage[] =
"[<common diff options>] <tree-ish> [<path>...]" "[<common diff options>] <tree-ish> [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;


int cmd_diff_index(int argc, const char **argv, char **envp) int cmd_diff_index(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
int cached = 0; int cached = 0;
int i; int i;


init_revisions(&rev, setup_git_directory()); init_revisions(&rev, prefix);
git_config(git_default_config); /* no "diff" UI options */ git_config(git_default_config); /* no "diff" UI options */
rev.abbrev = 0; rev.abbrev = 0;



3
builtin-diff-stages.c

@ -55,10 +55,9 @@ static void diff_stages(int stage1, int stage2, const char **pathspec)
} }
} }


int cmd_diff_stages(int ac, const char **av, char **envp) int cmd_diff_stages(int ac, const char **av, const char *prefix)
{ {
int stage1, stage2; int stage1, stage2;
const char *prefix = setup_git_directory();
const char **pathspec = NULL; const char **pathspec = NULL;


git_config(git_default_config); /* no "diff" UI options */ git_config(git_default_config); /* no "diff" UI options */

4
builtin-diff-tree.c

@ -59,7 +59,7 @@ static const char diff_tree_usage[] =
" --root include the initial commit as diff against /dev/null\n" " --root include the initial commit as diff against /dev/null\n"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;


int cmd_diff_tree(int argc, const char **argv, char **envp) int cmd_diff_tree(int argc, const char **argv, const char *prefix)
{ {
int nr_sha1; int nr_sha1;
char line[1000]; char line[1000];
@ -67,7 +67,7 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
static struct rev_info *opt = &log_tree_opt; static struct rev_info *opt = &log_tree_opt;
int read_stdin = 0; int read_stdin = 0;


init_revisions(opt, setup_git_directory()); init_revisions(opt, prefix);
git_config(git_default_config); /* no "diff" UI options */ git_config(git_default_config); /* no "diff" UI options */
nr_sha1 = 0; nr_sha1 = 0;
opt->abbrev = 0; opt->abbrev = 0;

5
builtin-diff.c

@ -221,13 +221,13 @@ void add_head(struct rev_info *revs)
add_pending_object(revs, obj, "HEAD"); add_pending_object(revs, obj, "HEAD");
} }


int cmd_diff(int argc, const char **argv, char **envp) int cmd_diff(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
struct rev_info rev; struct rev_info rev;
struct object_array_entry ent[100]; struct object_array_entry ent[100];
int ents = 0, blobs = 0, paths = 0; int ents = 0, blobs = 0, paths = 0;
const char *path = NULL, *prefix; const char *path = NULL;
struct blobinfo blob[2]; struct blobinfo blob[2];


/* /*
@ -250,7 +250,6 @@ int cmd_diff(int argc, const char **argv, char **envp)
* Other cases are errors. * Other cases are errors.
*/ */


prefix = setup_git_directory();
git_config(git_diff_ui_config); git_config(git_diff_ui_config);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);



3
builtin-fmt-merge-msg.c

@ -242,7 +242,7 @@ static void shortlog(const char *name, unsigned char *sha1,
free_list(&subjects); free_list(&subjects);
} }


int cmd_fmt_merge_msg(int argc, char **argv, char **envp) int cmd_fmt_merge_msg(int argc, char **argv, const char *prefix)
{ {
int limit = 20, i = 0; int limit = 20, i = 0;
char line[1024]; char line[1024];
@ -250,7 +250,6 @@ int cmd_fmt_merge_msg(int argc, char **argv, char **envp)
const char *sep = ""; const char *sep = "";
unsigned char head_sha1[20]; unsigned char head_sha1[20];
const char *head, *current_branch; const char *head, *current_branch;
const char *prefix = setup_git_directory();


git_config(fmt_merge_msg_config); git_config(fmt_merge_msg_config);



3
builtin-grep.c

@ -919,14 +919,13 @@ static const char emsg_missing_context_len[] =
static const char emsg_missing_argument[] = static const char emsg_missing_argument[] =
"option requires an argument -%s"; "option requires an argument -%s";


int cmd_grep(int argc, const char **argv, char **envp) int cmd_grep(int argc, const char **argv, const char *prefix)
{ {
int hit = 0; int hit = 0;
int cached = 0; int cached = 0;
int seen_dashdash = 0; int seen_dashdash = 0;
struct grep_opt opt; struct grep_opt opt;
struct object_array list = { 0, 0, NULL }; struct object_array list = { 0, 0, NULL };
const char *prefix = setup_git_directory();
const char **paths = NULL; const char **paths = NULL;
int i; int i;



4
builtin-help.c

@ -221,13 +221,13 @@ static void show_man_page(const char *git_cmd)
execlp("man", "man", page, NULL); execlp("man", "man", page, NULL);
} }


int cmd_version(int argc, const char **argv, char **envp) int cmd_version(int argc, const char **argv, const char *prefix)
{ {
printf("git version %s\n", git_version_string); printf("git version %s\n", git_version_string);
return 0; return 0;
} }


int cmd_help(int argc, const char **argv, char **envp) int cmd_help(int argc, const char **argv, const char *prefix)
{ {
const char *help_cmd = argc > 1 ? argv[1] : NULL; const char *help_cmd = argc > 1 ? argv[1] : NULL;
if (!help_cmd) if (!help_cmd)

2
builtin-init-db.c

@ -250,7 +250,7 @@ static const char init_db_usage[] =
* On the other hand, it might just make lookup slower and messier. You * On the other hand, it might just make lookup slower and messier. You
* be the judge. The default case is to have one DB per managed directory. * be the judge. The default case is to have one DB per managed directory.
*/ */
int cmd_init_db(int argc, const char **argv, char **envp) int cmd_init_db(int argc, const char **argv, const char *prefix)
{ {
const char *git_dir; const char *git_dir;
const char *sha1_dir; const char *sha1_dir;

25
builtin-log.c

@ -16,7 +16,7 @@
/* this is in builtin-diff.c */ /* this is in builtin-diff.c */
void add_head(struct rev_info *revs); void add_head(struct rev_info *revs);


static void cmd_log_init(int argc, const char **argv, char **envp, static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev) struct rev_info *rev)
{ {
rev->abbrev = DEFAULT_ABBREV; rev->abbrev = DEFAULT_ABBREV;
@ -45,26 +45,24 @@ static int cmd_log_walk(struct rev_info *rev)
return 0; return 0;
} }


int cmd_whatchanged(int argc, const char **argv, char **envp) int cmd_whatchanged(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
const char *prefix = setup_git_directory();


git_config(git_diff_ui_config); git_config(git_diff_ui_config);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
rev.diff = 1; rev.diff = 1;
rev.diffopt.recursive = 1; rev.diffopt.recursive = 1;
rev.simplify_history = 0; rev.simplify_history = 0;
cmd_log_init(argc, argv, envp, &rev); cmd_log_init(argc, argv, prefix, &rev);
if (!rev.diffopt.output_format) if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW; rev.diffopt.output_format = DIFF_FORMAT_RAW;
return cmd_log_walk(&rev); return cmd_log_walk(&rev);
} }


int cmd_show(int argc, const char **argv, char **envp) int cmd_show(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
const char *prefix = setup_git_directory();


git_config(git_diff_ui_config); git_config(git_diff_ui_config);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
@ -75,19 +73,18 @@ int cmd_show(int argc, const char **argv, char **envp)
rev.always_show_header = 1; rev.always_show_header = 1;
rev.ignore_merges = 0; rev.ignore_merges = 0;
rev.no_walk = 1; rev.no_walk = 1;
cmd_log_init(argc, argv, envp, &rev); cmd_log_init(argc, argv, prefix, &rev);
return cmd_log_walk(&rev); return cmd_log_walk(&rev);
} }


int cmd_log(int argc, const char **argv, char **envp) int cmd_log(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
const char *prefix = setup_git_directory();


git_config(git_diff_ui_config); git_config(git_diff_ui_config);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
rev.always_show_header = 1; rev.always_show_header = 1;
cmd_log_init(argc, argv, envp, &rev); cmd_log_init(argc, argv, prefix, &rev);
return cmd_log_walk(&rev); return cmd_log_walk(&rev);
} }


@ -181,14 +178,13 @@ static int get_patch_id(struct commit *commit, struct diff_options *options,
return diff_flush_patch_id(options, sha1); return diff_flush_patch_id(options, sha1);
} }


static void get_patch_ids(struct rev_info *rev, struct diff_options *options) static void get_patch_ids(struct rev_info *rev, struct diff_options *options, const char *prefix)
{ {
struct rev_info check_rev; struct rev_info check_rev;
struct commit *commit; struct commit *commit;
struct object *o1, *o2; struct object *o1, *o2;
unsigned flags1, flags2; unsigned flags1, flags2;
unsigned char sha1[20]; unsigned char sha1[20];
const char *prefix = setup_git_directory();


if (rev->pending.nr != 2) if (rev->pending.nr != 2)
die("Need exactly one range."); die("Need exactly one range.");
@ -244,7 +240,7 @@ static void gen_message_id(char *dest, unsigned int length, char *base)
(int)(email_end - email_start - 1), email_start + 1); (int)(email_end - email_start - 1), email_start + 1);
} }


int cmd_format_patch(int argc, const char **argv, char **envp) int cmd_format_patch(int argc, const char **argv, const char *prefix)
{ {
struct commit *commit; struct commit *commit;
struct commit **list = NULL; struct commit **list = NULL;
@ -261,7 +257,6 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
char *add_signoff = NULL; char *add_signoff = NULL;
char message_id[1024]; char message_id[1024];
char ref_message_id[1024]; char ref_message_id[1024];
const char *prefix = setup_git_directory();


git_config(git_format_config); git_config(git_format_config);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
@ -368,7 +363,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
} }


if (ignore_if_in_upstream) if (ignore_if_in_upstream)
get_patch_ids(&rev, &patch_id_opts); get_patch_ids(&rev, &patch_id_opts, prefix);


if (!use_stdout) if (!use_stdout)
realstdout = fdopen(dup(1), "w"); realstdout = fdopen(dup(1), "w");

3
builtin-ls-files.c

@ -322,14 +322,13 @@ static const char ls_files_usage[] =
"[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] " "[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
"[--] [<file>]*"; "[--] [<file>]*";


int cmd_ls_files(int argc, const char **argv, char** envp) int cmd_ls_files(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
int exc_given = 0; int exc_given = 0;
struct dir_struct dir; struct dir_struct dir;


memset(&dir, 0, sizeof(dir)); memset(&dir, 0, sizeof(dir));
prefix = setup_git_directory();
if (prefix) if (prefix)
prefix_offset = strlen(prefix); prefix_offset = strlen(prefix);
git_config(git_default_config); git_config(git_default_config);

8
builtin-ls-tree.c

@ -18,7 +18,7 @@ static int abbrev = 0;
static int ls_options = 0; static int ls_options = 0;
static const char **pathspec; static const char **pathspec;
static int chomp_prefix = 0; static int chomp_prefix = 0;
static const char *prefix; static const char *ls_tree_prefix;


static const char ls_tree_usage[] = static const char ls_tree_usage[] =
"git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]"; "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
@ -71,7 +71,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
return 0; return 0;


if (chomp_prefix && if (chomp_prefix &&
(baselen < chomp_prefix || memcmp(prefix, base, chomp_prefix))) (baselen < chomp_prefix || memcmp(ls_tree_prefix, base, chomp_prefix)))
return 0; return 0;


if (!(ls_options & LS_NAME_ONLY)) if (!(ls_options & LS_NAME_ONLY))
@ -85,13 +85,13 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
return retval; return retval;
} }


int cmd_ls_tree(int argc, const char **argv, char **envp) int cmd_ls_tree(int argc, const char **argv, const char *prefix)
{ {
unsigned char sha1[20]; unsigned char sha1[20];
struct tree *tree; struct tree *tree;


prefix = setup_git_directory();
git_config(git_default_config); git_config(git_default_config);
ls_tree_prefix = prefix;
if (prefix && *prefix) if (prefix && *prefix)
chomp_prefix = strlen(prefix); chomp_prefix = strlen(prefix);
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {

2
builtin-mailinfo.c

@ -836,7 +836,7 @@ int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
static const char mailinfo_usage[] = static const char mailinfo_usage[] =
"git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info"; "git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info";


int cmd_mailinfo(int argc, const char **argv, char **envp) int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{ {
/* NEEDSWORK: might want to do the optional .git/ directory /* NEEDSWORK: might want to do the optional .git/ directory
* discovery * discovery

2
builtin-mailsplit.c

@ -138,7 +138,7 @@ out:
free(name); free(name);
return ret; return ret;
} }
int cmd_mailsplit(int argc, const char **argv, char **envp) int cmd_mailsplit(int argc, const char **argv, const char *prefix)
{ {
int nr = 0, nr_prec = 4, ret; int nr = 0, nr_prec = 4, ret;
int allow_bare = 0; int allow_bare = 0;

4
builtin-prune.c

@ -217,7 +217,7 @@ static void add_cache_refs(void)
add_cache_tree(active_cache_tree); add_cache_tree(active_cache_tree);
} }


int cmd_prune(int argc, const char **argv, char **envp) int cmd_prune(int argc, const char **argv, const char *prefix)
{ {
int i; int i;


@ -234,7 +234,7 @@ int cmd_prune(int argc, const char **argv, char **envp)
* Set up revision parsing, and mark us as being interested * Set up revision parsing, and mark us as being interested
* in all object types, not just commits. * in all object types, not just commits.
*/ */
init_revisions(&revs, setup_git_directory()); init_revisions(&revs, prefix);
revs.tag_objects = 1; revs.tag_objects = 1;
revs.blob_objects = 1; revs.blob_objects = 1;
revs.tree_objects = 1; revs.tree_objects = 1;

2
builtin-push.c

@ -270,7 +270,7 @@ static int do_push(const char *repo)
return 0; return 0;
} }


int cmd_push(int argc, const char **argv, char **envp) int cmd_push(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
const char *repo = "origin"; /* default repository */ const char *repo = "origin"; /* default repository */

3
builtin-read-tree.c

@ -870,7 +870,7 @@ static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive


static struct lock_file lock_file; static struct lock_file lock_file;


int cmd_read_tree(int argc, const char **argv, char **envp) int cmd_read_tree(int argc, const char **argv, const char *prefix)
{ {
int i, newfd, stage = 0; int i, newfd, stage = 0;
unsigned char sha1[20]; unsigned char sha1[20];
@ -882,7 +882,6 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
state.quiet = 1; state.quiet = 1;
state.refresh_cache = 1; state.refresh_cache = 1;


setup_git_directory();
git_config(git_default_config); git_config(git_default_config);


newfd = hold_lock_file_for_update(&lock_file, get_index_file()); newfd = hold_lock_file_for_update(&lock_file, get_index_file());

4
builtin-rev-list.c

@ -306,12 +306,12 @@ static void mark_edges_uninteresting(struct commit_list *list)
} }
} }


int cmd_rev_list(int argc, const char **argv, char **envp) int cmd_rev_list(int argc, const char **argv, const char *prefix)
{ {
struct commit_list *list; struct commit_list *list;
int i; int i;


init_revisions(&revs, setup_git_directory()); init_revisions(&revs, prefix);
revs.abbrev = 0; revs.abbrev = 0;
revs.commit_format = CMIT_FMT_UNSPECIFIED; revs.commit_format = CMIT_FMT_UNSPECIFIED;
argc = setup_revisions(argc, argv, &revs, NULL); argc = setup_revisions(argc, argv, &revs, NULL);

3
builtin-rev-parse.c

@ -209,11 +209,10 @@ static int try_difference(const char *arg)
return 0; return 0;
} }


int cmd_rev_parse(int argc, const char **argv, char **envp) int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{ {
int i, as_is = 0, verify = 0; int i, as_is = 0, verify = 0;
unsigned char sha1[20]; unsigned char sha1[20];
const char *prefix = setup_git_directory();


git_config(git_default_config); git_config(git_default_config);



3
builtin-rm.c

@ -43,11 +43,10 @@ static int remove_file(const char *name)


static struct lock_file lock_file; static struct lock_file lock_file;


int cmd_rm(int argc, const char **argv, char **envp) int cmd_rm(int argc, const char **argv, const char *prefix)
{ {
int i, newfd; int i, newfd;
int verbose = 0, show_only = 0, force = 0; int verbose = 0, show_only = 0, force = 0;
const char *prefix = setup_git_directory();
const char **pathspec; const char **pathspec;
char *seen; char *seen;



3
builtin-show-branch.c

@ -550,7 +550,7 @@ static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
return 0; return 0;
} }


int cmd_show_branch(int ac, const char **av, char **envp) int cmd_show_branch(int ac, const char **av, const char *prefix)
{ {
struct commit *rev[MAX_REVS], *commit; struct commit *rev[MAX_REVS], *commit;
struct commit_list *list = NULL, *seen = NULL; struct commit_list *list = NULL, *seen = NULL;
@ -573,7 +573,6 @@ int cmd_show_branch(int ac, const char **av, char **envp)
int topics = 0; int topics = 0;
int dense = 1; int dense = 1;


setup_git_directory();
git_config(git_show_branch_config); git_config(git_show_branch_config);


/* If nothing is specified, try the default first */ /* If nothing is specified, try the default first */

2
builtin-stripspace.c

@ -54,7 +54,7 @@ void stripspace(FILE *in, FILE *out)
fputc('\n', out); fputc('\n', out);
} }


int cmd_stripspace(int argc, const char **argv, char **envp) int cmd_stripspace(int argc, const char **argv, const char *prefix)
{ {
stripspace(stdin, stdout); stripspace(stdin, stdout);
return 0; return 0;

9
builtin-tar-tree.c

@ -308,7 +308,7 @@ int git_tar_config(const char *var, const char *value)
return git_default_config(var, value); return git_default_config(var, value);
} }


static int generate_tar(int argc, const char **argv, char** envp) static int generate_tar(int argc, const char **argv, const char *prefix)
{ {
unsigned char sha1[20], tree_sha1[20]; unsigned char sha1[20], tree_sha1[20];
struct commit *commit; struct commit *commit;
@ -319,7 +319,6 @@ static int generate_tar(int argc, const char **argv, char** envp)
current_path.alloc = PATH_MAX; current_path.alloc = PATH_MAX;
current_path.len = current_path.eof = 0; current_path.len = current_path.eof = 0;


setup_git_directory();
git_config(git_tar_config); git_config(git_tar_config);


switch (argc) { switch (argc) {
@ -402,19 +401,19 @@ static int remote_tar(int argc, const char **argv)
return !!ret; return !!ret;
} }


int cmd_tar_tree(int argc, const char **argv, char **envp) int cmd_tar_tree(int argc, const char **argv, const char *prefix)
{ {
if (argc < 2) if (argc < 2)
usage(tar_tree_usage); usage(tar_tree_usage);
if (!strncmp("--remote=", argv[1], 9)) if (!strncmp("--remote=", argv[1], 9))
return remote_tar(argc, argv); return remote_tar(argc, argv);
return generate_tar(argc, argv, envp); return generate_tar(argc, argv, prefix);
} }


/* ustar header + extended global header content */ /* ustar header + extended global header content */
#define HEADERSIZE (2 * RECORDSIZE) #define HEADERSIZE (2 * RECORDSIZE)


int cmd_get_tar_commit_id(int argc, const char **argv, char **envp) int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
{ {
char buffer[HEADERSIZE]; char buffer[HEADERSIZE];
struct ustar_header *header = (struct ustar_header *)buffer; struct ustar_header *header = (struct ustar_header *)buffer;

3
builtin-update-index.c

@ -476,12 +476,11 @@ static int do_reupdate(int ac, const char **av,
return 0; return 0;
} }


int cmd_update_index(int argc, const char **argv, char **envp) int cmd_update_index(int argc, const char **argv, const char *prefix)
{ {
int i, newfd, entries, has_errors = 0, line_termination = '\n'; int i, newfd, entries, has_errors = 0, line_termination = '\n';
int allow_options = 1; int allow_options = 1;
int read_from_stdin = 0; int read_from_stdin = 0;
const char *prefix = setup_git_directory();
int prefix_length = prefix ? strlen(prefix) : 0; int prefix_length = prefix ? strlen(prefix) : 0;
char set_executable_bit = 0; char set_executable_bit = 0;
unsigned int refresh_flags = 0; unsigned int refresh_flags = 0;

3
builtin-update-ref.c

@ -5,7 +5,7 @@
static const char git_update_ref_usage[] = static const char git_update_ref_usage[] =
"git-update-ref <refname> <value> [<oldval>] [-m <reason>]"; "git-update-ref <refname> <value> [<oldval>] [-m <reason>]";


int cmd_update_ref(int argc, const char **argv, char **envp) int cmd_update_ref(int argc, const char **argv, const char *prefix)
{ {
const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL; const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL;
struct ref_lock *lock; struct ref_lock *lock;
@ -13,7 +13,6 @@ int cmd_update_ref(int argc, const char **argv, char **envp)
int i; int i;


setup_ident(); setup_ident();
setup_git_directory();
git_config(git_default_config); git_config(git_default_config);


for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {

2
builtin-upload-tar.c

@ -15,7 +15,7 @@ static int nak(const char *reason)
return 1; return 1;
} }


int cmd_upload_tar(int argc, const char **argv, char **envp) int cmd_upload_tar(int argc, const char **argv, const char *prefix)
{ {
int len; int len;
const char *dir = argv[1]; const char *dir = argv[1];

4
builtin-write-tree.c

@ -60,14 +60,12 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
return 0; return 0;
} }


int cmd_write_tree(int argc, const char **argv, char **envp) int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{ {
int missing_ok = 0, ret; int missing_ok = 0, ret;
const char *prefix = NULL; const char *prefix = NULL;
unsigned char sha1[20]; unsigned char sha1[20];


setup_git_directory();

while (1 < argc) { while (1 < argc) {
const char *arg = argv[1]; const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok")) if (!strcmp(arg, "--missing-ok"))

76
builtin.h

@ -15,53 +15,53 @@ void cmd_usage(int show_all, const char *exec_path, const char *fmt, ...)
#endif #endif
; ;


extern int cmd_help(int argc, const char **argv, char **envp); extern int cmd_help(int argc, const char **argv, const char *prefix);
extern int cmd_version(int argc, const char **argv, char **envp); extern int cmd_version(int argc, const char **argv, const char *prefix);


extern int cmd_whatchanged(int argc, const char **argv, char **envp); extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
extern int cmd_show(int argc, const char **argv, char **envp); extern int cmd_show(int argc, const char **argv, const char *prefix);
extern int cmd_log(int argc, const char **argv, char **envp); extern int cmd_log(int argc, const char **argv, const char *prefix);
extern int cmd_diff(int argc, const char **argv, char **envp); extern int cmd_diff(int argc, const char **argv, const char *prefix);
extern int cmd_format_patch(int argc, const char **argv, char **envp); extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
extern int cmd_count_objects(int argc, const char **argv, char **envp); extern int cmd_count_objects(int argc, const char **argv, const char *prefix);


extern int cmd_prune(int argc, const char **argv, char **envp); extern int cmd_prune(int argc, const char **argv, const char *prefix);


extern int cmd_push(int argc, const char **argv, char **envp); extern int cmd_push(int argc, const char **argv, const char *prefix);
extern int cmd_grep(int argc, const char **argv, char **envp); extern int cmd_grep(int argc, const char **argv, const char *prefix);
extern int cmd_rm(int argc, const char **argv, char **envp); extern int cmd_rm(int argc, const char **argv, const char *prefix);
extern int cmd_add(int argc, const char **argv, char **envp); extern int cmd_add(int argc, const char **argv, const char *prefix);
extern int cmd_rev_list(int argc, const char **argv, char **envp); extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
extern int cmd_check_ref_format(int argc, const char **argv, char **envp); extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
extern int cmd_init_db(int argc, const char **argv, char **envp); extern int cmd_init_db(int argc, const char **argv, const char *prefix);
extern int cmd_tar_tree(int argc, const char **argv, char **envp); extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
extern int cmd_upload_tar(int argc, const char **argv, char **envp); extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
extern int cmd_get_tar_commit_id(int argc, const char **argv, char **envp); extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
extern int cmd_ls_files(int argc, const char **argv, char **envp); extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
extern int cmd_ls_tree(int argc, const char **argv, char **envp); extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
extern int cmd_read_tree(int argc, const char **argv, char **envp); extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
extern int cmd_commit_tree(int argc, const char **argv, char **envp); extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
extern int cmd_apply(int argc, const char **argv, char **envp); extern int cmd_apply(int argc, const char **argv, const char *prefix);
extern int cmd_show_branch(int argc, const char **argv, char **envp); extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
extern int cmd_diff_files(int argc, const char **argv, char **envp); extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
extern int cmd_diff_index(int argc, const char **argv, char **envp); extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
extern int cmd_diff_stages(int argc, const char **argv, char **envp); extern int cmd_diff_stages(int argc, const char **argv, const char *prefix);
extern int cmd_diff_tree(int argc, const char **argv, char **envp); extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
extern int cmd_cat_file(int argc, const char **argv, char **envp); extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
extern int cmd_rev_parse(int argc, const char **argv, char **envp); extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
extern int cmd_update_index(int argc, const char **argv, char **envp); extern int cmd_update_index(int argc, const char **argv, const char *prefix);
extern int cmd_update_ref(int argc, const char **argv, char **envp); extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
extern int cmd_fmt_merge_msg(int argc, const char **argv, char **envp); extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);


extern int cmd_write_tree(int argc, const char **argv, char **envp); extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);


extern int cmd_mailsplit(int argc, const char **argv, char **envp); extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip); extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);


extern int cmd_mailinfo(int argc, const char **argv, char **envp); extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch); extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);


extern int cmd_stripspace(int argc, const char **argv, char **envp); extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
extern void stripspace(FILE *in, FILE *out); extern void stripspace(FILE *in, FILE *out);
#endif #endif

63
git.c

@ -214,51 +214,54 @@ static int handle_alias(int *argcp, const char ***argv)


const char git_version_string[] = GIT_VERSION; const char git_version_string[] = GIT_VERSION;


#define NEEDS_PREFIX 1

static void handle_internal_command(int argc, const char **argv, char **envp) static void handle_internal_command(int argc, const char **argv, char **envp)
{ {
const char *cmd = argv[0]; const char *cmd = argv[0];
static struct cmd_struct { static struct cmd_struct {
const char *cmd; const char *cmd;
int (*fn)(int, const char **, char **); int (*fn)(int, const char **, const char *);
int prefix;
} commands[] = { } commands[] = {
{ "version", cmd_version }, { "version", cmd_version },
{ "help", cmd_help }, { "help", cmd_help },
{ "log", cmd_log }, { "log", cmd_log, NEEDS_PREFIX },
{ "whatchanged", cmd_whatchanged }, { "whatchanged", cmd_whatchanged, NEEDS_PREFIX },
{ "show", cmd_show }, { "show", cmd_show, NEEDS_PREFIX },
{ "push", cmd_push }, { "push", cmd_push },
{ "format-patch", cmd_format_patch }, { "format-patch", cmd_format_patch, NEEDS_PREFIX },
{ "count-objects", cmd_count_objects }, { "count-objects", cmd_count_objects },
{ "diff", cmd_diff }, { "diff", cmd_diff, NEEDS_PREFIX },
{ "grep", cmd_grep }, { "grep", cmd_grep, NEEDS_PREFIX },
{ "rm", cmd_rm }, { "rm", cmd_rm, NEEDS_PREFIX },
{ "add", cmd_add }, { "add", cmd_add, NEEDS_PREFIX },
{ "rev-list", cmd_rev_list }, { "rev-list", cmd_rev_list, NEEDS_PREFIX },
{ "init-db", cmd_init_db }, { "init-db", cmd_init_db },
{ "get-tar-commit-id", cmd_get_tar_commit_id }, { "get-tar-commit-id", cmd_get_tar_commit_id },
{ "upload-tar", cmd_upload_tar }, { "upload-tar", cmd_upload_tar },
{ "check-ref-format", cmd_check_ref_format }, { "check-ref-format", cmd_check_ref_format },
{ "ls-files", cmd_ls_files }, { "ls-files", cmd_ls_files, NEEDS_PREFIX },
{ "ls-tree", cmd_ls_tree }, { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
{ "tar-tree", cmd_tar_tree }, { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
{ "read-tree", cmd_read_tree }, { "read-tree", cmd_read_tree, NEEDS_PREFIX },
{ "commit-tree", cmd_commit_tree }, { "commit-tree", cmd_commit_tree, NEEDS_PREFIX },
{ "apply", cmd_apply }, { "apply", cmd_apply },
{ "show-branch", cmd_show_branch }, { "show-branch", cmd_show_branch, NEEDS_PREFIX },
{ "diff-files", cmd_diff_files }, { "diff-files", cmd_diff_files, NEEDS_PREFIX },
{ "diff-index", cmd_diff_index }, { "diff-index", cmd_diff_index, NEEDS_PREFIX },
{ "diff-stages", cmd_diff_stages }, { "diff-stages", cmd_diff_stages, NEEDS_PREFIX },
{ "diff-tree", cmd_diff_tree }, { "diff-tree", cmd_diff_tree, NEEDS_PREFIX },
{ "cat-file", cmd_cat_file }, { "cat-file", cmd_cat_file, NEEDS_PREFIX },
{ "rev-parse", cmd_rev_parse }, { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
{ "write-tree", cmd_write_tree }, { "write-tree", cmd_write_tree, NEEDS_PREFIX },
{ "mailsplit", cmd_mailsplit }, { "mailsplit", cmd_mailsplit },
{ "mailinfo", cmd_mailinfo }, { "mailinfo", cmd_mailinfo },
{ "stripspace", cmd_stripspace }, { "stripspace", cmd_stripspace },
{ "update-index", cmd_update_index }, { "update-index", cmd_update_index, NEEDS_PREFIX },
{ "update-ref", cmd_update_ref }, { "update-ref", cmd_update_ref, NEEDS_PREFIX },
{ "fmt-merge-msg", cmd_fmt_merge_msg }, { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX },
{ "prune", cmd_prune }, { "prune", cmd_prune, NEEDS_PREFIX },
}; };
int i; int i;


@ -270,9 +273,13 @@ static void handle_internal_command(int argc, const char **argv, char **envp)


for (i = 0; i < ARRAY_SIZE(commands); i++) { for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands+i; struct cmd_struct *p = commands+i;
const char *prefix;
if (strcmp(p->cmd, cmd)) if (strcmp(p->cmd, cmd))
continue; continue;


prefix = NULL;
if (p->prefix)
prefix = setup_git_directory();
if (getenv("GIT_TRACE")) { if (getenv("GIT_TRACE")) {
int i; int i;
fprintf(stderr, "trace: built-in: git"); fprintf(stderr, "trace: built-in: git");
@ -284,7 +291,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
fflush(stderr); fflush(stderr);
} }


exit(p->fn(argc, argv, envp)); exit(p->fn(argc, argv, prefix));
} }
} }



Loading…
Cancel
Save