* An alternative: call setup_git_directory() early
From: Junio C Hamano @ 2006-07-29 4:41 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0607282118230.4168@g5.osdl.org>
We classify built-in commands into three classes: ones that
require to know where the .git directory is, ones that could use
the knowledge of where the .git directory is but can operate
without, and ones that should not attempt any .git discovery.
Most of the commands fall within the first category.
apply, mailsplit and mailinfo falls within the second category
(e.g. patches can be applied to non-git files without --index),
and the last category includes init-db (which should never do
a discovery).
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
> On Fri, 28 Jul 2006, Junio C Hamano wrote:
>>
>> No clever ideas, but I agree it would be _very_ nice if we could
>> do the setup unconditionally and early. Some commands that call
>> setup want to know prefix, so we would need to introduce a
>> global to hold the prefix for them.
>
> Ho humm. In the meantime, how about this? It fixes the places I noticed,
> but is mostly just a totally mindless conversion to move the call to
> "setup_git_directory()" into the caller.
I guess our mails crossed. This seems to pass all the tests but
our test do not cover subdirectory operation that much.
diff --git a/builtin-add.c b/builtin-add.c
index 3a73a17..07a29bc 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -127,7 +127,7 @@ int cmd_add(int argc, const char **argv,
{
int i, newfd;
int verbose = 0, show_only = 0;
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
const char **pathspec;
struct dir_struct dir;
diff --git a/builtin-apply.c b/builtin-apply.c
index d4381d9..fb06cc3 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2370,7 +2370,7 @@ int cmd_apply(int argc, const char **arg
}
if (check_index && prefix_length < 0) {
- prefix = setup_git_directory();
+ prefix = git_prefix;
prefix_length = prefix ? strlen(prefix) : 0;
git_config(git_apply_config);
if (!whitespace_option && apply_default_whitespace)
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 4d36817..53b15ef 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -102,7 +102,6 @@ int cmd_cat_file(int argc, const char **
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>");
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index ec082bf..cae544b 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -88,8 +88,6 @@ int cmd_commit_tree(int argc, const char
unsigned int size;
setup_ident();
- setup_git_directory();
-
git_config(git_default_config);
if (argc < 2)
diff --git a/builtin-diff-stages.c b/builtin-diff-stages.c
index 9c62702..9630a37 100644
--- a/builtin-diff-stages.c
+++ b/builtin-diff-stages.c
@@ -58,7 +58,7 @@ static void diff_stages(int stage1, int
int cmd_diff_stages(int ac, const char **av, char **envp)
{
int stage1, stage2;
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
const char **pathspec = NULL;
git_config(git_default_config); /* no "diff" UI options */
diff --git a/builtin-grep.c b/builtin-grep.c
index a79bac3..713cca1 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -926,7 +926,7 @@ int cmd_grep(int argc, const char **argv
int seen_dashdash = 0;
struct grep_opt opt;
struct object_array list = { 0, 0, NULL };
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
const char **paths = NULL;
int i;
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 8dae9f7..49e848e 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -329,7 +329,7 @@ int cmd_ls_files(int argc, const char **
struct dir_struct dir;
memset(&dir, 0, sizeof(dir));
- prefix = setup_git_directory();
+ prefix = git_prefix;
if (prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config);
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index b8d0d88..5cd4964 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -90,7 +90,7 @@ int cmd_ls_tree(int argc, const char **a
unsigned char sha1[20];
struct tree *tree;
- prefix = setup_git_directory();
+ prefix = git_prefix;
git_config(git_default_config);
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 122b6f1..375347d 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -882,7 +882,6 @@ int cmd_read_tree(int argc, const char *
state.quiet = 1;
state.refresh_cache = 1;
- setup_git_directory();
git_config(git_default_config);
newfd = hold_lock_file_for_update(&lock_file, get_index_file());
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index b3e4386..cca9b05 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -213,7 +213,7 @@ int cmd_rev_parse(int argc, const char *
{
int i, as_is = 0, verify = 0;
unsigned char sha1[20];
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
git_config(git_default_config);
diff --git a/builtin-rm.c b/builtin-rm.c
index bb810ba..25d0da3 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -47,7 +47,7 @@ int cmd_rm(int argc, const char **argv,
{
int i, newfd;
int verbose = 0, show_only = 0, force = 0;
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
const char **pathspec;
char *seen;
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 82f75b7..43ab1f8 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -573,7 +573,6 @@ int cmd_show_branch(int ac, const char *
int topics = 0;
int dense = 1;
- setup_git_directory();
git_config(git_show_branch_config);
/* If nothing is specified, try the default first */
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index e5aaded..3e6b736 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -319,7 +319,6 @@ static int generate_tar(int argc, const
current_path.alloc = PATH_MAX;
current_path.len = current_path.eof = 0;
- setup_git_directory();
git_config(git_tar_config);
switch (argc) {
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 1a4200d..c64506b 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -481,7 +481,7 @@ int cmd_update_index(int argc, const cha
int i, newfd, entries, has_errors = 0, line_termination = '\n';
int allow_options = 1;
int read_from_stdin = 0;
- const char *prefix = setup_git_directory();
+ const char *prefix = git_prefix;
int prefix_length = prefix ? strlen(prefix) : 0;
char set_executable_bit = 0;
unsigned int refresh_flags = 0;
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 83094ab..8138eba 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -13,7 +13,6 @@ int cmd_update_ref(int argc, const char
int i;
setup_ident();
- setup_git_directory();
git_config(git_default_config);
for (i = 1; i < argc; i++) {
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 449a4d1..d987d0b 100644
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
@@ -66,8 +66,6 @@ int cmd_write_tree(int argc, const char
const char *prefix = NULL;
unsigned char sha1[20];
- setup_git_directory();
-
while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok"))
diff --git a/cache.h b/cache.h
index eee5fc9..6c008f9 100644
--- a/cache.h
+++ b/cache.h
@@ -130,6 +130,8 @@ extern char *get_graft_file(void);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
+extern int gitdir_not_found;
+extern const char *git_prefix;
extern const char **get_pathspec(const char *prefix, const char **pathspec);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
diff --git a/environment.c b/environment.c
index 42f39d6..2fb978d 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,8 @@ int shared_repository = PERM_UMASK;
const char *apply_default_whitespace = NULL;
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
int pager_in_use;
+int gitdir_not_found;
+const char *git_prefix;
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
*git_graft_file;
diff --git a/git.c b/git.c
index 885e1ce..a9d6340 100644
--- a/git.c
+++ b/git.c
@@ -220,45 +220,50 @@ static void handle_internal_command(int
static struct cmd_struct {
const char *cmd;
int (*fn)(int, const char **, char **);
+ enum use_gitdir {
+ GITDIR_OPTIONAL,
+ GITDIR_REQUIRED,
+ GITDIR_DONTCARE,
+ } use_gitdir;
} commands[] = {
- { "version", cmd_version },
- { "help", cmd_help },
- { "log", cmd_log },
- { "whatchanged", cmd_whatchanged },
- { "show", cmd_show },
- { "push", cmd_push },
- { "format-patch", cmd_format_patch },
- { "count-objects", cmd_count_objects },
- { "diff", cmd_diff },
- { "grep", cmd_grep },
- { "rm", cmd_rm },
- { "add", cmd_add },
- { "rev-list", cmd_rev_list },
- { "init-db", cmd_init_db },
- { "get-tar-commit-id", cmd_get_tar_commit_id },
- { "upload-tar", cmd_upload_tar },
- { "check-ref-format", cmd_check_ref_format },
- { "ls-files", cmd_ls_files },
- { "ls-tree", cmd_ls_tree },
- { "tar-tree", cmd_tar_tree },
- { "read-tree", cmd_read_tree },
- { "commit-tree", cmd_commit_tree },
- { "apply", cmd_apply },
- { "show-branch", cmd_show_branch },
- { "diff-files", cmd_diff_files },
- { "diff-index", cmd_diff_index },
- { "diff-stages", cmd_diff_stages },
- { "diff-tree", cmd_diff_tree },
- { "cat-file", cmd_cat_file },
- { "rev-parse", cmd_rev_parse },
- { "write-tree", cmd_write_tree },
- { "mailsplit", cmd_mailsplit },
- { "mailinfo", cmd_mailinfo },
- { "stripspace", cmd_stripspace },
- { "update-index", cmd_update_index },
- { "update-ref", cmd_update_ref },
- { "fmt-merge-msg", cmd_fmt_merge_msg },
- { "prune", cmd_prune },
+ { "version", cmd_version, GITDIR_DONTCARE },
+ { "help", cmd_help, GITDIR_DONTCARE },
+ { "log", cmd_log, GITDIR_REQUIRED },
+ { "whatchanged", cmd_whatchanged, GITDIR_REQUIRED },
+ { "show", cmd_show, GITDIR_REQUIRED },
+ { "push", cmd_push, GITDIR_REQUIRED },
+ { "format-patch", cmd_format_patch, GITDIR_REQUIRED },
+ { "count-objects", cmd_count_objects, GITDIR_REQUIRED },
+ { "diff", cmd_diff, GITDIR_REQUIRED },
+ { "grep", cmd_grep, GITDIR_REQUIRED },
+ { "rm", cmd_rm, GITDIR_REQUIRED },
+ { "add", cmd_add, GITDIR_REQUIRED },
+ { "rev-list", cmd_rev_list, GITDIR_REQUIRED },
+ { "init-db", cmd_init_db, GITDIR_DONTCARE },
+ { "get-tar-commit-id", cmd_get_tar_commit_id, GITDIR_REQUIRED },
+ { "upload-tar", cmd_upload_tar, GITDIR_REQUIRED },
+ { "check-ref-format", cmd_check_ref_format, GITDIR_DONTCARE },
+ { "ls-files", cmd_ls_files, GITDIR_REQUIRED },
+ { "ls-tree", cmd_ls_tree, GITDIR_REQUIRED },
+ { "tar-tree", cmd_tar_tree, GITDIR_REQUIRED },
+ { "read-tree", cmd_read_tree, GITDIR_REQUIRED },
+ { "commit-tree", cmd_commit_tree, GITDIR_REQUIRED },
+ { "apply", cmd_apply, GITDIR_OPTIONAL },
+ { "show-branch", cmd_show_branch, GITDIR_REQUIRED },
+ { "diff-files", cmd_diff_files, GITDIR_REQUIRED },
+ { "diff-index", cmd_diff_index, GITDIR_REQUIRED },
+ { "diff-stages", cmd_diff_stages, GITDIR_REQUIRED },
+ { "diff-tree", cmd_diff_tree, GITDIR_REQUIRED },
+ { "cat-file", cmd_cat_file, GITDIR_REQUIRED },
+ { "rev-parse", cmd_rev_parse, GITDIR_REQUIRED },
+ { "write-tree", cmd_write_tree, GITDIR_REQUIRED },
+ { "mailsplit", cmd_mailsplit, GITDIR_OPTIONAL },
+ { "mailinfo", cmd_mailinfo, GITDIR_OPTIONAL },
+ { "stripspace", cmd_stripspace, GITDIR_OPTIONAL },
+ { "update-index", cmd_update_index, GITDIR_REQUIRED },
+ { "update-ref", cmd_update_ref, GITDIR_REQUIRED },
+ { "fmt-merge-msg", cmd_fmt_merge_msg, GITDIR_DONTCARE },
+ { "prune", cmd_prune, GITDIR_REQUIRED },
};
int i;
@@ -284,6 +289,18 @@ static void handle_internal_command(int
fflush(stderr);
}
+ gitdir_not_found = 0;
+ switch (p->use_gitdir) {
+ case GITDIR_REQUIRED:
+ git_prefix = setup_git_directory();
+ break;
+ case GITDIR_OPTIONAL:
+ git_prefix =
+ setup_git_directory_gently(&gitdir_not_found);
+ break;
+ case GITDIR_DONTCARE:
+ break;
+ }
exit(p->fn(argc, argv, envp));
}
}
diff --git a/t/trash/path0 b/t/trash/path0
deleted file mode 100644
index f87290f..0000000
--- a/t/trash/path0
+++ /dev/null
@@ -1 +0,0 @@
-hello path0
diff --git a/t/trash/path0sym b/t/trash/path0sym
deleted file mode 120000
index 15a9843..0000000
--- a/t/trash/path0sym
+++ /dev/null
@@ -1 +0,0 @@
-hello path0
\ No newline at end of file
diff --git a/t/trash/path2/file2 b/t/trash/path2/file2
deleted file mode 100644
index 3feff94..0000000
--- a/t/trash/path2/file2
+++ /dev/null
@@ -1 +0,0 @@
-hello path2/file2
diff --git a/t/trash/path2/file2sym b/t/trash/path2/file2sym
deleted file mode 120000
index d8ce161..0000000
--- a/t/trash/path2/file2sym
+++ /dev/null
@@ -1 +0,0 @@
-hello path2/file2
\ No newline at end of file
diff --git a/t/trash/path3/file3 b/t/trash/path3/file3
deleted file mode 100644
index 0aa34ca..0000000
--- a/t/trash/path3/file3
+++ /dev/null
@@ -1 +0,0 @@
-hello path3/file3
diff --git a/t/trash/path3/file3sym b/t/trash/path3/file3sym
deleted file mode 120000
index 8599103..0000000
--- a/t/trash/path3/file3sym
+++ /dev/null
@@ -1 +0,0 @@
-hello path3/file3
\ No newline at end of file
diff --git a/t/trash/path3/subp3/file3 b/t/trash/path3/subp3/file3
deleted file mode 100644
index 00fb590..0000000
--- a/t/trash/path3/subp3/file3
+++ /dev/null
@@ -1 +0,0 @@
-hello path3/subp3/file3
diff --git a/t/trash/path3/subp3/file3sym b/t/trash/path3/subp3/file3sym
deleted file mode 120000
index 6649a1e..0000000
--- a/t/trash/path3/subp3/file3sym
+++ /dev/null
@@ -1 +0,0 @@
-hello path3/subp3/file3
\ No newline at end of file
^ permalink raw reply related
* Re: Call setup_git_directory() early
From: Junio C Hamano @ 2006-07-29 5:06 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0607282118230.4168@g5.osdl.org>
Sorry for the earlier crapoid. The diffs contained there for
t/trash stuff were due to my earlier version that marked init-db
to be GITDIR_OPTIONAL -- which caused the "optional" discovery
to find the .git/ directory two levels up (relative to t/trash)
and contaminating the primary index file by mistake (Yuck).
Your patch makes a lot of sense.
^ permalink raw reply
* Re: Call setup_git_directory() early
From: Linus Torvalds @ 2006-07-29 5:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
In-Reply-To: <7vodv9j8yg.fsf@assigned-by-dhcp.cox.net>
On Fri, 28 Jul 2006, Junio C Hamano wrote:
>
> Your patch makes a lot of sense.
I don't think they are mutually incompatible.
My patch moves the call to "setup_git_directory()" a _bit_ earlier, and if
we just keep doing it, we'll end up with at least a subset of your patch.
Anyway, this was what I came up with when I did that "incremental" thing.
It's a bit like your patch, but a lot more invasive because it changes the
calling convention for the builtin commands (but it's cleaner because of
it, I think).
This is on top of my previous patch. What do you think? It does delete
more lines than it adds..
Linus
---
35 files changed, 109 insertions(+), 114 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 3a73a17..0fa7dc1 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -123,11 +123,10 @@ static int add_file_to_index(const char
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;
diff --git a/builtin-apply.c b/builtin-apply.c
index d924ac3..c1ba99e 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2222,7 +2222,7 @@ static int git_apply_config(const char *
}
-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;
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 4d36817..d796431 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -94,7 +94,7 @@ static int pprint_tag(const unsigned cha
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];
diff --git a/builtin-check-ref-format.c b/builtin-check-ref-format.c
index 4a23936..701de43 100644
--- a/builtin-check-ref-format.c
+++ b/builtin-check-ref-format.c
@@ -6,7 +6,7 @@ #include "cache.h"
#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");
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index ec082bf..e6fb16d 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -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;
diff --git a/builtin-count.c b/builtin-count.c
index 5ee72df..1d3729a 100644
--- a/builtin-count.c
+++ b/builtin-count.c
@@ -67,7 +67,7 @@ static void count_objects(DIR *d, char *
}
}
-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;
diff --git a/builtin-diff-files.c b/builtin-diff-files.c
index ea2936a..da51284 100644
--- a/builtin-diff-files.c
+++ b/builtin-diff-files.c
@@ -13,7 +13,7 @@ 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;
diff --git a/builtin-diff-index.c b/builtin-diff-index.c
index eeeee93..bedb90c 100644
--- a/builtin-diff-index.c
+++ b/builtin-diff-index.c
@@ -9,7 +9,7 @@ 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;
diff --git a/builtin-diff-stages.c b/builtin-diff-stages.c
index 9c62702..5960e08 100644
--- a/builtin-diff-stages.c
+++ b/builtin-diff-stages.c
@@ -55,10 +55,9 @@ static void diff_stages(int stage1, int
}
}
-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 */
diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c
index f8215ea..816946b 100644
--- a/builtin-diff-tree.c
+++ b/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"
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];
diff --git a/builtin-diff.c b/builtin-diff.c
index 7965c2c..4a592e6 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -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];
/*
@@ -250,7 +250,6 @@ int cmd_diff(int argc, const char **argv
* Other cases are errors.
*/
- prefix = setup_git_directory();
git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index 338f209..c84224e 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -242,7 +242,7 @@ static void shortlog(const char *name, u
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];
@@ -250,7 +250,6 @@ int cmd_fmt_merge_msg(int argc, char **a
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);
diff --git a/builtin-grep.c b/builtin-grep.c
index a79bac3..69b7c48 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -919,14 +919,13 @@ static const char emsg_missing_context_l
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;
diff --git a/builtin-help.c b/builtin-help.c
index 335fe5f..7f7701e 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -221,13 +221,13 @@ static void show_man_page(const char *gi
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 = argv[1];
if (!help_cmd)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 7fdd2fa..52473ed 100644
--- a/builtin-init-db.c
+++ b/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
* 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;
diff --git a/builtin-log.c b/builtin-log.c
index 52064cd..82c69d1 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -16,7 +16,7 @@ #include <sys/time.h>
/* 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;
@@ -45,26 +45,24 @@ static int cmd_log_walk(struct rev_info
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);
@@ -75,19 +73,18 @@ int cmd_show(int argc, const char **argv
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);
}
@@ -181,14 +178,13 @@ static int get_patch_id(struct commit *c
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.");
@@ -244,7 +240,7 @@ static void gen_message_id(char *dest, u
(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;
@@ -261,7 +257,6 @@ int cmd_format_patch(int argc, const cha
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);
@@ -368,7 +363,7 @@ int cmd_format_patch(int argc, const cha
}
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");
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 8dae9f7..e906c81 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -322,7 +322,7 @@ 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;
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index b8d0d88..d31efe9 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -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...]";
@@ -71,7 +71,7 @@ static int show_tree(const unsigned char
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))
@@ -85,13 +85,14 @@ static int show_tree(const unsigned char
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] == '-') {
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 05dc1bf..24a4fc6 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -836,7 +836,7 @@ int mailinfo(FILE *in, FILE *out, int ks
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
diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c
index e2a0058..91a699d 100644
--- a/builtin-mailsplit.c
+++ b/builtin-mailsplit.c
@@ -138,7 +138,7 @@ out:
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;
diff --git a/builtin-prune.c b/builtin-prune.c
index 4ed1e1b..15bb650 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -217,7 +217,7 @@ static void add_cache_refs(void)
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;
diff --git a/builtin-push.c b/builtin-push.c
index 31cbfd7..a824171 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -270,7 +270,7 @@ static int do_push(const char *repo)
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;
const char *repo = "origin"; /* default repository */
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 122b6f1..25ca69c 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -870,7 +870,7 @@ static const char read_tree_usage[] = "g
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;
unsigned char sha1[20];
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 2b6691c..65b4d0c 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -306,7 +306,7 @@ static void mark_edges_uninteresting(str
}
}
-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;
int i;
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index b3e4386..aca4a36 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -209,11 +209,10 @@ static int try_difference(const char *ar
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;
unsigned char sha1[20];
- const char *prefix = setup_git_directory();
git_config(git_default_config);
diff --git a/builtin-rm.c b/builtin-rm.c
index bb810ba..92d205a 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -43,11 +43,10 @@ static int remove_file(const char *name)
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 verbose = 0, show_only = 0, force = 0;
- const char *prefix = setup_git_directory();
const char **pathspec;
char *seen;
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 82f75b7..9c7f9f6 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -550,7 +550,7 @@ static int omit_in_dense(struct commit *
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_list *list = NULL, *seen = NULL;
diff --git a/builtin-stripspace.c b/builtin-stripspace.c
index 2ce1264..09cc910 100644
--- a/builtin-stripspace.c
+++ b/builtin-stripspace.c
@@ -54,7 +54,7 @@ void stripspace(FILE *in, FILE *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);
return 0;
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index e5aaded..637d22e 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -308,7 +308,7 @@ int git_tar_config(const char *var, cons
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];
struct commit *commit;
@@ -402,19 +402,19 @@ static int remote_tar(int argc, const ch
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)
usage(tar_tree_usage);
if (!strncmp("--remote=", argv[1], 9))
return remote_tar(argc, argv);
- return generate_tar(argc, argv, envp);
+ return generate_tar(argc, argv, prefix);
}
/* ustar header + extended global header content */
#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];
struct ustar_header *header = (struct ustar_header *)buffer;
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 1a4200d..24dca47 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -476,12 +476,11 @@ static int do_reupdate(int ac, const cha
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 allow_options = 1;
int read_from_stdin = 0;
- const char *prefix = setup_git_directory();
int prefix_length = prefix ? strlen(prefix) : 0;
char set_executable_bit = 0;
unsigned int refresh_flags = 0;
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 83094ab..acdf39a 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -5,7 +5,7 @@ #include "builtin.h"
static const char git_update_ref_usage[] =
"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;
struct ref_lock *lock;
diff --git a/builtin-upload-tar.c b/builtin-upload-tar.c
index d4fa7b5..7b401bb 100644
--- a/builtin-upload-tar.c
+++ b/builtin-upload-tar.c
@@ -15,7 +15,7 @@ static int nak(const char *reason)
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;
const char *dir = argv[1];
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 449a4d1..0f2dd7c 100644
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
@@ -60,7 +60,7 @@ int write_tree(unsigned char *sha1, int
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;
const char *prefix = NULL;
diff --git a/builtin.h b/builtin.h
index 5339d86..de244cd 100644
--- a/builtin.h
+++ b/builtin.h
@@ -15,53 +15,53 @@ #ifdef __GNUC__
#endif
;
-extern int cmd_help(int argc, const char **argv, char **envp);
-extern int cmd_version(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, const char *prefix);
-extern int cmd_whatchanged(int argc, const char **argv, char **envp);
-extern int cmd_show(int argc, const char **argv, char **envp);
-extern int cmd_log(int argc, const char **argv, char **envp);
-extern int cmd_diff(int argc, const char **argv, char **envp);
-extern int cmd_format_patch(int argc, const char **argv, char **envp);
-extern int cmd_count_objects(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, const char *prefix);
+extern int cmd_log(int argc, const char **argv, const char *prefix);
+extern int cmd_diff(int argc, const char **argv, const char *prefix);
+extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
+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_grep(int argc, const char **argv, char **envp);
-extern int cmd_rm(int argc, const char **argv, char **envp);
-extern int cmd_add(int argc, const char **argv, char **envp);
-extern int cmd_rev_list(int argc, const char **argv, char **envp);
-extern int cmd_check_ref_format(int argc, const char **argv, char **envp);
-extern int cmd_init_db(int argc, const char **argv, char **envp);
-extern int cmd_tar_tree(int argc, const char **argv, char **envp);
-extern int cmd_upload_tar(int argc, const char **argv, char **envp);
-extern int cmd_get_tar_commit_id(int argc, const char **argv, char **envp);
-extern int cmd_ls_files(int argc, const char **argv, char **envp);
-extern int cmd_ls_tree(int argc, const char **argv, char **envp);
-extern int cmd_read_tree(int argc, const char **argv, char **envp);
-extern int cmd_commit_tree(int argc, const char **argv, char **envp);
-extern int cmd_apply(int argc, const char **argv, char **envp);
-extern int cmd_show_branch(int argc, const char **argv, char **envp);
-extern int cmd_diff_files(int argc, const char **argv, char **envp);
-extern int cmd_diff_index(int argc, const char **argv, char **envp);
-extern int cmd_diff_stages(int argc, const char **argv, char **envp);
-extern int cmd_diff_tree(int argc, const char **argv, char **envp);
-extern int cmd_cat_file(int argc, const char **argv, char **envp);
-extern int cmd_rev_parse(int argc, const char **argv, char **envp);
-extern int cmd_update_index(int argc, const char **argv, char **envp);
-extern int cmd_update_ref(int argc, const char **argv, char **envp);
-extern int cmd_fmt_merge_msg(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, const char *prefix);
+extern int cmd_rm(int argc, const char **argv, const char *prefix);
+extern int cmd_add(int argc, const char **argv, const char *prefix);
+extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
+extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
+extern int cmd_init_db(int argc, const char **argv, const char *prefix);
+extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
+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, const char *prefix);
+extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
+extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_apply(int argc, const char **argv, const char *prefix);
+extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
+extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
+extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
+extern int cmd_diff_stages(int argc, const char **argv, const char *prefix);
+extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
+extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
+extern int cmd_update_index(int argc, const char **argv, const char *prefix);
+extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
+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 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 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 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);
#endif
diff --git a/git.c b/git.c
index ee5a0e8..e810d5c 100644
--- a/git.c
+++ b/git.c
@@ -157,25 +157,28 @@ static int handle_alias(int *argcp, cons
const char git_version_string[] = GIT_VERSION;
+#define NEEDS_PREFIX 1
+
static void handle_internal_command(int argc, const char **argv, char **envp)
{
const char *cmd = argv[0];
static struct cmd_struct {
const char *cmd;
- int (*fn)(int, const char **, char **);
+ int (*fn)(int, const char **, const char *);
+ int prefix;
} commands[] = {
{ "version", cmd_version },
{ "help", cmd_help },
- { "log", cmd_log },
- { "whatchanged", cmd_whatchanged },
- { "show", cmd_show },
+ { "log", cmd_log, NEEDS_PREFIX },
+ { "whatchanged", cmd_whatchanged, NEEDS_PREFIX },
+ { "show", cmd_show, NEEDS_PREFIX },
{ "push", cmd_push },
- { "format-patch", cmd_format_patch },
+ { "format-patch", cmd_format_patch, NEEDS_PREFIX },
{ "count-objects", cmd_count_objects },
- { "diff", cmd_diff },
- { "grep", cmd_grep },
- { "rm", cmd_rm },
- { "add", cmd_add },
+ { "diff", cmd_diff, NEEDS_PREFIX },
+ { "grep", cmd_grep, NEEDS_PREFIX },
+ { "rm", cmd_rm, NEEDS_PREFIX },
+ { "add", cmd_add, NEEDS_PREFIX },
{ "rev-list", cmd_rev_list },
{ "init-db", cmd_init_db },
{ "get-tar-commit-id", cmd_get_tar_commit_id },
@@ -190,17 +193,17 @@ static void handle_internal_command(int
{ "show-branch", cmd_show_branch },
{ "diff-files", cmd_diff_files },
{ "diff-index", cmd_diff_index },
- { "diff-stages", cmd_diff_stages },
+ { "diff-stages", cmd_diff_stages, NEEDS_PREFIX },
{ "diff-tree", cmd_diff_tree },
{ "cat-file", cmd_cat_file },
- { "rev-parse", cmd_rev_parse },
+ { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
{ "write-tree", cmd_write_tree },
{ "mailsplit", cmd_mailsplit },
{ "mailinfo", cmd_mailinfo },
{ "stripspace", cmd_stripspace },
- { "update-index", cmd_update_index },
+ { "update-index", cmd_update_index, NEEDS_PREFIX },
{ "update-ref", cmd_update_ref },
- { "fmt-merge-msg", cmd_fmt_merge_msg },
+ { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX },
{ "prune", cmd_prune },
};
int i;
@@ -213,9 +216,13 @@ static void handle_internal_command(int
for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands+i;
+ const char *prefix;
if (strcmp(p->cmd, cmd))
continue;
+ prefix = NULL;
+ if (p->prefix)
+ prefix = setup_git_directory();
if (getenv("GIT_TRACE")) {
int i;
fprintf(stderr, "trace: built-in: git");
@@ -227,7 +234,7 @@ static void handle_internal_command(int
fflush(stderr);
}
- exit(p->fn(argc, argv, envp));
+ exit(p->fn(argc, argv, prefix));
}
}
^ permalink raw reply related
* git prune pig slow
From: Russell King @ 2006-07-29 9:02 UTC (permalink / raw)
To: git
Hi,
git 1.4.0, P4 2.6GHz, 1GB.
I'm trying to use "git prune" to remove some unreachable objects from
my git tree. However, it appears to be _extremely_ expensive:
rmk 13376 91.3 15.7 165980 161556 pts/0 R+ 09:50 5:14 git-fsck-object
stracing it shows that it's doing lots and lots of brk() calls.
I killed it after 10 minutes and decided to do the job manually -
git-fsck-objects --unreachable and deleting the objects one by one is
_much_ quicker than git-fsck-objects --full --cache --unreachable.
--
Russell King
^ permalink raw reply
* Re: Call setup_git_directory() early
From: Junio C Hamano @ 2006-07-29 9:12 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0607282223320.4168@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
> On Fri, 28 Jul 2006, Junio C Hamano wrote:
>>
>> Your patch makes a lot of sense.
>
> I don't think they are mutually incompatible.
I agree. I was apologizing for the crap under t/trash in the
previous patch -- the rest were more or less in the same spirit
as yours.
> This is on top of my previous patch. What do you think? It does delete
> more lines than it adds..
Let me understand what is going on here.
> +#define NEEDS_PREFIX 1
>...
> { "init-db", cmd_init_db },
This is an oddball that wants to always use $GIT_DIR environment
or "./.git" if $GIT_DIR is not exported, and should never go
looking for GIT_DIR, so we should not give NEEDS_PREFIX, ever.
> { "stripspace", cmd_stripspace },
> { "mailsplit", cmd_mailsplit },
> { "get-tar-commit-id", cmd_get_tar_commit_id },
These are the other extreme -- they really do not care about
operating in a git context.
{ "push", cmd_push },
{ "count-objects", cmd_count_objects },
{ "check-ref-format", cmd_check_ref_format },
One rule seems to be that the commands that work at the while
repository level do not have NEEDS_PREFIX -- they will never
work from a subdirectory.
There is no technical reason not to let count-objects find
$GIT_DIR on its own, but the current implementation does not do
that and you are keeping the behaviour bug-to-bug compatible.
> + { "diff", cmd_diff, NEEDS_PREFIX },
> + { "grep", cmd_grep, NEEDS_PREFIX },
> + { "rm", cmd_rm, NEEDS_PREFIX },
> + { "add", cmd_add, NEEDS_PREFIX },
> + { "update-index", cmd_update_index, NEEDS_PREFIX },
> + { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
> + { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX },
Another rule: porcelain-ish should work from subdirectories, and
they do not have to call setup_git_directory() on their own.
> { "rev-list", cmd_rev_list },
I think we should mark this with NEEDS_PREFIX, and lose the call
to setup_git_directory() it has here:
...
int cmd_rev_list(int argc, const char **argv, const char *prefix)
{
struct commit_list *list;
int i;
- init_revisions(&revs, setup_git_directory());
+ init_revisions(&revs, prefix);
...
> { "diff-files", cmd_diff_files },
> { "diff-index", cmd_diff_index },
> { "diff-tree", cmd_diff_tree },
> { "prune", cmd_prune },
{ "ls-files", cmd_ls_files },
{ "ls-tree", cmd_ls_tree },
{ "tar-tree", cmd_tar_tree },
{ "read-tree", cmd_read_tree },
{ "commit-tree", cmd_commit_tree },
Likewise with the above group.
> { "show-branch", cmd_show_branch },
> { "cat-file", cmd_cat_file },
> { "write-tree", cmd_write_tree },
> { "update-ref", cmd_update_ref },
These call setup_git_directory() on their own and discard the
resulting prefix; they do want to know where $GIT_DIR is to find
objects and refs, so maybe we would want to mark these with
NEEDS_PREFIX and lose their own setup_git_directory(), like the
previous group. Perhaps you were thinking about splitting
setup_git_directory() into two independent functions, one for
finding out GIT_DIR, another for finding prefix and cd'ing up to
the project root?
Some of the above take configuration options, so even they are
not interested in finding out prefix they do need to know where
$GIT_DIR is (e.g. show-branch, update-ref, mailinfo).
> { "mailinfo", cmd_mailinfo },
{ "apply", cmd_apply },
These are tricky. On the one hand, there is no strong reason to
forbid use of mailinfo or apply outside git context, but they do
want to use some configuration items when available (commitencoding
for mailinfo, whitespace for apply).
So here is on top of your two patches to reflect the above
comments. Again it seems to pass our tests, so I'll put it in
"next" tonight.
--
builtin-cat-file.c | 1 -
builtin-commit-tree.c | 2 --
builtin-diff-files.c | 2 +-
builtin-diff-index.c | 2 +-
builtin-diff-tree.c | 2 +-
builtin-ls-files.c | 1 -
builtin-ls-tree.c | 1 -
builtin-prune.c | 2 +-
builtin-read-tree.c | 1 -
builtin-rev-list.c | 2 +-
builtin-show-branch.c | 1 -
builtin-tar-tree.c | 1 -
builtin-update-ref.c | 1 -
builtin-write-tree.c | 2 --
git.c | 28 ++++++++++++++--------------
15 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index d796431..814fb07 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -102,7 +102,6 @@ int cmd_cat_file(int argc, const char **
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>");
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index e6fb16d..9c98796 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -88,8 +88,6 @@ int cmd_commit_tree(int argc, const char
unsigned int size;
setup_ident();
- setup_git_directory();
-
git_config(git_default_config);
if (argc < 2)
diff --git a/builtin-diff-files.c b/builtin-diff-files.c
index da51284..ac13db7 100644
--- a/builtin-diff-files.c
+++ b/builtin-diff-files.c
@@ -18,7 +18,7 @@ int cmd_diff_files(int argc, const char
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;
diff --git a/builtin-diff-index.c b/builtin-diff-index.c
index bedb90c..95a3db1 100644
--- a/builtin-diff-index.c
+++ b/builtin-diff-index.c
@@ -15,7 +15,7 @@ int cmd_diff_index(int argc, const char
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;
diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c
index 816946b..24cb2d7 100644
--- a/builtin-diff-tree.c
+++ b/builtin-diff-tree.c
@@ -67,7 +67,7 @@ int cmd_diff_tree(int argc, const char *
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;
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index e906c81..79ffe8f 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -329,7 +329,6 @@ int cmd_ls_files(int argc, const char **
struct dir_struct dir;
memset(&dir, 0, sizeof(dir));
- prefix = setup_git_directory();
if (prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config);
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index d31efe9..261147f 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -90,7 +90,6 @@ int cmd_ls_tree(int argc, const char **a
unsigned char sha1[20];
struct tree *tree;
- prefix = setup_git_directory();
git_config(git_default_config);
ls_tree_prefix = prefix;
if (prefix && *prefix)
diff --git a/builtin-prune.c b/builtin-prune.c
index 15bb650..6a86eb5 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -234,7 +234,7 @@ int cmd_prune(int argc, const char **arg
* Set up revision parsing, and mark us as being interested
* in all object types, not just commits.
*/
- init_revisions(&revs, setup_git_directory());
+ init_revisions(&revs, prefix);
revs.tag_objects = 1;
revs.blob_objects = 1;
revs.tree_objects = 1;
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 25ca69c..49c10bf 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -882,7 +882,6 @@ int cmd_read_tree(int argc, const char *
state.quiet = 1;
state.refresh_cache = 1;
- setup_git_directory();
git_config(git_default_config);
newfd = hold_lock_file_for_update(&lock_file, get_index_file());
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 65b4d0c..0dee173 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -311,7 +311,7 @@ int cmd_rev_list(int argc, const char **
struct commit_list *list;
int i;
- init_revisions(&revs, setup_git_directory());
+ init_revisions(&revs, prefix);
revs.abbrev = 0;
revs.commit_format = CMIT_FMT_UNSPECIFIED;
argc = setup_revisions(argc, argv, &revs, NULL);
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 9c7f9f6..2a1b848 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -573,7 +573,6 @@ int cmd_show_branch(int ac, const char *
int topics = 0;
int dense = 1;
- setup_git_directory();
git_config(git_show_branch_config);
/* If nothing is specified, try the default first */
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 637d22e..7c48db9 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -319,7 +319,6 @@ static int generate_tar(int argc, const
current_path.alloc = PATH_MAX;
current_path.len = current_path.eof = 0;
- setup_git_directory();
git_config(git_tar_config);
switch (argc) {
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index acdf39a..5bd7182 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -13,7 +13,6 @@ int cmd_update_ref(int argc, const char
int i;
setup_ident();
- setup_git_directory();
git_config(git_default_config);
for (i = 1; i < argc; i++) {
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 0f2dd7c..0289f59 100644
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
@@ -66,8 +66,6 @@ int cmd_write_tree(int argc, const char
const char *prefix = NULL;
unsigned char sha1[20];
- setup_git_directory();
-
while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok"))
diff --git a/git.c b/git.c
index 34328c0..79db43e 100644
--- a/git.c
+++ b/git.c
@@ -236,32 +236,32 @@ static void handle_internal_command(int
{ "grep", cmd_grep, NEEDS_PREFIX },
{ "rm", cmd_rm, NEEDS_PREFIX },
{ "add", cmd_add, NEEDS_PREFIX },
- { "rev-list", cmd_rev_list },
+ { "rev-list", cmd_rev_list, NEEDS_PREFIX },
{ "init-db", cmd_init_db },
{ "get-tar-commit-id", cmd_get_tar_commit_id },
{ "upload-tar", cmd_upload_tar },
{ "check-ref-format", cmd_check_ref_format },
- { "ls-files", cmd_ls_files },
- { "ls-tree", cmd_ls_tree },
- { "tar-tree", cmd_tar_tree },
- { "read-tree", cmd_read_tree },
- { "commit-tree", cmd_commit_tree },
+ { "ls-files", cmd_ls_files, NEEDS_PREFIX },
+ { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
+ { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
+ { "read-tree", cmd_read_tree, NEEDS_PREFIX },
+ { "commit-tree", cmd_commit_tree, NEEDS_PREFIX },
{ "apply", cmd_apply },
- { "show-branch", cmd_show_branch },
- { "diff-files", cmd_diff_files },
- { "diff-index", cmd_diff_index },
+ { "show-branch", cmd_show_branch, NEEDS_PREFIX },
+ { "diff-files", cmd_diff_files, NEEDS_PREFIX },
+ { "diff-index", cmd_diff_index, NEEDS_PREFIX },
{ "diff-stages", cmd_diff_stages, NEEDS_PREFIX },
- { "diff-tree", cmd_diff_tree },
- { "cat-file", cmd_cat_file },
+ { "diff-tree", cmd_diff_tree, NEEDS_PREFIX },
+ { "cat-file", cmd_cat_file, NEEDS_PREFIX },
{ "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
- { "write-tree", cmd_write_tree },
+ { "write-tree", cmd_write_tree, NEEDS_PREFIX },
{ "mailsplit", cmd_mailsplit },
{ "mailinfo", cmd_mailinfo },
{ "stripspace", cmd_stripspace },
{ "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, NEEDS_PREFIX },
- { "prune", cmd_prune },
+ { "prune", cmd_prune, NEEDS_PREFIX },
};
int i;
^ permalink raw reply related
* Re: Java GIT/Eclipse GIT version 0.1.1
From: Jakub Narebski @ 2006-07-29 10:15 UTC (permalink / raw)
To: git
In-Reply-To: <20060728063620.GD30783@spearce.org>
Shawn Pearce wrote:
> My Java GIT library and Eclipse GIT team provider is now at a point
> where it may be partially useful to someone else who is also trying
> to write something which interacts with GIT. Or who might also
> be interested in seeing a pure-Java Eclipse team provider for GIT.
>
> So I've posted my repository (currently ~200 KB) on my website:
>
> http://www.spearce.org/projects/scm/egit.git
Could you also provide some webpage and/or gitweb for this project?
I have added some info about your work on GitWiki at
http://git.or.cz/gitwiki/InterfacesFrontendsAndTools#Eclipse
Please review, correct errors, and expand information as needed.
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply
* Re: Licensing and the library version of git
From: Johannes Schindelin @ 2006-07-29 11:21 UTC (permalink / raw)
To: Jon Smirl; +Cc: Shawn Pearce, Wolfgang Denk, git
In-Reply-To: <9e4733910607282131i4429e93fx7da0022791d53b69@mail.gmail.com>
Hi,
On Sat, 29 Jul 2006, Jon Smirl wrote:
> I don't believe there is any legal way to link GPL code into a Java
> app since there are no free Java runtimes.
First, there are quite a few free Java runtimes; you did not really try to
find one, right?
Second, since the Java runtime can be likened to the libc, all
de-restrictions about system libraries should hold for Java, too.
Hth,
Dscho
^ permalink raw reply
* Re: git prune pig slow
From: Johannes Schindelin @ 2006-07-29 11:40 UTC (permalink / raw)
To: Russell King; +Cc: git
In-Reply-To: <20060729090250.GC26956@flint.arm.linux.org.uk>
Hi,
On Sat, 29 Jul 2006, Russell King wrote:
> Hi,
>
> git 1.4.0, P4 2.6GHz, 1GB.
>
> I'm trying to use "git prune" to remove some unreachable objects from
> my git tree. However, it appears to be _extremely_ expensive:
>
> rmk 13376 91.3 15.7 165980 161556 pts/0 R+ 09:50 5:14 git-fsck-object
>
> stracing it shows that it's doing lots and lots of brk() calls.
Does git-count-objects show a high amount of unpacked objects? You should
try "git-repack -a -d" _before_ git-prune, then.
Hth,
Dscho
^ permalink raw reply
* Re: [PATCH] Teach the git wrapper about --name-rev and --name-rev-by-tags
From: Nguyễn Thái Ngọc Duy @ 2006-07-29 12:43 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Linus Torvalds, Junio C Hamano, git
In-Reply-To: <Pine.LNX.4.63.0607282042470.29667@wbgn013.biozentrum.uni-wuerzburg.de>
On 7/29/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> You are probably right. But _I_ want to know that e.g. commit
> a025463bc0ec2c894a88f2dfb44cf88ba71bb712 is really tags/v1.4.0^0~27^2.
> Both are immutable, but the latter is nicer to people than to computers.
I think so too. I had requested a similar feature on the git survey
and was surprised to see this patch. I'd appreciate it.
^ permalink raw reply
* Re: [PATCH] Teach the git wrapper about --name-rev and --name-rev-by-tags
From: Johannes Schindelin @ 2006-07-29 12:47 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: Linus Torvalds, Junio C Hamano, git
In-Reply-To: <fcaeb9bf0607290543h12b70c74q54a1fbfc3c8e3b7e@mail.gmail.com>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 537 bytes --]
Hi,
On Sat, 29 Jul 2006, Nguyn Thái Ngc Duy wrote:
> On 7/29/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > You are probably right. But _I_ want to know that e.g. commit
> > a025463bc0ec2c894a88f2dfb44cf88ba71bb712 is really tags/v1.4.0^0~27^2.
> > Both are immutable, but the latter is nicer to people than to computers.
> I think so too. I had requested a similar feature on the git survey
> and was surprised to see this patch. I'd appreciate it.
Now, guess three times where the idea comes from. ;-)
Ciao,
Dscho
^ permalink raw reply
* Better Future, wind-outspeeding
From: Eloise Roland @ 2006-07-29 15:04 UTC (permalink / raw)
To: git-commits-head-owner
Your cre dit doesn't matter to us! If you OWN real est ate
and want IMMEDIATES cash to spend ANY way you like, or simply wish
to LOWER your monthly paym ents by a third or more, here are the dea ls
we have TODAY (hurry, these ofers will expre TONIGHT):
$488,000.00 at a 3.67,% fixed-rateM
$372,000.00 at a 3.90,% variable-rateA
$492,000.00 at a 3.21,% interest-only3
$248,000.00 at a 3.36,% fixed-rateB
$198,000.00 at a 3.55,% variable-rateJ
Hurry, when these deals are gone, they are gone Simply fill out this one-min ute form...
Don't worry about approval, your cre dit will not disqualify you!
http://VK38M1BX.corkpencills.com
them back?"
even redder. His eyes filled with tears. Redrick grinned.
tearing inside, like a dried bandage pulling from a wound. Arthur also
seated himself at the table, where a pint bottle, a bowl with thick soup,
drop dead. So I get back, and there's a surprise for me--emigration has been
has to pay for this, and somebody will! Just wait, just let me get to the
designs made by rust on the cabin's red roof.
chatting but thought, as he looked at those two horrors born of the Zone: My
tearing inside, like a dried bandage pulling from a wound. Arthur also
was flaming before his half-closed eyes, and they were all bitter, and they
trying not to move, still hoping that it would blow over, even though he
^ permalink raw reply
* [PATCH] Build on Debian GNU/kFreeBSD
From: Gerrit Pape @ 2006-07-29 16:26 UTC (permalink / raw)
To: git
Patch from Petr Salinger to make the build process detect and support the
Debian GNU/kFreeBSD architecture, see
http://bugs.debian.org/380209
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
Makefile | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index 8349e3d..91ba183 100644
--- a/Makefile
+++ b/Makefile
@@ -264,6 +264,9 @@ # we had "elif" things would have been m
ifeq ($(uname_S),Linux)
NO_STRLCPY = YesPlease
endif
+ifeq ($(uname_S),GNU/kFreeBSD)
+ NO_STRLCPY = YesPlease
+endif
ifeq ($(uname_S),Darwin)
NEEDS_SSL_WITH_CRYPTO = YesPlease
NEEDS_LIBICONV = YesPlease
--
1.4.1
^ permalink raw reply related
* Re: Java GIT/Eclipse GIT version 0.1.1
From: Peter Baumann @ 2006-07-29 16:46 UTC (permalink / raw)
To: git
In-Reply-To: <1154139012.3154.38.camel@dv>
On 2006-07-29, Pavel Roskin <proski@gnu.org> wrote:
> On Fri, 2006-07-28 at 09:23 +0200, Peter Baumann wrote:
>> >> *** glibc detected *** double free or corruption (!prev): 0x080933b0 ***
>> >> /usr/bin/git-clone: line 29: 10712 Aborted git-http-fetch -v
>> >> -a -w "$tname" "$name" "$1/"
>> >
>> > I'm not getting that. I hope you are just using an obsolete version of git.
>>
>> Not _that_ old, me thinks. I'm using the debian unstable version.
>
> I tried to reproduce it but couldn't. I tried valgrind (3.2.0 and
> current) on two architectures, I tried _FORTIFY_SOURCE=2 to no avail -
> it just won't crash or report anything suspicious. It's the current
> master branch of git.
>
> So, it's up to you to debug it.
>
Strange. Running git-clone now works.
devil:~ cd src; git clone http://www.spearce.org/projects/scm/egit.git
error: File ac32c7cc2f7cf87a1ed80d0cdfca2af2a0385bb2
(http://www.spearce.org/projects/scm/egit.git/objects/ac/32c7cc2f7cf87a1ed80d0cdfca2af2a0385bb2)
corrupt
Getting pack list for http://www.spearce.org/projects/scm/egit.git/
error: XML error: not well-formed (invalid token)
Getting index for pack 052a98c5ca30068b8ecda3302198174e4588bab1
Getting pack 052a98c5ca30068b8ecda3302198174e4588bab1
which contains ac32c7cc2f7cf87a1ed80d0cdfca2af2a0385bb2
walk ac32c7cc2f7cf87a1ed80d0cdfca2af2a0385bb2
[... lots of correct looking walk's ...]
walk c1f287cb19b9910af19756cf29c08b1fda75da8c
Some loose object were found to be corrupt, but they might be just
a false '404 Not Found' error message sent with incorrect HTTP
status code. Suggest running git fsck-objects.
got eab86de8ac23e2e77878835007724146fdd83796
And git-fsck-objects --full doesn't barf, so it should be ok. Could it
be related that I am not using a proxy today (as last time)?
-Peter
^ permalink raw reply
* Re: Call setup_git_directory() early
From: Linus Torvalds @ 2006-07-29 16:52 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vzmesg4g3.fsf@assigned-by-dhcp.cox.net>
On Sat, 29 Jul 2006, Junio C Hamano wrote:
>
> > +#define NEEDS_PREFIX 1
> >...
> > { "init-db", cmd_init_db },
>
> This is an oddball that wants to always use $GIT_DIR environment
> or "./.git" if $GIT_DIR is not exported, and should never go
> looking for GIT_DIR, so we should not give NEEDS_PREFIX, ever.
Well, the way I did things, each command _can_ still decide to call
"setup_git_directory()" on their own, and we don't actually say up front
whether they will or not.
So some commands will just choose to let the git.c wrapper do it for them,
and others can do it their own way, which leaves the maximum of
flexibility, and doesn't mean that odd-balls like "init-db" really have to
even be an issue.
> > { "stripspace", cmd_stripspace },
> > { "mailsplit", cmd_mailsplit },
> > { "get-tar-commit-id", cmd_get_tar_commit_id },
>
> These are the other extreme -- they really do not care about
> operating in a git context.
Right.
> { "push", cmd_push },
> { "count-objects", cmd_count_objects },
> { "check-ref-format", cmd_check_ref_format },
>
> One rule seems to be that the commands that work at the while
> repository level do not have NEEDS_PREFIX -- they will never
> work from a subdirectory.
Well, maybe we will make them do so, and maybe we won't.
The way I chose the NEED_PREFIX ones was actually really simple and
totally automated: I changed every builtin function to first _not_ have
NEEDS_PREFIX, but changed the prototype to take "const char *prefix"
instead of the "char **envp" that nobody actually used.
I then compiled them, and for each function that _already_ had a "prefix"
in their existing implementation (which the compiler warned about), I
just removed the old "prefix = setup_git_directory()", and added the
NEEDS_PREFIX flag for that command.
> There is no technical reason not to let count-objects find
> $GIT_DIR on its own, but the current implementation does not do
> that and you are keeping the behaviour bug-to-bug compatible.
Exactly. My conversions (both the first smaller one, and the second thing)
were really totally mindless translations, nothing fancy. I fixed a few
bugs as I hit them (ie the first one moved the "setup_git_directory()"
call earlier over some "git_config()" calls), but other than those kinds
of local changes, I tried to keep not just the patch, but very much the
process of me creating it, very straightforward.
> > { "rev-list", cmd_rev_list },
>
> I think we should mark this with NEEDS_PREFIX, and lose the call
> to setup_git_directory() it has here:
I think you're right, and the above explanation of how the patch was
mindlessly created explains why my patch didn't do it that way ;)
When I do re-organizations, I like doing them in two stages: the
"mindless" stage that does the bulk of the syntactic stuff and the
movement of code, but that pretty much by definition should not introduce
any new bugs, and then the second stage is the "ok, now we have the new
organization, we can clean up and fix problems".
Linus
^ permalink raw reply
* Re: git prune pig slow
From: Linus Torvalds @ 2006-07-29 18:14 UTC (permalink / raw)
To: Russell King; +Cc: git
In-Reply-To: <20060729090250.GC26956@flint.arm.linux.org.uk>
On Sat, 29 Jul 2006, Russell King wrote:
>
> I killed it after 10 minutes and decided to do the job manually -
> git-fsck-objects --unreachable and deleting the objects one by one is
> _much_ quicker than git-fsck-objects --full --cache --unreachable.
It's also very dangerous.
If you have partial packing (which you can get if you fetch data using
rsync or http, for example), not havign the "--full" means that
git-fsck-objects will report on objects being "unreachable" if they are
only reachable from another object that is packed.
Now, in practice, if you only use the git native protocol, this should
never happen, and you're fine. But there's a _very_ real reason why "git
prune" passes the "--full" flag to git-fsck-cache. "git prune" is simply
too dangerous without it.
That said, the current "git prune" in 1.4.2-rc is much faster, because it
does the reachability analysis on its own, and doesn't do all the other
things that git-fsck-cache does.
Btw, another alternative to "git prune" is actually to do
git repack -a -d
and then just delete all unpacked objects.
Linus
^ permalink raw reply
* Re: git prune pig slow
From: Linus Torvalds @ 2006-07-29 20:03 UTC (permalink / raw)
To: Russell King; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0607291110180.4168@g5.osdl.org>
On Sat, 29 Jul 2006, Linus Torvalds wrote:
>
> It's also very dangerous.
>
> If you have partial packing (which you can get if you fetch data using
> rsync or http, for example), not havign the "--full" means that
> git-fsck-objects will report on objects being "unreachable" if they are
> only reachable from another object that is packed.
>
> Now, in practice, if you only use the git native protocol, this should
> never happen, and you're fine.
Side note: in _practice_, it probably doesn't happen even with rsync and
http, so in that sense, it's true that "--full" is almost always likely to
just be a waste of time, and I can't come up with a schenario where you
really need "--full" for pruning unless you did something strange. All the
normal workflows means that if you have an object that is in a pack,
everything it points to will _also_ be in a pack, and as such, "git prune"
would never remove anything that wasn't safe to remove, even without the
"--full".
But just to get an example of how a _strange_ schenario could happen,
let's say that
- you're tracking a upstreams repository using rsync or http (ie you will
get the objects in the same format that upstream tracks them, either as
individual objects, or as "packs")
- that upstreams repository does _incremental_ repacks every once in a
while.
- the last time you fetched was _just_ before upstream did an incremental
pack, we call this "State A".
As a result, you now have his old state A all as individual
objects in your object database.
- you fetch again, now after upstream has done _two_ incremntal packs
(one to pack all the loose objects that you already had, and one to
pack the new state). Upstream is now at "State B"
As a result, you get all of his _new_ objects as one nice pack:
you do not get his other pack, because you already have all
_those_ objects (which are "state A") as individual objects.
- so now, since you're only tracking the other ends state, and have no
objects of your own (in particular, the last fetch/pull did _not_
generate a merge object of your own to connect the new pack with the
old objects), what has happened is that all your heads point into the
new incremental pack you just fetched, and that pack itself will have
pointers to the individual objects that you fetched last time, because
it was an incremental pack to "state A".
- what happens now is that if you run "git-fsck-objects" without the
"--full", it will claim that _all_ of your unpacked objects are
unreachable, because they really are reachable only though that new
pack.
So in this (very very unusual) circumstance, "git prune" without the
"--full" would literally prune away objects that you very much need.
I hope this explains why that "unnecessary" (and admittedly much more
expensive) --full is there. It really is unnecessary in practice: partly
because Junio has made "git repack -a -d" so efficient that doing
incremental packs isn't even worth it for most people, and partly because
you probably use the native git protocol and repack yourself, and thus
never use another persons pack directly (which also avoids this problem).
But yeah, the olf "git prune" was really very expensive. It's much better
in the current git branch, although it's still not _cheap_ (because it
does do the whole reachability analysis, though all pack-files, because it
wants to get the above special case right).
If we really wanted to, we could add a "core.fullpacks" flag that you
could set, and that would cause the non-native protocols to not work (or
alternatively force a re-pack after they have fetched a pack), and that
would disallow incremental repacking locally, and then we could optimize
the hell out of "git prune" and say that it never needs to look at any
reachability for an object that is already packed.
That would make "git prune" basically instantaneous, the way "git
fsck-objects" is by default. But to be safe, it really needs to have some
per-repository flag that is honored by the other git commands.
Linus
^ permalink raw reply
* [PATCH 0] Some gitweb patches
From: Jakub Narebski @ 2006-07-29 20:39 UTC (permalink / raw)
To: git
This series of patches, based on 'next' branch (v1.4.2-rc2-g688a750 or
688a75071490101dbc660e3304aafb7a13e28807) is the beginning of gitweb
cleanup. It would hopefully introduce no new features.
Open-ended series...
--
Jakub Narebski
Poland
^ permalink raw reply
* [PATCH 1] gitweb: whitespace cleanup
From: Jakub Narebski @ 2006-07-29 20:43 UTC (permalink / raw)
To: git
In-Reply-To: <200607292239.11034.jnareb@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Use tab for indenting commands, spaces for align
(because the fact that some elements are aligned
should not depend on the tab width).
gitweb/gitweb.cgi | 58 +++++++++++++++++++++++++++--------------------------
1 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index e5fca63..f92eeab 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -36,7 +36,7 @@ our $git_version = qx($GIT --version) =~
# location for temporary files needed for diffs
our $git_temp = "/tmp/gitweb";
if (! -d $git_temp) {
- mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp");
+ mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp");
}
# target of the home link on top of all pages
@@ -104,7 +104,7 @@ if (defined $project) {
die_error(undef, "No such project.");
}
$rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" .
- "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
+ "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
$ENV{'GIT_DIR'} = "$projectroot/$project";
} else {
git_project_list();
@@ -303,7 +303,7 @@ sub git_header_html {
} else {
$content_type = 'text/html';
}
- print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
+ print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
print <<EOF;
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -1138,17 +1138,17 @@ sub git_summary {
"</td>\n" .
"<td>";
if (defined($comment)) {
- print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment));
+ print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment));
}
print "</td>\n" .
"<td class=\"link\">";
if ($tag{'type'} eq "tag") {
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
}
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
if ($tag{'reftype'} eq "commit") {
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
+ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
}
print "</td>\n" .
"</tr>";
@@ -1457,17 +1457,17 @@ sub git_tags {
"</td>\n" .
"<td>";
if (defined($comment)) {
- print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+ print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
}
print "</td>\n" .
"<td class=\"link\">";
if ($tag{'type'} eq "tag") {
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
}
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
if ($tag{'reftype'} eq "commit") {
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
+ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
}
print "</td>\n" .
"</tr>";
@@ -1613,13 +1613,14 @@ sub git_blob_plain_mimetype {
sub git_blob_plain {
if (!defined $hash) {
- if (defined $file_name) {
- my $base = $hash_base || git_read_head($project);
- $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
- } else {
- die_error(undef, "No file name defined.");
- }
- }
+ if (defined $file_name) {
+ my $base = $hash_base || git_read_head($project);
+ $hash = git_get_hash_by_path($base, $file_name, "blob")
+ or die_error(undef, "Error lookup file.");
+ } else {
+ die_error(undef, "No file name defined.");
+ }
+ }
my $type = shift;
open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
@@ -1644,13 +1645,14 @@ sub git_blob_plain {
sub git_blob {
if (!defined $hash) {
- if (defined $file_name) {
- my $base = $hash_base || git_read_head($project);
- $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
- } else {
- die_error(undef, "No file name defined.");
- }
- }
+ if (defined $file_name) {
+ my $base = $hash_base || git_read_head($project);
+ $hash = git_get_hash_by_path($base, $file_name, "blob")
+ or die_error(undef, "Error lookup file.");
+ } else {
+ die_error(undef, "No file name defined.");
+ }
+ }
my $have_blame = git_get_project_config_bool ('blame');
open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed.");
my $mimetype = git_blob_plain_mimetype($fd, $file_name);
@@ -1677,7 +1679,7 @@ sub git_blob {
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
}
print "</div>\n".
- "<div>" .
+ "<div>" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
"</div>\n";
} else {
@@ -2305,7 +2307,7 @@ sub git_commitdiff {
my $status = $5;
my $file = validate_input(unquote($6));
if ($status eq "A") {
- print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
+ print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
"</div>\n";
git_diff_print(undef, "/dev/null", $to_id, "b/$file");
@@ -2359,7 +2361,7 @@ sub git_commitdiff_plain {
"Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
"Subject: $co{'title'}\n";
if (defined $tagname) {
- print "X-Git-Tag: $tagname\n";
+ print "X-Git-Tag: $tagname\n";
}
print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
"\n";
--
1.4.0
^ permalink raw reply related
* [PATCH 2] gitweb: Use list for of open for running git commands, thorougly.
From: Jakub Narebski @ 2006-07-29 20:51 UTC (permalink / raw)
To: git
In-Reply-To: <200607292239.11034.jnareb@gmail.com>
Use list form of open for running git commands and reading their
output through pipe, for example
open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash
instead of
open my $fd, "-|", "$GIT rev-list --header --parents $hash"
Single letter options use ' instead of " as quotes, according to style
used in list form of magic "-|" open.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
The correct solution would be to use safe_pipe_capture or,
what's better, use Git.pm, when it will be in released version.
Should have no impact on speed. Using ' instead of " could bring
insignificant speedup.
gitweb/gitweb.cgi | 45 +++++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index f92eeab..9a17f87 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -388,7 +388,7 @@ sub die_error {
sub git_get_type {
my $hash = shift;
- open my $fd, "-|", "$GIT cat-file -t $hash" or return;
+ open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
my $type = <$fd>;
close $fd or return;
chomp $type;
@@ -440,7 +440,7 @@ sub git_read_tag {
my %tag;
my @comment;
- open my $fd, "-|", "$GIT cat-file tag $tag_id" or return;
+ open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
$tag{'id'} = $tag_id;
while (my $line = <$fd>) {
chomp $line;
@@ -512,7 +512,7 @@ sub git_read_commit {
@commit_lines = @$commit_text;
} else {
$/ = "\0";
- open my $fd, "-|", "$GIT rev-list --header --parents --max-count=1 $commit_id" or return;
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
@commit_lines = split '\n', <$fd>;
close $fd or return;
$/ = "\n";
@@ -610,7 +610,7 @@ sub git_diff_print {
if (defined $from) {
$from_tmp = "$git_temp/gitweb_" . $$ . "_from";
open my $fd2, "> $from_tmp";
- open my $fd, "-|", "$GIT cat-file blob $from";
+ open my $fd, "-|", $GIT, "cat-file", "blob", $from;
my @file = <$fd>;
print $fd2 @file;
close $fd2;
@@ -621,7 +621,7 @@ sub git_diff_print {
if (defined $to) {
$to_tmp = "$git_temp/gitweb_" . $$ . "_to";
open my $fd2, "> $to_tmp";
- open my $fd, "-|", "$GIT cat-file blob $to";
+ open my $fd, "-|", $GIT, "cat-file", "blob", $to;
my @file = <$fd>;
print $fd2 @file;
close $fd2;
@@ -1062,7 +1062,8 @@ sub git_summary {
"<tr><td>owner</td><td>$owner</td></tr>\n" .
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
"</table>\n";
- open my $fd, "-|", "$GIT rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
+ or die_error(undef, "Open failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
print "<div>\n" .
@@ -1526,7 +1527,7 @@ sub git_get_hash_by_path {
my $tree = $base;
my @parts = split '/', $path;
while (my $part = shift @parts) {
- open my $fd, "-|", "$GIT ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
+ open my $fd, "-|", $GIT, "ls-tree", $tree or die_error(undef, "Open git-ls-tree failed.");
my (@entries) = map { chomp; $_ } <$fd>;
close $fd or return undef;
foreach my $line (@entries) {
@@ -1622,7 +1623,7 @@ sub git_blob_plain {
}
}
my $type = shift;
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error("Couldn't cat $file_name, $hash");
$type ||= git_blob_plain_mimetype($fd, $file_name);
@@ -1654,7 +1655,7 @@ sub git_blob {
}
}
my $have_blame = git_get_project_config_bool ('blame');
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error(undef, "Open failed.");
my $mimetype = git_blob_plain_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
close $fd;
@@ -1718,7 +1719,7 @@ sub git_tree {
}
}
$/ = "\0";
- open my $fd, "-|", "$GIT ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
+ open my $fd, "-|", $GIT, "ls-tree", '-z', $hash or die_error(undef, "Open git-ls-tree failed.");
chomp (my (@entries) = <$fd>);
close $fd or die_error(undef, "Reading tree failed.");
$/ = "\n";
@@ -1799,7 +1800,8 @@ # " | " . $cgi->a({-href => "$my
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
- open my $fd, "-|", "$GIT rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head($project)
+ or die_error(undef, "Open failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading rev-list failed.");
print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
@@ -1819,7 +1821,7 @@ sub git_rss {
last;
}
my %cd = date_str($co{'committer_epoch'});
- open $fd, "-|", "$GIT diff-tree -r $co{'parent'} $co{'id'}" or next;
+ open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
my @difftree = map { chomp; $_ } <$fd>;
close $fd or next;
print "<item>\n" .
@@ -1907,7 +1909,7 @@ sub git_log {
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
@@ -1998,7 +2000,8 @@ sub git_commit {
$root = " --root";
$parent = "";
}
- open my $fd, "-|", "$GIT diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $root, $parent, $hash
+ or die_error(undef, "Open failed.");
@difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
@@ -2244,7 +2247,8 @@ sub git_commitdiff {
if (!defined $hash_parent) {
$hash_parent = $co{'parent'};
}
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
+ or die_error(undef, "Open failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
@@ -2334,14 +2338,15 @@ sub git_commitdiff {
sub git_commitdiff_plain {
mkdir($git_temp, 0700);
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
+ or die_error(undef, "Open failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
# try to figure out the next tag after this commit
my $tagname;
my $refs = read_info_ref("tags");
- open $fd, "-|", "$GIT rev-list HEAD";
+ open $fd, "-|", $GIT, "rev-list", "HEAD";
chomp (my (@commits) = <$fd>);
close $fd;
foreach my $commit (@commits) {
@@ -2419,7 +2424,7 @@ sub git_history {
git_print_page_path($file_name, $ftype);
open my $fd, "-|",
- "$GIT rev-list --full-history $hash_base -- \'$file_name\'";
+ $GIT, "rev-list", "--full-history", $hash_base, "--", "\'$file_name\'";
print "<table cellspacing=\"0\">\n";
my $alternate = 0;
while (my $line = <$fd>) {
@@ -2506,7 +2511,7 @@ sub git_search {
my $alternate = 0;
if ($commit_search) {
$/ = "\0";
- open my $fd, "-|", "$GIT rev-list --header --parents $hash" or next;
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
while (my $commit_text = <$fd>) {
if (!grep m/$searchtext/i, $commit_text) {
next;
@@ -2627,7 +2632,7 @@ sub git_shortlog {
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
--
1.4.0
^ permalink raw reply related
* [PATCH 3] gitweb: simplify git_get_hash_by_path
From: Jakub Narebski @ 2006-07-29 20:55 UTC (permalink / raw)
To: git
In-Reply-To: <200607292239.11034.jnareb@gmail.com>
Simplify git_get_hash_by_path by using git-ls-tree to do path
limiting, instead of finding correct ttree and parsing unconstrained
git-ls-tree output.
_Should_ be slightly faster.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Testing speed before and after this patch using ApacheBench
on git.git repository has shown speedup withing error. Perhaps
sample size was too small...
Speedup should be larger for deeper nested projects with larger number
of files in a directory.
Not extensively tested!
gitweb/gitweb.cgi | 32 +++++++++-----------------------
1 files changed, 9 insertions(+), 23 deletions(-)
diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index 9a17f87..e1a817b 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -1525,29 +1525,15 @@ sub git_get_hash_by_path {
my $path = shift || return undef;
my $tree = $base;
- my @parts = split '/', $path;
- while (my $part = shift @parts) {
- open my $fd, "-|", $GIT, "ls-tree", $tree or die_error(undef, "Open git-ls-tree failed.");
- my (@entries) = map { chomp; $_ } <$fd>;
- close $fd or return undef;
- foreach my $line (@entries) {
- #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
- $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
- my $t_mode = $1;
- my $t_type = $2;
- my $t_hash = $3;
- my $t_name = validate_input(unquote($4));
- if ($t_name eq $part) {
- if (!(@parts)) {
- return $t_hash;
- }
- if ($t_type eq "tree") {
- $tree = $t_hash;
- }
- last;
- }
- }
- }
+
+ open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
+ or die_error(undef, "Open git-ls-tree failed.");
+ my $line = <$fd>;
+ close $fd or return undef;
+
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
+ $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
+ return $3;
}
sub mimetype_guess_file {
--
1.4.0
^ permalink raw reply related
* [PATCH 4] gitweb: More explicit error messages for open "-|"
From: Jakub Narebski @ 2006-07-29 21:01 UTC (permalink / raw)
To: git
In-Reply-To: <200607292239.11034.jnareb@gmail.com>
Use more explicit error messages when failing magical "-|" open,
stating at least the name of the git command that failed.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Should not affect web security.
gitweb/gitweb.cgi | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index e1a817b..2c67df0 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -1063,7 +1063,7 @@ sub git_summary {
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
"</table>\n";
open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
print "<div>\n" .
@@ -1271,7 +1271,7 @@ sub git_blame2 {
die_error("400 Bad Request", "object is not a blob");
}
open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
- or die_error(undef, "Open failed");
+ or die_error(undef, "Open git-blame failed.");
git_header_html();
print "<div class=\"page_nav\">\n" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1333,7 +1333,7 @@ sub git_blame {
or die_error(undef, "Error lookup file.");
}
open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-annotate failed.");
git_header_html();
print "<div class=\"page_nav\">\n" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1609,7 +1609,8 @@ sub git_blob_plain {
}
}
my $type = shift;
- open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error("Couldn't cat $file_name, $hash");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash
+ or die_error("Couldn't cat $file_name, $hash");
$type ||= git_blob_plain_mimetype($fd, $file_name);
@@ -1641,7 +1642,8 @@ sub git_blob {
}
}
my $have_blame = git_get_project_config_bool ('blame');
- open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash
+ or die_error(undef, "Couldn't cat $file_name, $hash.");
my $mimetype = git_blob_plain_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
close $fd;
@@ -1705,7 +1707,8 @@ sub git_tree {
}
}
$/ = "\0";
- open my $fd, "-|", $GIT, "ls-tree", '-z', $hash or die_error(undef, "Open git-ls-tree failed.");
+ open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
+ or die_error(undef, "Open git-ls-tree failed.");
chomp (my (@entries) = <$fd>);
close $fd or die_error(undef, "Reading tree failed.");
$/ = "\n";
@@ -1787,7 +1790,7 @@ # " | " . $cgi->a({-href => "$my
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head($project)
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading rev-list failed.");
print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
@@ -1895,7 +1898,8 @@ sub git_log {
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
@@ -1987,7 +1991,7 @@ sub git_commit {
$parent = "";
}
open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $root, $parent, $hash
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-diff-tree failed.");
@difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
@@ -2234,7 +2238,7 @@ sub git_commitdiff {
$hash_parent = $co{'parent'};
}
open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-diff-tree failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
@@ -2325,7 +2329,7 @@ sub git_commitdiff {
sub git_commitdiff_plain {
mkdir($git_temp, 0700);
open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-diff-tree failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
@@ -2618,7 +2622,8 @@ sub git_shortlog {
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
--
1.4.0
^ permalink raw reply related
* [PATCH] pager: config variable pager.program
From: Matthias Lederhofer @ 2006-07-29 21:28 UTC (permalink / raw)
To: git
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
I'd like to use another pager (or other options) with git than the
normal pager. Normally I would not want the -R option with less but
for git less should show colors.
---
Documentation/config.txt | 5 +++++
| 16 +++++++++++++++-
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 465eb13..96429b6 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -116,6 +116,11 @@ apply.whitespace::
Tells `git-apply` how to handle whitespaces, in the same way
as the '--whitespace' option. See gitlink:git-apply[1].
+pager.program::
+ Use this program as pager. git will try this configuration
+ variable first, then the 'PAGER' environment variable and
+ "less" as fallback.
+
diff.color::
When true (or `always`), always use colors in patch.
When false (or `never`), never. When set to `auto`, use
--git a/pager.c b/pager.c
index 280f57f..3f753f6 100644
--- a/pager.c
+++ b/pager.c
@@ -5,6 +5,18 @@ #include "cache.h"
* something different on Windows, for example.
*/
+static const char *pager = NULL;
+
+static int git_pager_config(const char *var, const char *value)
+{
+ if (!strcmp(var, "pager.program")) {
+ if (value)
+ pager = strdup(value);
+ return 0;
+ }
+ return 0;
+}
+
static void run_pager(const char *pager)
{
execlp(pager, pager, NULL);
@@ -15,10 +27,12 @@ void setup_pager(void)
{
pid_t pid;
int fd[2];
- const char *pager = getenv("PAGER");
if (!isatty(1))
return;
+ git_config(git_pager_config);
+ if (!pager)
+ pager = getenv("PAGER");
if (!pager)
pager = "less";
else if (!*pager || !strcmp(pager, "cat"))
--
1.4.2.rc2.g688a
^ permalink raw reply related
* [PATCH] pager: config variable pager.color
From: Matthias Lederhofer @ 2006-07-29 22:27 UTC (permalink / raw)
To: git
enable/disable colored output when the pager is in use
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
setup_pager has to be called before git_diff_ui_config because the
latter uses pager_use_color initialized by setup_pager.
---
Documentation/config.txt | 4 ++++
builtin-log.c | 4 +++-
cache.h | 1 +
diff.c | 2 +-
environment.c | 1 +
| 4 ++++
6 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 96429b6..5e243a8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -121,6 +121,10 @@ pager.program::
variable first, then the 'PAGER' environment variable and
"less" as fallback.
+pager.color::
+ A boolean to enable/disable colored output when the pager is in
+ use (default is true).
+
diff.color::
When true (or `always`), always use colors in patch.
When false (or `never`), never. When set to `auto`, use
diff --git a/builtin-log.c b/builtin-log.c
index 82c69d1..7fdefec 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -34,7 +34,6 @@ static int cmd_log_walk(struct rev_info
struct commit *commit;
prepare_revision_walk(rev);
- setup_pager();
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
@@ -49,6 +48,7 @@ int cmd_whatchanged(int argc, const char
{
struct rev_info rev;
+ setup_pager();
git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
rev.diff = 1;
@@ -64,6 +64,7 @@ int cmd_show(int argc, const char **argv
{
struct rev_info rev;
+ setup_pager();
git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
rev.diff = 1;
@@ -81,6 +82,7 @@ int cmd_log(int argc, const char **argv,
{
struct rev_info rev;
+ setup_pager();
git_config(git_diff_ui_config);
init_revisions(&rev, prefix);
rev.always_show_header = 1;
diff --git a/cache.h b/cache.h
index 8891073..913be6a 100644
--- a/cache.h
+++ b/cache.h
@@ -392,6 +392,7 @@ extern int receive_keep_pack(int fd[2],
/* pager.c */
extern void setup_pager(void);
extern int pager_in_use;
+extern int pager_use_color;
/* base85 */
int decode_85(char *dst, char *line, int linelen);
diff --git a/diff.c b/diff.c
index 6198a61..16d47bf 100644
--- a/diff.c
+++ b/diff.c
@@ -175,7 +175,7 @@ int git_diff_ui_config(const char *var,
diff_use_color_default = 1; /* bool */
else if (!strcasecmp(value, "auto")) {
diff_use_color_default = 0;
- if (isatty(1) || pager_in_use) {
+ if (isatty(1) || (pager_in_use && pager_use_color)) {
char *term = getenv("TERM");
if (term && strcmp(term, "dumb"))
diff_use_color_default = 1;
diff --git a/environment.c b/environment.c
index 558801a..1ce3411 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,7 @@ int shared_repository = PERM_UMASK;
const char *apply_default_whitespace = NULL;
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
int pager_in_use;
+int pager_use_color = 1;
static int dyn_git_object_dir, dyn_git_index_file, dyn_git_graft_file;
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
--git a/pager.c b/pager.c
index 3f753f6..afd684e 100644
--- a/pager.c
+++ b/pager.c
@@ -14,6 +14,10 @@ static int git_pager_config(const char *
pager = strdup(value);
return 0;
}
+ if (!strcmp(var, "pager.color")) {
+ pager_use_color = git_config_bool(var,value);
+ return 0;
+ }
return 0;
}
--
1.4.2.rc2.g91b7
^ permalink raw reply related
* Re: git prune pig slow
From: linux @ 2006-07-29 22:41 UTC (permalink / raw)
To: git; +Cc: torvalds
> Btw, another alternative to "git prune" is actually to do
>
> git repack -a -d
>
> and then just delete all unpacked objects.
No, that's dangerous too. The index file is considered part of the root
set for git-fsck-objects, but not for git-repack.
Example script:
$ git-init-db
$ cat > hello.c
#include <stdio.h>
int
main(void)
{
puts("Hello, world!");
return 0;
}
$ git-update-index --add hello.c
$ git-repack -a -d
Generating pack...
Done counting 0 objects.
Nothing new to pack.
$ rm .git/objects/67/159ba959e0a0cd6157bf04d5dad66af59383c2
rm: remove write-protected regular file `.git/objects/67/159ba959e0a0cd6157bf04d5dad66af59383c2'? y
$ git commit
error: invalid object 67159ba959e0a0cd6157bf04d5dad66af59383c2
fatal: git-write-tree: error building trees
^ permalink raw reply
* Re: [PATCH] pager: config variable pager.color
From: Johannes Schindelin @ 2006-07-29 23:15 UTC (permalink / raw)
To: Matthias Lederhofer; +Cc: git
In-Reply-To: <E1G6xHb-0008Rw-G2@moooo.ath.cx>
Hi,
On Sun, 30 Jul 2006, Matthias Lederhofer wrote:
> diff --git a/builtin-log.c b/builtin-log.c
> index 82c69d1..7fdefec 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -34,7 +34,6 @@ static int cmd_log_walk(struct rev_info
> struct commit *commit;
>
> prepare_revision_walk(rev);
> - setup_pager();
> while ((commit = get_revision(rev)) != NULL) {
> log_tree_commit(rev, commit);
> free(commit->buffer);
> @@ -49,6 +48,7 @@ int cmd_whatchanged(int argc, const char
> {
> struct rev_info rev;
>
> + setup_pager();
> git_config(git_diff_ui_config);
> init_revisions(&rev, prefix);
> rev.diff = 1;
> @@ -64,6 +64,7 @@ int cmd_show(int argc, const char **argv
> {
> struct rev_info rev;
>
> + setup_pager();
> git_config(git_diff_ui_config);
> init_revisions(&rev, prefix);
> rev.diff = 1;
> @@ -81,6 +82,7 @@ int cmd_log(int argc, const char **argv,
> {
> struct rev_info rev;
>
> + setup_pager();
> git_config(git_diff_ui_config);
> init_revisions(&rev, prefix);
> rev.always_show_header = 1;
Why? The three users of cmd_log_walk() need to call setup_pager()
explicitely, when cmd_log_walk() can do it for them?
Oh, and I do not really understand why you would enable color _at all_ if
you want to disable it when paging. Do you have many instances when you
want a color diff which is short enough not to be paged?
Ciao,
Dscho
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox