Skip to content

Commit f23c75a

Browse files
author
Junio C Hamano
committed
Merge branch 'master' into js/merge-base
This is to pull in the object-hash clean-up from the master branch.
2 parents 160b798 + 8fced61 commit f23c75a

File tree

13 files changed

+163
-95
lines changed

13 files changed

+163
-95
lines changed

Documentation/git-commit.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ SYNOPSIS
1515
DESCRIPTION
1616
-----------
1717
Updates the index file for given paths, or all modified files if
18-
'-a' is specified, and makes a commit object. The command
19-
VISUAL and EDITOR environment variables to edit the commit log
20-
message.
18+
'-a' is specified, and makes a commit object. The command specified
19+
by either the VISUAL or EDITOR environment variables are used to edit
20+
the commit log message.
2121

2222
Several environment variable are used during commits. They are
2323
documented in gitlink:git-commit-tree[1].

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,11 @@ git-ssh-push$X: rsh.o
587587
git-imap-send$X: imap-send.o $(LIB_FILE)
588588

589589
http.o http-fetch.o http-push.o: http.h
590-
git-http-fetch$X: fetch.o http.o http-fetch.o $(LIB_FILE)
590+
git-http-fetch$X: fetch.o http.o http-fetch.o $(GITLIBS)
591591
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
592592
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
593593

594-
git-http-push$X: revision.o http.o http-push.o $(LIB_FILE)
594+
git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
595595
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
596596
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
597597

connect.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static enum protocol get_protocol(const char *name)
328328
*/
329329
static int git_tcp_connect_sock(char *host)
330330
{
331-
int sockfd = -1;
331+
int sockfd = -1, saved_errno = 0;
332332
char *colon, *end;
333333
const char *port = STR(DEFAULT_GIT_PORT);
334334
struct addrinfo hints, *ai0, *ai;
@@ -362,9 +362,12 @@ static int git_tcp_connect_sock(char *host)
362362
for (ai0 = ai; ai; ai = ai->ai_next) {
363363
sockfd = socket(ai->ai_family,
364364
ai->ai_socktype, ai->ai_protocol);
365-
if (sockfd < 0)
365+
if (sockfd < 0) {
366+
saved_errno = errno;
366367
continue;
368+
}
367369
if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
370+
saved_errno = errno;
368371
close(sockfd);
369372
sockfd = -1;
370373
continue;
@@ -375,7 +378,7 @@ static int git_tcp_connect_sock(char *host)
375378
freeaddrinfo(ai0);
376379

377380
if (sockfd < 0)
378-
die("unable to connect a socket (%s)", strerror(errno));
381+
die("unable to connect a socket (%s)", strerror(saved_errno));
379382

380383
return sockfd;
381384
}
@@ -387,7 +390,7 @@ static int git_tcp_connect_sock(char *host)
387390
*/
388391
static int git_tcp_connect_sock(char *host)
389392
{
390-
int sockfd = -1;
393+
int sockfd = -1, saved_errno = 0;
391394
char *colon, *end;
392395
char *port = STR(DEFAULT_GIT_PORT), *ep;
393396
struct hostent *he;
@@ -426,15 +429,18 @@ static int git_tcp_connect_sock(char *host)
426429

427430
for (ap = he->h_addr_list; *ap; ap++) {
428431
sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
429-
if (sockfd < 0)
432+
if (sockfd < 0) {
433+
saved_errno = errno;
430434
continue;
435+
}
431436

432437
memset(&sa, 0, sizeof sa);
433438
sa.sin_family = he->h_addrtype;
434439
sa.sin_port = htons(nport);
435440
memcpy(&sa.sin_addr, *ap, he->h_length);
436441

437442
if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
443+
saved_errno = errno;
438444
close(sockfd);
439445
sockfd = -1;
440446
continue;
@@ -443,7 +449,7 @@ static int git_tcp_connect_sock(char *host)
443449
}
444450

445451
if (sockfd < 0)
446-
die("unable to connect a socket (%s)", strerror(errno));
452+
die("unable to connect a socket (%s)", strerror(saved_errno));
447453

448454
return sockfd;
449455
}

contrib/git-svn/git-svn.perl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,19 @@ sub rebuild {
264264
}
265265

266266
sub init {
267-
$SVN_URL = shift or die "SVN repository location required " .
267+
my $url = shift or die "SVN repository location required " .
268268
"as a command-line argument\n";
269-
$SVN_URL =~ s!/+$!!; # strip trailing slash
269+
$url =~ s!/+$!!; # strip trailing slash
270+
271+
if (my $repo_path = shift) {
272+
unless (-d $repo_path) {
273+
mkpath([$repo_path]);
274+
}
275+
$GIT_DIR = $ENV{GIT_DIR} = $repo_path . "/.git";
276+
init_vars();
277+
}
278+
279+
$SVN_URL = $url;
270280
unless (-d $GIT_DIR) {
271281
my @init_db = ('git-init-db');
272282
push @init_db, "--template=$_template" if defined $_template;

fsck-objects.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ static int objwarning(struct object *obj, const char *err, ...)
6060

6161
static void check_connectivity(void)
6262
{
63-
int i;
63+
int i, max;
6464

6565
/* Look up all the requirements, warn about missing objects.. */
66-
for (i = 0; i < obj_allocs; i++) {
66+
max = get_max_object_index();
67+
for (i = 0; i < max; i++) {
6768
const struct object_refs *refs;
68-
struct object *obj = objs[i];
69+
struct object *obj = get_indexed_object(i);
6970

7071
if (!obj)
7172
continue;

git-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ THIS_INDEX="$GIT_DIR/index"
2929
NEXT_INDEX="$GIT_DIR/next-index$$"
3030
rm -f "$NEXT_INDEX"
3131
save_index () {
32-
cp "$THIS_INDEX" "$NEXT_INDEX"
32+
cp -p "$THIS_INDEX" "$NEXT_INDEX"
3333
}
3434

3535
report () {

git-svnimport.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ sub commit {
534534
my($author_name,$author_email,$dest);
535535
my(@old,@new,@parents);
536536

537-
if (not defined $author) {
537+
if (not defined $author or $author eq "") {
538538
$author_name = $author_email = "unknown";
539539
} elsif (defined $users_file) {
540540
die "User $author is not listed in $users_file\n"

name-rev.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,15 @@ int main(int argc, char **argv)
234234
fwrite(p_start, p - p_start, 1, stdout);
235235
}
236236
} else if (all) {
237-
int i;
237+
int i, max;
238238

239-
for (i = 0; i < obj_allocs; i++)
240-
if (objs[i])
241-
printf("%s %s\n", sha1_to_hex(objs[i]->sha1),
242-
get_rev_name(objs[i]));
239+
max = get_max_object_index();
240+
for (i = 0; i < max; i++) {
241+
struct object * obj = get_indexed_object(i);
242+
if (!obj)
243+
continue;
244+
printf("%s %s\n", sha1_to_hex(obj->sha1), get_rev_name(obj));
245+
}
243246
} else {
244247
int i;
245248
for (i = 0; i < revs.nr; i++)

object.c

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,97 @@
55
#include "commit.h"
66
#include "tag.h"
77

8-
struct object **objs;
9-
static int nr_objs;
10-
int obj_allocs;
8+
static struct object **obj_hash;
9+
static int nr_objs, obj_hash_size;
10+
11+
unsigned int get_max_object_index(void)
12+
{
13+
return obj_hash_size;
14+
}
15+
16+
struct object *get_indexed_object(unsigned int idx)
17+
{
18+
return obj_hash[idx];
19+
}
1120

1221
const char *type_names[] = {
1322
"none", "blob", "tree", "commit", "bad"
1423
};
1524

25+
static unsigned int hash_obj(struct object *obj, unsigned int n)
26+
{
27+
unsigned int hash = *(unsigned int *)obj->sha1;
28+
return hash % n;
29+
}
30+
31+
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
32+
{
33+
int j = hash_obj(obj, size);
34+
35+
while (hash[j]) {
36+
j++;
37+
if (j >= size)
38+
j = 0;
39+
}
40+
hash[j] = obj;
41+
}
42+
1643
static int hashtable_index(const unsigned char *sha1)
1744
{
1845
unsigned int i;
1946
memcpy(&i, sha1, sizeof(unsigned int));
20-
return (int)(i % obj_allocs);
47+
return (int)(i % obj_hash_size);
2148
}
2249

23-
static int find_object(const unsigned char *sha1)
50+
struct object *lookup_object(const unsigned char *sha1)
2451
{
2552
int i;
53+
struct object *obj;
2654

27-
if (!objs)
28-
return -1;
55+
if (!obj_hash)
56+
return NULL;
2957

3058
i = hashtable_index(sha1);
31-
while (objs[i]) {
32-
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
33-
return i;
59+
while ((obj = obj_hash[i]) != NULL) {
60+
if (!memcmp(sha1, obj->sha1, 20))
61+
break;
3462
i++;
35-
if (i == obj_allocs)
63+
if (i == obj_hash_size)
3664
i = 0;
3765
}
38-
return -1 - i;
66+
return obj;
3967
}
4068

41-
struct object *lookup_object(const unsigned char *sha1)
69+
static void grow_object_hash(void)
4270
{
43-
int pos = find_object(sha1);
44-
if (pos >= 0)
45-
return objs[pos];
46-
return NULL;
71+
int i;
72+
int new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size;
73+
struct object **new_hash;
74+
75+
new_hash = calloc(new_hash_size, sizeof(struct object *));
76+
for (i = 0; i < obj_hash_size; i++) {
77+
struct object *obj = obj_hash[i];
78+
if (!obj)
79+
continue;
80+
insert_obj_hash(obj, new_hash, new_hash_size);
81+
}
82+
free(obj_hash);
83+
obj_hash = new_hash;
84+
obj_hash_size = new_hash_size;
4785
}
4886

4987
void created_object(const unsigned char *sha1, struct object *obj)
5088
{
51-
int pos;
52-
5389
obj->parsed = 0;
54-
memcpy(obj->sha1, sha1, 20);
55-
obj->type = TYPE_NONE;
5690
obj->used = 0;
91+
obj->type = TYPE_NONE;
92+
obj->flags = 0;
93+
memcpy(obj->sha1, sha1, 20);
5794

58-
if (obj_allocs - 1 <= nr_objs * 2) {
59-
int i, count = obj_allocs;
60-
obj_allocs = (obj_allocs < 32 ? 32 : 2 * obj_allocs);
61-
objs = xrealloc(objs, obj_allocs * sizeof(struct object *));
62-
memset(objs + count, 0, (obj_allocs - count)
63-
* sizeof(struct object *));
64-
for (i = 0; i < obj_allocs; i++)
65-
if (objs[i]) {
66-
int j = find_object(objs[i]->sha1);
67-
if (j != i) {
68-
j = -1 - j;
69-
objs[j] = objs[i];
70-
objs[i] = NULL;
71-
}
72-
}
73-
}
74-
75-
pos = find_object(sha1);
76-
if (pos >= 0)
77-
die("Inserting %s twice\n", sha1_to_hex(sha1));
78-
pos = -pos-1;
95+
if (obj_hash_size - 1 <= nr_objs * 2)
96+
grow_object_hash();
7997

80-
objs[pos] = obj;
98+
insert_obj_hash(obj, obj_hash, obj_hash_size);
8199
nr_objs++;
82100
}
83101

@@ -222,7 +240,7 @@ void clear_object_marks(unsigned mark)
222240
{
223241
int i;
224242

225-
for (i = 0; i < obj_allocs; i++)
226-
if (objs[i])
227-
objs[i]->flags &= ~mark;
243+
for (i = 0; i < obj_hash_size; i++)
244+
if (obj_hash[i])
245+
obj_hash[i]->flags &= ~mark;
228246
}

object.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ struct object {
4040
};
4141

4242
extern int track_object_refs;
43-
extern int obj_allocs;
44-
extern struct object **objs;
4543
extern const char *type_names[];
4644

45+
extern unsigned int get_max_object_index(void);
46+
extern struct object *get_indexed_object(unsigned int);
47+
4748
static inline const char *typename(unsigned int type)
4849
{
4950
return type_names[type > TYPE_TAG ? TYPE_BAD : type];

0 commit comments

Comments
 (0)