Skip to content

Commit

Permalink
Merge branch 'master' into js/merge-base
Browse files Browse the repository at this point in the history
This is to pull in the object-hash clean-up from the master branch.
  • Loading branch information
Junio C Hamano committed Jul 3, 2006
2 parents 160b798 + 8fced61 commit f23c75a
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 95 deletions.
6 changes: 3 additions & 3 deletions Documentation/git-commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ SYNOPSIS
DESCRIPTION
-----------
Updates the index file for given paths, or all modified files if
'-a' is specified, and makes a commit object. The command
VISUAL and EDITOR environment variables to edit the commit log
message.
'-a' is specified, and makes a commit object. The command specified
by either the VISUAL or EDITOR environment variables are used to edit
the commit log message.

Several environment variable are used during commits. They are
documented in gitlink:git-commit-tree[1].
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ git-ssh-push$X: rsh.o
git-imap-send$X: imap-send.o $(LIB_FILE)

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

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

Expand Down
18 changes: 12 additions & 6 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static enum protocol get_protocol(const char *name)
*/
static int git_tcp_connect_sock(char *host)
{
int sockfd = -1;
int sockfd = -1, saved_errno = 0;
char *colon, *end;
const char *port = STR(DEFAULT_GIT_PORT);
struct addrinfo hints, *ai0, *ai;
Expand Down Expand Up @@ -362,9 +362,12 @@ static int git_tcp_connect_sock(char *host)
for (ai0 = ai; ai; ai = ai->ai_next) {
sockfd = socket(ai->ai_family,
ai->ai_socktype, ai->ai_protocol);
if (sockfd < 0)
if (sockfd < 0) {
saved_errno = errno;
continue;
}
if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
saved_errno = errno;
close(sockfd);
sockfd = -1;
continue;
Expand All @@ -375,7 +378,7 @@ static int git_tcp_connect_sock(char *host)
freeaddrinfo(ai0);

if (sockfd < 0)
die("unable to connect a socket (%s)", strerror(errno));
die("unable to connect a socket (%s)", strerror(saved_errno));

return sockfd;
}
Expand All @@ -387,7 +390,7 @@ static int git_tcp_connect_sock(char *host)
*/
static int git_tcp_connect_sock(char *host)
{
int sockfd = -1;
int sockfd = -1, saved_errno = 0;
char *colon, *end;
char *port = STR(DEFAULT_GIT_PORT), *ep;
struct hostent *he;
Expand Down Expand Up @@ -426,15 +429,18 @@ static int git_tcp_connect_sock(char *host)

for (ap = he->h_addr_list; *ap; ap++) {
sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
if (sockfd < 0)
if (sockfd < 0) {
saved_errno = errno;
continue;
}

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

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

if (sockfd < 0)
die("unable to connect a socket (%s)", strerror(errno));
die("unable to connect a socket (%s)", strerror(saved_errno));

return sockfd;
}
Expand Down
14 changes: 12 additions & 2 deletions contrib/git-svn/git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,19 @@ sub rebuild {
}

sub init {
$SVN_URL = shift or die "SVN repository location required " .
my $url = shift or die "SVN repository location required " .
"as a command-line argument\n";
$SVN_URL =~ s!/+$!!; # strip trailing slash
$url =~ s!/+$!!; # strip trailing slash

if (my $repo_path = shift) {
unless (-d $repo_path) {
mkpath([$repo_path]);
}
$GIT_DIR = $ENV{GIT_DIR} = $repo_path . "/.git";
init_vars();
}

$SVN_URL = $url;
unless (-d $GIT_DIR) {
my @init_db = ('git-init-db');
push @init_db, "--template=$_template" if defined $_template;
Expand Down
7 changes: 4 additions & 3 deletions fsck-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ static int objwarning(struct object *obj, const char *err, ...)

static void check_connectivity(void)
{
int i;
int i, max;

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

if (!obj)
continue;
Expand Down
2 changes: 1 addition & 1 deletion git-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ THIS_INDEX="$GIT_DIR/index"
NEXT_INDEX="$GIT_DIR/next-index$$"
rm -f "$NEXT_INDEX"
save_index () {
cp "$THIS_INDEX" "$NEXT_INDEX"
cp -p "$THIS_INDEX" "$NEXT_INDEX"
}

report () {
Expand Down
2 changes: 1 addition & 1 deletion git-svnimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ sub commit {
my($author_name,$author_email,$dest);
my(@old,@new,@parents);

if (not defined $author) {
if (not defined $author or $author eq "") {
$author_name = $author_email = "unknown";
} elsif (defined $users_file) {
die "User $author is not listed in $users_file\n"
Expand Down
13 changes: 8 additions & 5 deletions name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,15 @@ int main(int argc, char **argv)
fwrite(p_start, p - p_start, 1, stdout);
}
} else if (all) {
int i;
int i, max;

for (i = 0; i < obj_allocs; i++)
if (objs[i])
printf("%s %s\n", sha1_to_hex(objs[i]->sha1),
get_rev_name(objs[i]));
max = get_max_object_index();
for (i = 0; i < max; i++) {
struct object * obj = get_indexed_object(i);
if (!obj)
continue;
printf("%s %s\n", sha1_to_hex(obj->sha1), get_rev_name(obj));
}
} else {
int i;
for (i = 0; i < revs.nr; i++)
Expand Down
110 changes: 64 additions & 46 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,97 @@
#include "commit.h"
#include "tag.h"

struct object **objs;
static int nr_objs;
int obj_allocs;
static struct object **obj_hash;
static int nr_objs, obj_hash_size;

unsigned int get_max_object_index(void)
{
return obj_hash_size;
}

struct object *get_indexed_object(unsigned int idx)
{
return obj_hash[idx];
}

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

static unsigned int hash_obj(struct object *obj, unsigned int n)
{
unsigned int hash = *(unsigned int *)obj->sha1;
return hash % n;
}

static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
{
int j = hash_obj(obj, size);

while (hash[j]) {
j++;
if (j >= size)
j = 0;
}
hash[j] = obj;
}

static int hashtable_index(const unsigned char *sha1)
{
unsigned int i;
memcpy(&i, sha1, sizeof(unsigned int));
return (int)(i % obj_allocs);
return (int)(i % obj_hash_size);
}

static int find_object(const unsigned char *sha1)
struct object *lookup_object(const unsigned char *sha1)
{
int i;
struct object *obj;

if (!objs)
return -1;
if (!obj_hash)
return NULL;

i = hashtable_index(sha1);
while (objs[i]) {
if (memcmp(sha1, objs[i]->sha1, 20) == 0)
return i;
while ((obj = obj_hash[i]) != NULL) {
if (!memcmp(sha1, obj->sha1, 20))
break;
i++;
if (i == obj_allocs)
if (i == obj_hash_size)
i = 0;
}
return -1 - i;
return obj;
}

struct object *lookup_object(const unsigned char *sha1)
static void grow_object_hash(void)
{
int pos = find_object(sha1);
if (pos >= 0)
return objs[pos];
return NULL;
int i;
int new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size;
struct object **new_hash;

new_hash = calloc(new_hash_size, sizeof(struct object *));
for (i = 0; i < obj_hash_size; i++) {
struct object *obj = obj_hash[i];
if (!obj)
continue;
insert_obj_hash(obj, new_hash, new_hash_size);
}
free(obj_hash);
obj_hash = new_hash;
obj_hash_size = new_hash_size;
}

void created_object(const unsigned char *sha1, struct object *obj)
{
int pos;

obj->parsed = 0;
memcpy(obj->sha1, sha1, 20);
obj->type = TYPE_NONE;
obj->used = 0;
obj->type = TYPE_NONE;
obj->flags = 0;
memcpy(obj->sha1, sha1, 20);

if (obj_allocs - 1 <= nr_objs * 2) {
int i, count = obj_allocs;
obj_allocs = (obj_allocs < 32 ? 32 : 2 * obj_allocs);
objs = xrealloc(objs, obj_allocs * sizeof(struct object *));
memset(objs + count, 0, (obj_allocs - count)
* sizeof(struct object *));
for (i = 0; i < obj_allocs; i++)
if (objs[i]) {
int j = find_object(objs[i]->sha1);
if (j != i) {
j = -1 - j;
objs[j] = objs[i];
objs[i] = NULL;
}
}
}

pos = find_object(sha1);
if (pos >= 0)
die("Inserting %s twice\n", sha1_to_hex(sha1));
pos = -pos-1;
if (obj_hash_size - 1 <= nr_objs * 2)
grow_object_hash();

objs[pos] = obj;
insert_obj_hash(obj, obj_hash, obj_hash_size);
nr_objs++;
}

Expand Down Expand Up @@ -222,7 +240,7 @@ void clear_object_marks(unsigned mark)
{
int i;

for (i = 0; i < obj_allocs; i++)
if (objs[i])
objs[i]->flags &= ~mark;
for (i = 0; i < obj_hash_size; i++)
if (obj_hash[i])
obj_hash[i]->flags &= ~mark;
}
5 changes: 3 additions & 2 deletions object.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ struct object {
};

extern int track_object_refs;
extern int obj_allocs;
extern struct object **objs;
extern const char *type_names[];

extern unsigned int get_max_object_index(void);
extern struct object *get_indexed_object(unsigned int);

static inline const char *typename(unsigned int type)
{
return type_names[type > TYPE_TAG ? TYPE_BAD : type];
Expand Down
Loading

0 comments on commit f23c75a

Please sign in to comment.