Merge branch 'fixes'

This commit is contained in:
Junio C Hamano 2005-09-22 21:52:34 -07:00
commit d6179f56f8
5 changed files with 53 additions and 41 deletions

View File

@ -44,14 +44,16 @@ man: man1 man7
man1: $(DOC_MAN1)
man7: $(DOC_MAN7)
install:
install: man
$(INSTALL) -d -m755 $(DESTDIR)/$(man1) $(DESTDIR)/$(man7)
$(INSTALL) $(DOC_MAN1) $(DESTDIR)/$(man1)
$(INSTALL) $(DOC_MAN7) $(DESTDIR)/$(man7)
# 'include' dependencies
git-diff-%.txt: diff-format.txt diff-options.txt
touch $@
$(patsubst %.txt,%.1,$(wildcard git-diff-*.txt)): \
diff-format.txt diff-options.txt
$(patsubst %,%.1,git-fetch git-pull git-push): pull-fetch-param.txt
git.7: ../README
clean:
rm -f *.xml *.html *.1 *.7 howto-index.txt howto/*.html

49
fetch.c
View File

@ -33,7 +33,7 @@ static void report_missing(const char *what, const unsigned char *missing)
what, missing_hex, sha1_to_hex(current_commit_sha1));
}
static int process(unsigned char *sha1, const char *type);
static int process(struct object *obj);
static int process_tree(struct tree *tree)
{
@ -46,8 +46,7 @@ static int process_tree(struct tree *tree)
tree->entries = NULL;
while (entry) {
struct tree_entry_list *next = entry->next;
if (process(entry->item.any->sha1,
entry->directory ? tree_type : blob_type))
if (process(entry->item.any))
return -1;
free(entry);
entry = next;
@ -55,10 +54,9 @@ static int process_tree(struct tree *tree)
return 0;
}
#define COMPLETE 1U
#define TO_FETCH 2U
#define TO_SCAN 4U
#define SCANNED 8U
#define COMPLETE (1U << 0)
#define SEEN (1U << 1)
#define TO_SCAN (1U << 2)
static struct commit_list *complete = NULL;
@ -79,7 +77,7 @@ static int process_commit(struct commit *commit)
pull_say("walk %s\n", sha1_to_hex(commit->object.sha1));
if (get_tree) {
if (process(commit->tree->object.sha1, tree_type))
if (process(&commit->tree->object))
return -1;
if (!get_all)
get_tree = 0;
@ -87,7 +85,7 @@ static int process_commit(struct commit *commit)
if (get_history) {
struct commit_list *parents = commit->parents;
for (; parents; parents = parents->next) {
if (process(parents->item->object.sha1, commit_type))
if (process(&parents->item->object))
return -1;
}
}
@ -98,7 +96,7 @@ static int process_tag(struct tag *tag)
{
if (parse_tag(tag))
return -1;
return process(tag->tagged->sha1, NULL);
return process(tag->tagged);
}
static struct object_list *process_queue = NULL;
@ -106,10 +104,6 @@ static struct object_list **process_queue_end = &process_queue;
static int process_object(struct object *obj)
{
if (obj->flags & SCANNED)
return 0;
obj->flags |= SCANNED;
if (obj->type == commit_type) {
if (process_commit((struct commit *)obj))
return -1;
@ -133,28 +127,23 @@ static int process_object(struct object *obj)
obj->type, sha1_to_hex(obj->sha1));
}
static int process(unsigned char *sha1, const char *type)
static int process(struct object *obj)
{
struct object *obj = lookup_object_type(sha1, type);
if (obj->flags & SEEN)
return 0;
obj->flags |= SEEN;
if (has_sha1_file(sha1)) {
parse_object(sha1);
if (has_sha1_file(obj->sha1)) {
/* We already have it, so we should scan it now. */
if (obj->flags & (SCANNED | TO_SCAN))
return 0;
object_list_insert(obj, process_queue_end);
process_queue_end = &(*process_queue_end)->next;
obj->flags |= TO_SCAN;
return 0;
} else {
if (obj->flags & COMPLETE)
return 0;
prefetch(obj->sha1);
}
if (obj->flags & (COMPLETE | TO_FETCH))
return 0;
object_list_insert(obj, process_queue_end);
process_queue_end = &(*process_queue_end)->next;
obj->flags |= TO_FETCH;
prefetch(sha1);
return 0;
}
@ -228,7 +217,7 @@ int pull(char *target)
if (interpret_target(target, sha1))
return error("Could not interpret %s as something to pull",
target);
if (process(sha1, NULL))
if (process(lookup_unknown_object(sha1)))
return -1;
if (loop())
return -1;

View File

@ -152,7 +152,8 @@ yes,yes)
# Look at objects/info/alternates for rsync -- http will
# support it natively and git native ones will do it on the
# remote end. Not having that file is not a crime.
rsync -q "$repo/objects/info/alternates" "$D/.git/TMP_ALT" ||
rsync -q "$repo/objects/info/alternates" \
"$D/.git/TMP_ALT" 2>/dev/null ||
rm -f "$D/.git/TMP_ALT"
if test -f "$D/.git/TMP_ALT"
then

View File

@ -193,8 +193,9 @@ do
# Look at objects/info/alternates for rsync -- http will
# support it natively and git native ones will do it on the remote
# end. Not having that file is not a crime.
rsync -q "$remote/objects/info/alternates" "$GIT_DIR/TMP_ALT" ||
rm -f "$GIT_DIR/TMP_ALT"
rsync -q "$remote/objects/info/alternates" \
"$GIT_DIR/TMP_ALT" 2>/dev/null ||
rm -f "$GIT_DIR/TMP_ALT"
if test -f "$GIT_DIR/TMP_ALT"
then
resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |

View File

@ -350,13 +350,18 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
char *hex = sha1_to_hex(sha1);
char *filename = sha1_file_name(sha1);
unsigned char real_sha1[20];
char tmpfile[PATH_MAX];
int ret;
char *url;
char *posn;
local = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX",
get_object_directory());
local = mkstemp(tmpfile);
if (local < 0)
return error("Couldn't open local object %s\n", filename);
return error("Couldn't create temporary file %s for %s: %s\n",
tmpfile, filename, strerror(errno));
memset(&stream, 0, sizeof(stream));
@ -386,18 +391,32 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
return -1;
}
fchmod(local, 0444);
close(local);
inflateEnd(&stream);
SHA1_Final(real_sha1, &c);
if (zret != Z_STREAM_END) {
unlink(filename);
unlink(tmpfile);
return error("File %s (%s) corrupt\n", hex, url);
}
if (memcmp(sha1, real_sha1, 20)) {
unlink(filename);
unlink(tmpfile);
return error("File %s has bad hash\n", hex);
}
ret = link(tmpfile, filename);
if (ret < 0) {
/* Same Coda hack as in write_sha1_file(sha1_file.c) */
ret = errno;
if (ret == EXDEV && !rename(tmpfile, filename))
goto out;
}
unlink(tmpfile);
if (ret) {
if (ret != EEXIST)
return error("unable to write sha1 filename %s: %s",
filename, strerror(ret));
}
out:
pull_say("got %s\n", hex);
return 0;
}