Skip to content

Commit

Permalink
Call setup_git_directory() much earlier
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jul 29, 2006
1 parent db6296a commit a633fca
Show file tree
Hide file tree
Showing 35 changed files with 128 additions and 144 deletions.
3 changes: 1 addition & 2 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ static int add_file_to_index(const char *path, int verbose)

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 verbose = 0, show_only = 0;
const char *prefix = setup_git_directory();
const char **pathspec;
struct dir_struct dir;

Expand Down
2 changes: 1 addition & 1 deletion builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 read_stdin = 1;
Expand Down
3 changes: 1 addition & 2 deletions builtin-cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ static int pprint_tag(const unsigned char *sha1, const char *buf, unsigned long
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];
char type[20];
void *buf;
unsigned long size;
int opt;

setup_git_directory();
git_config(git_default_config);
if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
Expand Down
2 changes: 1 addition & 1 deletion builtin-check-ref-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "refs.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)
usage("git check-ref-format refname");
Expand Down
4 changes: 1 addition & 3 deletions builtin-commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int new_parent(int idx)
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 parents = 0;
Expand All @@ -88,8 +88,6 @@ int cmd_commit_tree(int argc, const char **argv, char **envp)
unsigned int size;

setup_ident();
setup_git_directory();

git_config(git_default_config);

if (argc < 2)
Expand Down
2 changes: 1 addition & 1 deletion builtin-count.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 verbose = 0;
Expand Down
4 changes: 2 additions & 2 deletions builtin-diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ static const char diff_files_usage[] =
"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
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;
int silent = 0;

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

Expand Down
4 changes: 2 additions & 2 deletions builtin-diff-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ static const char diff_cache_usage[] =
"[<common diff options>] <tree-ish> [<path>...]"
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;
int cached = 0;
int i;

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

Expand Down
3 changes: 1 addition & 2 deletions builtin-diff-stages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
const char *prefix = setup_git_directory();
const char **pathspec = NULL;

git_config(git_default_config); /* no "diff" UI options */
Expand Down
4 changes: 2 additions & 2 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ static const char diff_tree_usage[] =
" --root include the initial commit as diff against /dev/null\n"
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;
char line[1000];
struct object *tree1, *tree2;
static struct rev_info *opt = &log_tree_opt;
int read_stdin = 0;

init_revisions(opt, setup_git_directory());
init_revisions(opt, prefix);
git_config(git_default_config); /* no "diff" UI options */
nr_sha1 = 0;
opt->abbrev = 0;
Expand Down
5 changes: 2 additions & 3 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ void add_head(struct rev_info *revs)
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;
struct rev_info rev;
struct object_array_entry ent[100];
int ents = 0, blobs = 0, paths = 0;
const char *path = NULL, *prefix;
const char *path = NULL;
struct blobinfo blob[2];

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

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

Expand Down
3 changes: 1 addition & 2 deletions builtin-fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,14 @@ static void shortlog(const char *name, unsigned char *sha1,
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;
char line[1024];
FILE *in = stdin;
const char *sep = "";
unsigned char head_sha1[20];
const char *head, *current_branch;
const char *prefix = setup_git_directory();

git_config(fmt_merge_msg_config);

Expand Down
3 changes: 1 addition & 2 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,14 +919,13 @@ static const char emsg_missing_context_len[] =
static const char emsg_missing_argument[] =
"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 cached = 0;
int seen_dashdash = 0;
struct grep_opt opt;
struct object_array list = { 0, 0, NULL };
const char *prefix = setup_git_directory();
const char **paths = NULL;
int i;

Expand Down
4 changes: 2 additions & 2 deletions builtin-help.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ static void show_man_page(const char *git_cmd)
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);
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;
if (!help_cmd)
Expand Down
2 changes: 1 addition & 1 deletion builtin-init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static const char init_db_usage[] =
* 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.
*/
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 *sha1_dir;
Expand Down
25 changes: 10 additions & 15 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/* this is in builtin-diff.c */
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)
{
rev->abbrev = DEFAULT_ABBREV;
Expand Down Expand Up @@ -45,26 +45,24 @@ static int cmd_log_walk(struct rev_info *rev)
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;
const char *prefix = setup_git_directory();

git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
rev.diff = 1;
rev.diffopt.recursive = 1;
rev.simplify_history = 0;
cmd_log_init(argc, argv, envp, &rev);
cmd_log_init(argc, argv, prefix, &rev);
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
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;
const char *prefix = setup_git_directory();

git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
Expand All @@ -75,19 +73,18 @@ int cmd_show(int argc, const char **argv, char **envp)
rev.always_show_header = 1;
rev.ignore_merges = 0;
rev.no_walk = 1;
cmd_log_init(argc, argv, envp, &rev);
cmd_log_init(argc, argv, prefix, &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;
const char *prefix = setup_git_directory();

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

Expand Down Expand Up @@ -181,14 +178,13 @@ static int get_patch_id(struct commit *commit, struct diff_options *options,
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 commit *commit;
struct object *o1, *o2;
unsigned flags1, flags2;
unsigned char sha1[20];
const char *prefix = setup_git_directory();

if (rev->pending.nr != 2)
die("Need exactly one range.");
Expand Down Expand Up @@ -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 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 **list = NULL;
Expand All @@ -261,7 +257,6 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
char *add_signoff = NULL;
char message_id[1024];
char ref_message_id[1024];
const char *prefix = setup_git_directory();

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

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

if (!use_stdout)
realstdout = fdopen(dup(1), "w");
Expand Down
3 changes: 1 addition & 2 deletions builtin-ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,13 @@ static const char ls_files_usage[] =
"[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
"[--] [<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 exc_given = 0;
struct dir_struct dir;

memset(&dir, 0, sizeof(dir));
prefix = setup_git_directory();
if (prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config);
Expand Down
8 changes: 4 additions & 4 deletions builtin-ls-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static int abbrev = 0;
static int ls_options = 0;
static const char **pathspec;
static int chomp_prefix = 0;
static const char *prefix;
static const char *ls_tree_prefix;

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

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

if (!(ls_options & LS_NAME_ONLY))
Expand All @@ -85,13 +85,13 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
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];
struct tree *tree;

prefix = setup_git_directory();
git_config(git_default_config);
ls_tree_prefix = prefix;
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
while (1 < argc && argv[1][0] == '-') {
Expand Down
2 changes: 1 addition & 1 deletion builtin-mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
static const char mailinfo_usage[] =
"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
* discovery
Expand Down
2 changes: 1 addition & 1 deletion builtin-mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec,
free(name);
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 allow_bare = 0;
Expand Down
Loading

0 comments on commit a633fca

Please sign in to comment.