Skip to content

Commit 81a7173

Browse files
author
Junio C Hamano
committed
Revert "Make it possible to set up libgit directly (instead of from the environment)"
This reverts commit 0270083.
1 parent 9594b32 commit 81a7173

File tree

7 files changed

+24
-114
lines changed

7 files changed

+24
-114
lines changed

cache.h

-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
117117
extern struct cache_tree *active_cache_tree;
118118
extern int cache_errno;
119119

120-
extern void setup_git(char *new_git_dir, char *new_git_object_dir,
121-
char *new_git_index_file, char *new_git_graft_file);
122-
123120
#define GIT_DIR_ENVIRONMENT "GIT_DIR"
124121
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
125122
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"

commit.c

+4-19
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,6 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
163163
return 0;
164164
}
165165

166-
void free_commit_grafts(void)
167-
{
168-
int pos = commit_graft_nr;
169-
while (pos >= 0)
170-
free(commit_graft[pos--]);
171-
commit_graft_nr = 0;
172-
}
173-
174166
struct commit_graft *read_graft_line(char *buf, int len)
175167
{
176168
/* The format is just "Commit Parent1 Parent2 ...\n" */
@@ -223,18 +215,11 @@ int read_graft_file(const char *graft_file)
223215
static void prepare_commit_graft(void)
224216
{
225217
static int commit_graft_prepared;
226-
static char *last_graft_file;
227-
char *graft_file = get_graft_file();
228-
229-
if (last_graft_file) {
230-
if (!strcmp(graft_file, last_graft_file))
231-
return;
232-
free_commit_grafts();
233-
}
234-
if (last_graft_file)
235-
free(last_graft_file);
236-
last_graft_file = strdup(graft_file);
218+
char *graft_file;
237219

220+
if (commit_graft_prepared)
221+
return;
222+
graft_file = get_graft_file();
238223
read_graft_file(graft_file);
239224
commit_graft_prepared = 1;
240225
}

environment.c

+6-39
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,28 @@ int zlib_compression_level = Z_DEFAULT_COMPRESSION;
2525
int pager_in_use;
2626
int pager_use_color = 1;
2727

28-
static int dyn_git_object_dir, dyn_git_index_file, dyn_git_graft_file;
2928
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
3029
*git_graft_file;
31-
32-
void setup_git(char *new_git_dir, char *new_git_object_dir,
33-
char *new_git_index_file, char *new_git_graft_file)
30+
static void setup_git_env(void)
3431
{
35-
git_dir = new_git_dir;
32+
git_dir = getenv(GIT_DIR_ENVIRONMENT);
3633
if (!git_dir)
3734
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
38-
39-
if (dyn_git_object_dir)
40-
free(git_object_dir);
41-
git_object_dir = new_git_object_dir;
35+
git_object_dir = getenv(DB_ENVIRONMENT);
4236
if (!git_object_dir) {
4337
git_object_dir = xmalloc(strlen(git_dir) + 9);
4438
sprintf(git_object_dir, "%s/objects", git_dir);
45-
dyn_git_object_dir = 1;
46-
} else {
47-
dyn_git_object_dir = 0;
4839
}
49-
50-
if (git_refs_dir)
51-
free(git_refs_dir);
5240
git_refs_dir = xmalloc(strlen(git_dir) + 6);
5341
sprintf(git_refs_dir, "%s/refs", git_dir);
54-
55-
if (dyn_git_index_file)
56-
free(git_index_file);
57-
git_index_file = new_git_index_file;
42+
git_index_file = getenv(INDEX_ENVIRONMENT);
5843
if (!git_index_file) {
5944
git_index_file = xmalloc(strlen(git_dir) + 7);
6045
sprintf(git_index_file, "%s/index", git_dir);
61-
dyn_git_index_file = 1;
62-
} else {
63-
dyn_git_index_file = 0;
6446
}
65-
66-
if (dyn_git_graft_file)
67-
free(git_graft_file);
68-
git_graft_file = new_git_graft_file;
69-
if (!git_graft_file) {
47+
git_graft_file = getenv(GRAFT_ENVIRONMENT);
48+
if (!git_graft_file)
7049
git_graft_file = strdup(git_path("info/grafts"));
71-
dyn_git_graft_file = 1;
72-
} else {
73-
dyn_git_graft_file = 0;
74-
}
75-
}
76-
77-
static void setup_git_env(void)
78-
{
79-
setup_git(getenv(GIT_DIR_ENVIRONMENT),
80-
getenv(DB_ENVIRONMENT),
81-
getenv(INDEX_ENVIRONMENT),
82-
getenv(GRAFT_ENVIRONMENT));
8350
}
8451

8552
char *get_git_dir(void)

perl/Git.pm

+5-6
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ XSLoader::load('Git', $VERSION);
9898

9999
}
100100

101-
my $instance_id = 0;
102-
103101

104102
=head1 CONSTRUCTORS
105103
@@ -217,7 +215,7 @@ sub repository {
217215
delete $opts{Directory};
218216
}
219217

220-
$self = { opts => \%opts, id => $instance_id++ };
218+
$self = { opts => \%opts };
221219
bless $self, $class;
222220
}
223221

@@ -835,10 +833,11 @@ sub _call_gate {
835833
if (defined $self) {
836834
# XXX: We ignore the WorkingCopy! To properly support
837835
# that will require heavy changes in libgit.
838-
# For now, when we will need to do it we could temporarily
839-
# chdir() there and then chdir() back after the call is done.
840836

841-
xs__call_gate($self->{id}, $self->repo_path());
837+
# XXX: And we ignore everything else as well. libgit
838+
# at least needs to be extended to let us specify
839+
# the $GIT_DIR instead of looking it up in environment.
840+
#xs_call_gate($self->{opts}->{Repository});
842841
}
843842

844843
# Having to call throw from the C code is a sure path to insanity.

perl/Git.xs

+1-15
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,7 @@ BOOT:
5252
}
5353

5454

55-
void
56-
xs__call_gate(repoid, git_dir)
57-
long repoid;
58-
char *git_dir;
59-
CODE:
60-
{
61-
static long last_repoid;
62-
if (repoid != last_repoid) {
63-
setup_git(git_dir,
64-
getenv(DB_ENVIRONMENT),
65-
getenv(INDEX_ENVIRONMENT),
66-
getenv(GRAFT_ENVIRONMENT));
67-
last_repoid = repoid;
68-
}
69-
}
55+
# /* TODO: xs_call_gate(). See Git.pm. */
7056

7157

7258
char *

sha1_file.c

+6-24
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,16 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
126126
char *sha1_file_name(const unsigned char *sha1)
127127
{
128128
static char *name, *base;
129-
static const char *last_objdir;
130-
const char *sha1_file_directory = get_object_directory();
131129

132-
if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
130+
if (!base) {
131+
const char *sha1_file_directory = get_object_directory();
133132
int len = strlen(sha1_file_directory);
134-
if (base)
135-
free(base);
136133
base = xmalloc(len + 60);
137134
memcpy(base, sha1_file_directory, len);
138135
memset(base+len, 0, 60);
139136
base[len] = '/';
140137
base[len+3] = '/';
141138
name = base + len + 1;
142-
if (last_objdir)
143-
free((char *) last_objdir);
144-
last_objdir = strdup(sha1_file_directory);
145139
}
146140
fill_sha1_path(name, sha1);
147141
return base;
@@ -151,20 +145,14 @@ char *sha1_pack_name(const unsigned char *sha1)
151145
{
152146
static const char hex[] = "0123456789abcdef";
153147
static char *name, *base, *buf;
154-
static const char *last_objdir;
155-
const char *sha1_file_directory = get_object_directory();
156148
int i;
157149

158-
if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
150+
if (!base) {
151+
const char *sha1_file_directory = get_object_directory();
159152
int len = strlen(sha1_file_directory);
160-
if (base)
161-
free(base);
162153
base = xmalloc(len + 60);
163154
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.pack", sha1_file_directory);
164155
name = base + len + 11;
165-
if (last_objdir)
166-
free((char *) last_objdir);
167-
last_objdir = strdup(sha1_file_directory);
168156
}
169157

170158
buf = name;
@@ -182,20 +170,14 @@ char *sha1_pack_index_name(const unsigned char *sha1)
182170
{
183171
static const char hex[] = "0123456789abcdef";
184172
static char *name, *base, *buf;
185-
static const char *last_objdir;
186-
const char *sha1_file_directory = get_object_directory();
187173
int i;
188174

189-
if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
175+
if (!base) {
176+
const char *sha1_file_directory = get_object_directory();
190177
int len = strlen(sha1_file_directory);
191-
if (base)
192-
free(base);
193178
base = xmalloc(len + 60);
194179
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.idx", sha1_file_directory);
195180
name = base + len + 11;
196-
if (last_objdir)
197-
free((char *) last_objdir);
198-
last_objdir = strdup(sha1_file_directory);
199181
}
200182

201183
buf = name;

sha1_name.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@ static int find_short_object_filename(int len, const char *name, unsigned char *
1212
char hex[40];
1313
int found = 0;
1414
static struct alternate_object_database *fakeent;
15-
static const char *last_objdir;
16-
const char *objdir = get_object_directory();
1715

18-
if (!last_objdir || strcmp(last_objdir, objdir)) {
16+
if (!fakeent) {
17+
const char *objdir = get_object_directory();
1918
int objdir_len = strlen(objdir);
2019
int entlen = objdir_len + 43;
21-
if (fakeent)
22-
free(fakeent);
2320
fakeent = xmalloc(sizeof(*fakeent) + entlen);
2421
memcpy(fakeent->base, objdir, objdir_len);
2522
fakeent->name = fakeent->base + objdir_len + 1;
2623
fakeent->name[-1] = '/';
27-
if (last_objdir)
28-
free((char *) last_objdir);
29-
last_objdir = strdup(objdir);
3024
}
3125
fakeent->next = alt_odb_list;
3226

0 commit comments

Comments
 (0)