Browse Source

[PATCH] Handle deltified object correctly in git-*-pull family.

When a remote repository is deltified, we need to get the
objects that a deltified object we want to obtain is based upon.
The initial parts of each retrieved SHA1 file is inflated and
inspected to see if it is deltified, and its base object is
asked from the remote side when it is.  Since this partial
inflation and inspection has a small performance hit, it can
optionally be skipped by giving -d flag to git-*-pull commands.
This flag should be used only when the remote repository is
known to have no deltified objects.

Rsync transport does not have this problem since it fetches
everything the remote side has.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
maint
Junio C Hamano 20 years ago committed by Linus Torvalds
parent
commit
4a62b61939
  1. 6
      Documentation/git-http-pull.txt
  2. 6
      Documentation/git-local-pull.txt
  3. 6
      Documentation/git-rpull.txt
  4. 1
      cache.h
  5. 4
      http-pull.c
  6. 4
      local-pull.c
  7. 7
      pull.c
  8. 3
      pull.h
  9. 4
      rpull.c
  10. 31
      sha1_file.c

6
Documentation/git-http-pull.txt

@ -9,7 +9,7 @@ git-http-pull - Downloads a remote GIT repository via HTTP


SYNOPSIS SYNOPSIS
-------- --------
'git-http-pull' [-c] [-t] [-a] [-v] commit-id url 'git-http-pull' [-c] [-t] [-a] [-v] [-d] commit-id url


DESCRIPTION DESCRIPTION
----------- -----------
@ -21,6 +21,10 @@ Downloads a remote GIT repository via HTTP.
Get trees associated with the commit objects. Get trees associated with the commit objects.
-a:: -a::
Get all the objects. Get all the objects.
-d::
Do not check for delta base objects (use this option
only when you know the remote repository is not
deltified).
-v:: -v::
Report what is downloaded. Report what is downloaded.



6
Documentation/git-local-pull.txt

@ -9,7 +9,7 @@ git-local-pull - Duplicates another GIT repository on a local system


SYNOPSIS SYNOPSIS
-------- --------
'git-local-pull' [-c] [-t] [-a] [-l] [-s] [-n] [-v] commit-id path 'git-local-pull' [-c] [-t] [-a] [-l] [-s] [-n] [-v] [-d] commit-id path


DESCRIPTION DESCRIPTION
----------- -----------
@ -23,6 +23,10 @@ OPTIONS
Get trees associated with the commit objects. Get trees associated with the commit objects.
-a:: -a::
Get all the objects. Get all the objects.
-d::
Do not check for delta base objects (use this option
only when you know the remote repository is not
deltified).
-v:: -v::
Report what is downloaded. Report what is downloaded.



6
Documentation/git-rpull.txt

@ -10,7 +10,7 @@ git-rpull - Pulls from a remote repository over ssh connection


SYNOPSIS SYNOPSIS
-------- --------
'git-rpull' [-c] [-t] [-a] [-v] commit-id url 'git-rpull' [-c] [-t] [-a] [-d] [-v] commit-id url


DESCRIPTION DESCRIPTION
----------- -----------
@ -25,6 +25,10 @@ OPTIONS
Get trees associated with the commit objects. Get trees associated with the commit objects.
-a:: -a::
Get all the objects. Get all the objects.
-d::
Do not check for delta base objects (use this option
only when you know the remote repository is not
deltified).
-v:: -v::
Report what is downloaded. Report what is downloaded.



1
cache.h

@ -153,6 +153,7 @@ extern char *sha1_file_name(const unsigned char *sha1);
extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size); extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);
extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size); extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);
extern int parse_sha1_header(char *hdr, char *type, unsigned long *sizep); extern int parse_sha1_header(char *hdr, char *type, unsigned long *sizep);
extern int sha1_delta_base(const unsigned char *, unsigned char *);
extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size); extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size);
extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);

4
http-pull.c

@ -103,6 +103,8 @@ int main(int argc, char **argv)
get_tree = 1; get_tree = 1;
} else if (argv[arg][1] == 'c') { } else if (argv[arg][1] == 'c') {
get_history = 1; get_history = 1;
} else if (argv[arg][1] == 'd') {
get_delta = 0;
} else if (argv[arg][1] == 'a') { } else if (argv[arg][1] == 'a') {
get_all = 1; get_all = 1;
get_tree = 1; get_tree = 1;
@ -113,7 +115,7 @@ int main(int argc, char **argv)
arg++; arg++;
} }
if (argc < arg + 2) { if (argc < arg + 2) {
usage("git-http-pull [-c] [-t] [-a] [-v] commit-id url"); usage("git-http-pull [-c] [-t] [-a] [-d] [-v] commit-id url");
return 1; return 1;
} }
commit_id = argv[arg]; commit_id = argv[arg];

4
local-pull.c

@ -74,7 +74,7 @@ int fetch(unsigned char *sha1)
} }


static const char *local_pull_usage = static const char *local_pull_usage =
"git-local-pull [-c] [-t] [-a] [-l] [-s] [-n] [-v] commit-id path"; "git-local-pull [-c] [-t] [-a] [-l] [-s] [-n] [-v] [-d] commit-id path";


/* /*
* By default we only use file copy. * By default we only use file copy.
@ -92,6 +92,8 @@ int main(int argc, char **argv)
get_tree = 1; get_tree = 1;
else if (argv[arg][1] == 'c') else if (argv[arg][1] == 'c')
get_history = 1; get_history = 1;
else if (argv[arg][1] == 'd')
get_delta = 0;
else if (argv[arg][1] == 'a') { else if (argv[arg][1] == 'a') {
get_all = 1; get_all = 1;
get_tree = 1; get_tree = 1;

7
pull.c

@ -6,6 +6,7 @@


int get_tree = 0; int get_tree = 0;
int get_history = 0; int get_history = 0;
int get_delta = 1;
int get_all = 0; int get_all = 0;
int get_verbosely = 0; int get_verbosely = 0;
static unsigned char current_commit_sha1[20]; static unsigned char current_commit_sha1[20];
@ -37,6 +38,12 @@ static int make_sure_we_have_it(const char *what, unsigned char *sha1)
status = fetch(sha1); status = fetch(sha1);
if (status && what) if (status && what)
report_missing(what, sha1); report_missing(what, sha1);
if (get_delta) {
char delta_sha1[20];
status = sha1_delta_base(sha1, delta_sha1);
if (0 < status)
status = make_sure_we_have_it(what, delta_sha1);
}
return status; return status;
} }



3
pull.h

@ -13,6 +13,9 @@ extern int get_history;
/** Set to fetch the trees in the commit history. **/ /** Set to fetch the trees in the commit history. **/
extern int get_all; extern int get_all;


/* Set to zero to skip the check for delta object base. */
extern int get_delta;

/* Set to be verbose */ /* Set to be verbose */
extern int get_verbosely; extern int get_verbosely;



4
rpull.c

@ -27,6 +27,8 @@ int main(int argc, char **argv)
get_tree = 1; get_tree = 1;
} else if (argv[arg][1] == 'c') { } else if (argv[arg][1] == 'c') {
get_history = 1; get_history = 1;
} else if (argv[arg][1] == 'd') {
get_delta = 0;
} else if (argv[arg][1] == 'a') { } else if (argv[arg][1] == 'a') {
get_all = 1; get_all = 1;
get_tree = 1; get_tree = 1;
@ -37,7 +39,7 @@ int main(int argc, char **argv)
arg++; arg++;
} }
if (argc < arg + 2) { if (argc < arg + 2) {
usage("git-rpull [-c] [-t] [-a] [-v] commit-id url"); usage("git-rpull [-c] [-t] [-a] [-v] [-d] commit-id url");
return 1; return 1;
} }
commit_id = argv[arg]; commit_id = argv[arg];

31
sha1_file.c

@ -401,6 +401,37 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l
return unpack_sha1_rest(&stream, hdr, *size); return unpack_sha1_rest(&stream, hdr, *size);
} }


int sha1_delta_base(const unsigned char *sha1, unsigned char *base_sha1)
{
int ret;
unsigned long mapsize, size;
void *map;
z_stream stream;
char hdr[64], type[20];
void *delta_data_head;

map = map_sha1_file(sha1, &mapsize);
if (!map)
return -1;
ret = unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr));
if (ret < Z_OK || parse_sha1_header(hdr, type, &size) < 0) {
ret = -1;
goto out;
}
if (strcmp(type, "delta")) {
ret = 0;
goto out;
}

delta_data_head = hdr + strlen(hdr) + 1;
ret = 1;
memcpy(base_sha1, delta_data_head, 20);
out:
inflateEnd(&stream);
munmap(map, mapsize);
return ret;
}

void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size) void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
{ {
unsigned long mapsize; unsigned long mapsize;

Loading…
Cancel
Save