From 5edbcd8d778d81254d2c8a4229c76c6fa7880407 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 4 May 2006 23:18:14 +0200 Subject: [PATCH 01/15] builtin-push: --all and --tags _are_ explicit refspecs ... so do not get refspecs from remotes/* or the config if one of them was specified. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index 06d06ff310..e530022824 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -72,7 +72,7 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) { int n = 0; FILE *f = fopen(git_path("remotes/%s", repo), "r"); - int has_explicit_refspec = refspec_nr; + int has_explicit_refspec = refspec_nr || all || tags; if (!f) return -1; @@ -144,7 +144,7 @@ static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI]) config_repo = repo; config_current_uri = 0; config_uri = uri; - config_get_refspecs = !refspec_nr; + config_get_refspecs = !(refspec_nr || all || tags); git_config(get_remote_config); return config_current_uri; From fb335158d5a93349e16bc0985e75e93bb9fcd5eb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 May 2006 17:38:41 -0700 Subject: [PATCH 02/15] Makefile: do not link rev-list any specially. We used to depend on bignum from openssl for rev-list to compute merge-order, but there is no reason to use different build recipe from other programs anymore. Just build it with git-%$X rule like everybody else. Noticed by Alexey Dobriyan. Signed-off-by: Junio C Hamano --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index a3f7e92d01..45484fcd82 100644 --- a/Makefile +++ b/Makefile @@ -564,10 +564,6 @@ git-http-push$X: revision.o http.o http-push.o $(LIB_FILE) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) -git-rev-list$X: rev-list.o $(LIB_FILE) - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ - $(LIBS) $(OPENSSL_LIBSSL) - init-db.o: init-db.c $(CC) -c $(ALL_CFLAGS) \ -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $*.c From ac4c758adcf52b913b82d481626b0f8648e95475 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 02:35:58 -0700 Subject: [PATCH 03/15] delta: stricter constness Signed-off-by: Junio C Hamano --- delta.h | 6 +++--- diff-delta.c | 4 ++-- patch-delta.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/delta.h b/delta.h index 9464f3e9b0..09b2e1eed5 100644 --- a/delta.h +++ b/delta.h @@ -2,11 +2,11 @@ #define DELTA_H /* handling of delta buffers */ -extern void *diff_delta(void *from_buf, unsigned long from_size, - void *to_buf, unsigned long to_size, +extern void *diff_delta(const void *from_buf, unsigned long from_size, + const void *to_buf, unsigned long to_size, unsigned long *delta_size, unsigned long max_size); extern void *patch_delta(void *src_buf, unsigned long src_size, - void *delta_buf, unsigned long delta_size, + const void *delta_buf, unsigned long delta_size, unsigned long *dst_size); /* the smallest possible delta size is 4 bytes */ diff --git a/diff-delta.c b/diff-delta.c index 1188b31cd0..5bc22047f8 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -131,8 +131,8 @@ static struct index ** delta_index(const unsigned char *buf, /* the maximum size for any opcode */ #define MAX_OP_SIZE COPYOP_SIZE(0xffffffff, 0xffffffff) -void *diff_delta(void *from_buf, unsigned long from_size, - void *to_buf, unsigned long to_size, +void *diff_delta(const void *from_buf, unsigned long from_size, + const void *to_buf, unsigned long to_size, unsigned long *delta_size, unsigned long max_size) { diff --git a/patch-delta.c b/patch-delta.c index d95f0d9721..affd4f673d 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -14,7 +14,7 @@ #include "delta.h" void *patch_delta(void *src_buf, unsigned long src_size, - void *delta_buf, unsigned long delta_size, + const void *delta_buf, unsigned long delta_size, unsigned long *dst_size) { const unsigned char *data, *top; From 81c5a0e6e5135384a7316b9689a5b0baaf1a2752 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 May 2006 12:35:39 -0700 Subject: [PATCH 04/15] git-svn: documentation updates * Clarify that 'init' requires an argument * Remove instances of 'SVN_URL' in the manpage, it's not an environment variable. * Refer to 'Additional Fetch Arguments' when documenting 'fetch' * document --authors-file / -A option Thanks to Pavel Roskin and Seth Falcon for bringing these issues to my attention. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 6 +++-- contrib/git-svn/git-svn.txt | 45 +++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index 7c44450d72..e003501be6 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -42,7 +42,8 @@ my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext, my %cmd = ( fetch => [ \&fetch, "Download new revisions from SVN", { 'revision|r=s' => \$_revision, %fc_opts } ], - init => [ \&init, "Initialize and fetch (import)", { } ], + init => [ \&init, "Initialize a repo for tracking" . + " (requires URL argument)", { } ], commit => [ \&commit, "Commit git revisions to SVN", { 'stdin|' => \$_stdin, 'edit|e' => \$_edit, @@ -220,7 +221,8 @@ when you have upgraded your tools and habits to use refs/remotes/$GIT_SVN } sub init { - $SVN_URL = shift or croak "SVN repository location required\n"; + $SVN_URL = shift or die "SVN repository location required " . + "as a command-line argument\n"; unless (-d $GIT_DIR) { sys('git-init-db'); } diff --git a/contrib/git-svn/git-svn.txt b/contrib/git-svn/git-svn.txt index e18fcaf4fb..f7d3de48f0 100644 --- a/contrib/git-svn/git-svn.txt +++ b/contrib/git-svn/git-svn.txt @@ -36,17 +36,22 @@ COMMANDS -------- init:: Creates an empty git repository with additional metadata - directories for git-svn. The SVN_URL must be specified - at this point. + directories for git-svn. The Subversion URL must be specified + as a command-line argument. fetch:: - Fetch unfetched revisions from the SVN_URL we are tracking. - refs/heads/remotes/git-svn will be updated to the latest revision. + Fetch unfetched revisions from the Subversion URL we are + tracking. refs/remotes/git-svn will be updated to the + latest revision. - Note: You should never attempt to modify the remotes/git-svn branch - outside of git-svn. Instead, create a branch from remotes/git-svn - and work on that branch. Use the 'commit' command (see below) - to write git commits back to remotes/git-svn. + Note: You should never attempt to modify the remotes/git-svn + branch outside of git-svn. Instead, create a branch from + remotes/git-svn and work on that branch. Use the 'commit' + command (see below) to write git commits back to + remotes/git-svn. + + See 'Additional Fetch Arguments' if you are interested in + manually joining branches on commit. commit:: Commit specified commit or tree objects to SVN. This relies on @@ -62,9 +67,9 @@ rebuild:: tracked with git-svn. Unfortunately, git-clone does not clone git-svn metadata and the svn working tree that git-svn uses for its operations. This rebuilds the metadata so git-svn can - resume fetch operations. SVN_URL may be optionally specified if - the directory/repository you're tracking has moved or changed - protocols. + resume fetch operations. A Subversion URL may be optionally + specified at the command-line if the directory/repository you're + tracking has moved or changed protocols. show-ignore:: Recursively finds and lists the svn:ignore property on @@ -123,6 +128,24 @@ OPTIONS repo-config key: svn.l repo-config key: svn.findcopiesharder +-A:: +--authors-file=:: + + Syntax is compatible with the files used by git-svnimport and + git-cvsimport: + +------------------------------------------------------------------------ +loginname = Joe User +------------------------------------------------------------------------ + + If this option is specified and git-svn encounters an SVN + committer name that does not exist in the authors-file, git-svn + will abort operation. The user will then have to add the + appropriate entry. Re-running the previous git-svn command + after the authors-file is modified should continue operation. + + repo-config key: svn.authors-file + ADVANCED OPTIONS ---------------- -b:: From 88521450fc4cca1f96d9179ee4f2cbe51da3359c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 May 2006 12:35:40 -0700 Subject: [PATCH 05/15] git-svn 1.0.0 Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index e003501be6..de13a96b8a 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -8,7 +8,7 @@ use vars qw/ $AUTHOR $VERSION $GIT_SVN_INDEX $GIT_SVN $GIT_DIR $REV_DIR/; $AUTHOR = 'Eric Wong '; -$VERSION = '0.11.0'; +$VERSION = '1.0.0'; use Cwd qw/abs_path/; $GIT_DIR = abs_path($ENV{GIT_DIR} || '.git'); From 2b5f3ed3166ea7d93f4138bb2b6c849851ba86ac Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:10 -0400 Subject: [PATCH 06/15] Several trivial documentation touch ups. Move incorrect asciidoc level 2 titles back to level 1. Show output of git-name-rev in man page example. Reword sentences that begin with a period (.) in asciidoc numbered lists to work around conversion to man page bug. Mention that git-repack now calls git-prune-packed when the -d option is passed to it. [imap] section headers in the config file example need to be contained in a literal block. imap.pass is the proper config file variable to use, not imap.password. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-clone.txt | 2 +- Documentation/git-imap-send.txt | 4 +++- Documentation/git-name-rev.txt | 1 + Documentation/git-repack.txt | 1 + Documentation/git-repo-config.txt | 6 +++--- Documentation/git-reset.txt | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 131e445747..b333f51045 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -101,7 +101,7 @@ OPTIONS is not allowed. Examples -~~~~~~~~ +-------- Clone from upstream:: + diff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt index cfc0d88d02..eca9e9ccef 100644 --- a/Documentation/git-imap-send.txt +++ b/Documentation/git-imap-send.txt @@ -29,6 +29,7 @@ CONFIGURATION git-imap-send requires the following values in the repository configuration file (shown with examples): +.......................... [imap] Folder = "INBOX.Drafts" @@ -38,8 +39,9 @@ configuration file (shown with examples): [imap] Host = imap.server.com User = bob - Password = pwd + Pass = pwd Port = 143 +.......................... BUGS diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt index 68707083be..ffaa00468f 100644 --- a/Documentation/git-name-rev.txt +++ b/Documentation/git-name-rev.txt @@ -41,6 +41,7 @@ Enter git-name-rev: ------------ % git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a +33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99^0~940 ------------ Now you are wiser, because you know that it happened 940 revisions before v0.99. diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index d2f9a44382..951622774a 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -38,6 +38,7 @@ OPTIONS -d:: After packing, if the newly created packs make some existing packs redundant, remove the redundant packs. + Also runs gitlink:git-prune-packed[1]. -l:: Pass the `--local` option to `git pack-objects`, see diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt index ddcf52364c..fd44f629f5 100644 --- a/Documentation/git-repo-config.txt +++ b/Documentation/git-repo-config.txt @@ -34,10 +34,10 @@ convert the value to the canonical form (simple decimal number for int, a "true" or "false" string for bool). If no type specifier is passed, no checks or transformations are performed on the value. -This command will fail if +This command will fail if: -. .git/config is invalid, -. .git/config can not be written to, +. The .git/config file is invalid, +. Can not write to .git/config, . no section was provided, . the section or key is invalid, . you try to unset an option which does not exist, or diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index ebcfe5edb7..b27399dd41 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -43,7 +43,7 @@ OPTIONS Commit to make the current HEAD. Examples -~~~~~~~~ +-------- Undo a commit and redo:: + From e994004f93a481414b9065ac24edd0807d1c311e Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:24 -0400 Subject: [PATCH 07/15] Fix up docs where "--" isn't displayed correctly. A bare "--" doesn't show up in man or html pages correctly as two individual dashes unless backslashed as \-- in the asciidoc source. Note, no backslash is needed inside a literal block. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-add.txt | 2 +- Documentation/git-checkout-index.txt | 2 +- Documentation/git-commit.txt | 2 +- Documentation/git-log.txt | 2 +- Documentation/git-ls-files.txt | 2 +- Documentation/git-merge-index.txt | 4 ++-- Documentation/git-prune.txt | 2 +- Documentation/git-rm.txt | 2 +- Documentation/git-update-index.txt | 2 +- Documentation/git-verify-pack.txt | 2 +- Documentation/git-whatchanged.txt | 2 +- Documentation/gitk.txt | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index ae24547c8a..5e3112943d 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -26,7 +26,7 @@ OPTIONS -v:: Be verbose. ---:: +\--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options). diff --git a/Documentation/git-checkout-index.txt b/Documentation/git-checkout-index.txt index 09bd6a5535..765c173e15 100644 --- a/Documentation/git-checkout-index.txt +++ b/Documentation/git-checkout-index.txt @@ -63,7 +63,7 @@ OPTIONS Only meaningful with `--stdin`; paths are separated with NUL character instead of LF. ---:: +\--:: Do not interpret any more arguments as options. The order of the flags used to matter, but not anymore. diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 0a7365b9a8..38df59ce23 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -106,7 +106,7 @@ but can be used to amend a merge commit. index and the latest commit does not match on the specified paths to avoid confusion. ---:: +\--:: Do not interpret any more arguments as options. ...:: diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index af378ffcf9..c9ffff734c 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -51,7 +51,7 @@ git log v2.6.12.. include/scsi drivers/scsi:: Show all commits since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -git log --since="2 weeks ago" -- gitk:: +git log --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 796d049be6..a29c633c8d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -106,7 +106,7 @@ OPTIONS lines, show only handful hexdigits prefix. Non default number of digits can be specified with --abbrev=. ---:: +\--:: Do not interpret any more arguments as options. :: diff --git a/Documentation/git-merge-index.txt b/Documentation/git-merge-index.txt index fbc986aa84..332e023d0f 100644 --- a/Documentation/git-merge-index.txt +++ b/Documentation/git-merge-index.txt @@ -8,7 +8,7 @@ git-merge-index - Runs a merge for files needing merging SYNOPSIS -------- -'git-merge-index' [-o] [-q] (-a | -- | \*) +'git-merge-index' [-o] [-q] (-a | \-- | \*) DESCRIPTION ----------- @@ -19,7 +19,7 @@ files are passed as arguments 5, 6 and 7. OPTIONS ------- ---:: +\--:: Do not interpret any more arguments as options. -a:: diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt index f694fcbde8..a11e303094 100644 --- a/Documentation/git-prune.txt +++ b/Documentation/git-prune.txt @@ -28,7 +28,7 @@ OPTIONS Do not remove anything; just report what it would remove. ---:: +\--:: Do not interpret any more arguments as options. ...:: diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt index c9c3088424..66fc478f57 100644 --- a/Documentation/git-rm.txt +++ b/Documentation/git-rm.txt @@ -32,7 +32,7 @@ OPTIONS -v:: Be verbose. ---:: +\--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options). diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 23f2b6f1a5..57177c7fb6 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -113,7 +113,7 @@ OPTIONS Only meaningful with `--stdin`; paths are separated with NUL character instead of LF. ---:: +\--:: Do not interpret any more arguments as options. :: diff --git a/Documentation/git-verify-pack.txt b/Documentation/git-verify-pack.txt index 4962d6975f..7a6132b016 100644 --- a/Documentation/git-verify-pack.txt +++ b/Documentation/git-verify-pack.txt @@ -25,7 +25,7 @@ OPTIONS -v:: After verifying the pack, show list of objects contained in the pack. ---:: +\--:: Do not interpret any more arguments as options. OUTPUT FORMAT diff --git a/Documentation/git-whatchanged.txt b/Documentation/git-whatchanged.txt index 641cb7ea97..e8f21d02f7 100644 --- a/Documentation/git-whatchanged.txt +++ b/Documentation/git-whatchanged.txt @@ -58,7 +58,7 @@ git-whatchanged -p v2.6.12.. include/scsi drivers/scsi:: Show as patches the commits since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -git-whatchanged --since="2 weeks ago" -- gitk:: +git-whatchanged --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index eb126d7a4b..cb482bf98e 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -31,7 +31,7 @@ gitk v2.6.12.. include/scsi drivers/scsi:: Show as the changes since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -gitk --since="2 weeks ago" -- gitk:: +gitk --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named From ae0b219c8e32aa8f34401252d845916b136a467b Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:36 -0400 Subject: [PATCH 08/15] Update git-unpack-objects documentation. Document that git-unpack-objects will not produce any results when used on a pack that exists in a repository; move it first. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-unpack-objects.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/git-unpack-objects.txt b/Documentation/git-unpack-objects.txt index 18280628a1..c20b38b08a 100644 --- a/Documentation/git-unpack-objects.txt +++ b/Documentation/git-unpack-objects.txt @@ -13,9 +13,16 @@ SYNOPSIS DESCRIPTION ----------- -Reads a packed archive (.pack) from the standard input, and -expands the objects contained in the pack into "one-file -one-object" format in $GIT_OBJECT_DIRECTORY. +Read a packed archive (.pack) from the standard input, expanding +the objects contained within and writing them into the repository in +"loose" (one object per file) format. + +Objects that already exist in the repository will *not* be unpacked +from the pack-file. Therefore, nothing will be unpacked if you use +this command on a pack-file that exists within the target repository. + +Please see the `git-repack` documentation for options to generate +new packs and replace existing ones. OPTIONS ------- From 81ae43cdc4ec4bfba1638aa9786e08322d10b72c Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:06:07 -0400 Subject: [PATCH 09/15] Clarify git-cherry documentation. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-cherry.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt index 9a5e37186f..893baaa6f6 100644 --- a/Documentation/git-cherry.txt +++ b/Documentation/git-cherry.txt @@ -11,11 +11,20 @@ SYNOPSIS DESCRIPTION ----------- -Each commit between the fork-point and is examined, and compared against -the change each commit between the fork-point and introduces. -Commits already included in upstream are prefixed with '-' (meaning "drop from -my local pull"), while commits missing from upstream are prefixed with '+' -(meaning "add to the updated upstream"). +The changeset (or "diff") of each commit between the fork-point and +is compared against each commit between the fork-point and . + +Every commit with a changeset that doesn't exist in the other branch +has its id (sha1) reported, prefixed by a symbol. Those existing only +in the branch are prefixed with a minus (-) sign, and those +that only exist in the branch are prefixed with a plus (+) symbol. + +Because git-cherry compares the changeset rather than the commit id +(sha1), you can use git-cherry to find out if a commit you made locally +has been applied under a different commit id. For example, +this will happen if you're feeding patches via email rather +than pushing or pulling commits directly. + OPTIONS ------- From 93ddef3e2dd5f7f3238fad9d52e974d03c7844f2 Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 09:49:15 -0400 Subject: [PATCH 10/15] Fix for config file section parsing. Currently, if the target key has a section that matches the initial substring of another section we mistakenly believe we've found the correct section. To avoid this problem, ensure that the section lengths are identical before comparison. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 4e1f0c2286..a3e14d76e5 100644 --- a/config.c +++ b/config.c @@ -335,8 +335,9 @@ static int store_aux(const char* key, const char* value) store.offset[store.seen] = ftell(config_file); store.state = KEY_SEEN; store.seen++; - } else if(!strncmp(key, store.key, store.baselen)) - store.state = SECTION_SEEN; + } else if (strrchr(key, '.') - key == store.baselen && + !strncmp(key, store.key, store.baselen)) + store.state = SECTION_SEEN; } return 0; } From 7ebdba614223f867d3f19963647406df1d0e5ce0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 2 May 2006 16:58:37 +0200 Subject: [PATCH 11/15] repo-config: trim white-space before comment Earlier, calling git-repo-config core.hello on a .git/config like this: [core] hello = world ; a comment would yield "world " (i.e. with a trailing space). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano (cherry picked from c1aee1fd8d94da9b3c5d2dc1d4264f7e73a58f80 commit) --- config.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index a3e14d76e5..2cdf5fcab4 100644 --- a/config.c +++ b/config.c @@ -60,6 +60,12 @@ static char *parse_value(void) space = 1; continue; } + if (!quote) { + if (c == ';' || c == '#') { + comment = 1; + continue; + } + } if (space) { if (len) value[len++] = ' '; @@ -93,12 +99,6 @@ static char *parse_value(void) quote = 1-quote; continue; } - if (!quote) { - if (c == ';' || c == '#') { - comment = 1; - continue; - } - } value[len++] = c; } } From e388c7382563b7497397c78bc078d0679dc891a8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 00:40:24 -0700 Subject: [PATCH 12/15] core.prefersymlinkrefs: use symlinks for .git/HEAD When inspecting a project whose build infrastructure used to assume that .git/HEAD is a symlink ref, core.prefersymlinkrefs in the config file of such a project would help to bisect its history. Signed-off-by: Junio C Hamano (cherry picked from 9f0bb90d161edf8c43f5261d12bf83f14eb02ff4 commit) --- Documentation/config.txt | 8 +++++--- Makefile | 8 ++++++-- cache.h | 2 +- config.c | 4 ++-- environment.c | 2 +- refs.c | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index b27b0d5c06..d1a4bec0d4 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -64,9 +64,11 @@ core.ignoreStat:: slow, such as Microsoft Windows. See gitlink:git-update-index[1]. False by default. -core.onlyUseSymrefs:: - Always use the "symref" format instead of symbolic links for HEAD - and other symbolic reference files. True by default. +core.preferSymlinkRefs:: + Instead of the default "symref" format for HEAD + and other symbolic reference files, use symbolic links. + This is sometimes needed to work with old scripts that + expect HEAD to be a symbolic link. core.repositoryFormatVersion:: Internal variable identifying the repository format and layout diff --git a/Makefile b/Makefile index 8aed3af016..3972d10886 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ all: # # Define NO_SETENV if you don't have setenv in the C library. # -# Define USE_SYMLINK_HEAD if you want .git/HEAD to be a symbolic link. -# Don't enable it on Windows. +# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. +# Enable it on Windows. By default, symrefs are still used. # # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. @@ -260,6 +260,7 @@ ifeq ($(uname_O),Cygwin) NO_D_TYPE_IN_DIRENT = YesPlease NO_D_INO_IN_DIRENT = YesPlease NO_STRCASESTR = YesPlease + NO_SYMLINK_HEAD = YesPlease NEEDS_LIBICONV = YesPlease # There are conflicting reports about this. # On some boxes NO_MMAP is needed, and not so elsewhere. @@ -383,6 +384,9 @@ endif ifdef NO_D_INO_IN_DIRENT ALL_CFLAGS += -DNO_D_INO_IN_DIRENT endif +ifdef NO_SYMLINK_HEAD + ALL_CFLAGS += -DNO_SYMLINK_HEAD +endif ifdef NO_STRCASESTR COMPAT_CFLAGS += -DNO_STRCASESTR COMPAT_OBJS += compat/strcasestr.o diff --git a/cache.h b/cache.h index 4d8fabc6d8..ae69fdea95 100644 --- a/cache.h +++ b/cache.h @@ -168,7 +168,7 @@ extern void rollback_index_file(struct cache_file *); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; extern int assume_unchanged; -extern int only_use_symrefs; +extern int prefer_symlink_refs; extern int warn_ambiguous_refs; extern int diff_rename_limit_default; extern int shared_repository; diff --git a/config.c b/config.c index 2cdf5fcab4..87fb22041e 100644 --- a/config.c +++ b/config.c @@ -227,8 +227,8 @@ int git_default_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "core.symrefsonly")) { - only_use_symrefs = git_config_bool(var, value); + if (!strcmp(var, "core.prefersymlinkrefs")) { + prefer_symlink_refs = git_config_bool(var, value); return 0; } diff --git a/environment.c b/environment.c index 6df647862c..444c99ed6e 100644 --- a/environment.c +++ b/environment.c @@ -13,7 +13,7 @@ char git_default_email[MAX_GITNAME]; char git_default_name[MAX_GITNAME]; int trust_executable_bit = 1; int assume_unchanged = 0; -int only_use_symrefs = 0; +int prefer_symlink_refs = 0; int warn_ambiguous_refs = 1; int repository_format_version = 0; char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8"; diff --git a/refs.c b/refs.c index 03398ccc53..275b914b2b 100644 --- a/refs.c +++ b/refs.c @@ -76,8 +76,8 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master) char ref[1000]; int fd, len, written; -#ifdef USE_SYMLINK_HEAD - if (!only_use_symrefs) { +#ifndef NO_SYMLINK_HEAD + if (prefer_symlink_refs) { unlink(git_HEAD); if (!symlink(refs_heads_master, git_HEAD)) return 0; From 86118bcb463e3f34b3df21d550335a40586dfb66 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 03:20:44 -0700 Subject: [PATCH 13/15] pack-object: squelch eye-candy on non-tty One of my post-update scripts runs a git-fetch into a separate repository and sends the results back to me (2>&1); I end up getting this in the mail: Generating pack... Done counting 180 objects. Result has 131 objects. Deltifying 131 objects. 0% (0/131) done^M 1% (2/131) done^M... This defaults not to do the progress report when not on a tty. You could give --progress to force the progress report, but let's not bother even documenting it nor mentioning it in the usage string. Signed-off-by: Junio C Hamano --- pack-objects.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pack-objects.c b/pack-objects.c index 6604338131..53caed42dd 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1239,6 +1239,7 @@ int main(int argc, char **argv) setup_git_directory(); + progress = isatty(2); for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -1269,6 +1270,10 @@ int main(int argc, char **argv) usage(pack_usage); continue; } + if (!strcmp("--progress", arg)) { + progress = 1; + continue; + } if (!strcmp("-q", arg)) { progress = 0; continue; From 051308f6e9cebeb76b8fb4f52b7e9e7ce064445c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 May 2006 16:51:44 -0700 Subject: [PATCH 14/15] binary patch. This adds "binary patch" to the diff output and teaches apply what to do with them. On the diff generation side, traditionally, we said "Binary files differ\n" without giving anything other than the preimage and postimage object name on the index line. This was good enough for applying a patch generated from your own repository (very useful while rebasing), because the postimage would be available in such a case. However, this was not useful when the recipient of such a patch via e-mail were to apply it, even if the preimage was available. This patch allows the diff to generate "binary" patch when operating under --full-index option. The binary patch follows the usual extended git diff headers, and looks like this: "GIT binary patch\n" "\n" ... "\n" Each line is prefixed with a "length-byte", whose value is upper or lowercase alphabet that encodes number of bytes that the data on the line decodes to (1..52 -- 'A' means 1, 'B' means 2, ..., 'Z' means 26, 'a' means 27, ...). is 1 or more groups of 5-byte sequence, each of which encodes up to 4 bytes in base85 encoding. Because 52 / 4 * 5 = 65 and we have the length byte, an output line is capped to 66 characters. The payload is the same diff-delta as we use in the packfiles. On the consumption side, git-apply now can decode and apply the binary patch when --allow-binary-replacement is given, the diff was generated with --full-index, and the receiving repository has the preimage blob, which is the same condition as it always required when accepting an "Binary files differ\n" patch. Signed-off-by: Junio C Hamano --- Makefile | 2 +- apply.c | 242 ++++++++++++++++++++++++++++++++++++++++--------------- cache.h | 3 + diff.c | 106 ++++++++++++++++++++++-- 4 files changed, 280 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 45484fcd82..814010d7b4 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,7 @@ DIFF_OBJS = \ diffcore-delta.o log-tree.o LIB_OBJS = \ - blob.o commit.o connect.o csum-file.o \ + blob.o commit.o connect.o csum-file.o base85.o \ date.o diff-delta.o entry.o exec_cmd.o ident.o index.o \ object.o pack-check.o patch-delta.o path.o pkt-line.o \ quote.o read-cache.o refs.o run-command.o \ diff --git a/apply.c b/apply.c index 269210a578..e37c4ebf52 100644 --- a/apply.c +++ b/apply.c @@ -10,6 +10,7 @@ #include "cache.h" #include "quote.h" #include "blob.h" +#include "delta.h" // --check turns on checking that the working tree matches the // files that are being modified, but doesn't apply the patch @@ -966,6 +967,70 @@ static inline int metadata_changes(struct patch *patch) patch->old_mode != patch->new_mode); } +static int parse_binary(char *buffer, unsigned long size, struct patch *patch) +{ + /* We have read "GIT binary patch\n"; what follows is a + * sequence of 'length-byte' followed by base-85 encoded + * delta data. + * + * Each 5-byte sequence of base-85 encodes up to 4 bytes, + * and we would limit the patch line to 66 characters, + * so one line can fit up to 13 groups that would decode + * to 52 bytes max. The length byte 'A'-'Z' corresponds + * to 1-26 bytes, and 'a'-'z' corresponds to 27-52 bytes. + * The end of binary is signalled with an empty line. + */ + int llen, used; + struct fragment *fragment; + char *delta = NULL; + + patch->is_binary = 1; + patch->fragments = fragment = xcalloc(1, sizeof(*fragment)); + used = 0; + while (1) { + int byte_length, max_byte_length, newsize; + llen = linelen(buffer, size); + used += llen; + linenr++; + if (llen == 1) + break; + /* Minimum line is "A00000\n" which is 7-byte long, + * and the line length must be multiple of 5 plus 2. + */ + if ((llen < 7) || (llen-2) % 5) + goto corrupt; + max_byte_length = (llen - 2) / 5 * 4; + byte_length = *buffer; + if ('A' <= byte_length && byte_length <= 'Z') + byte_length = byte_length - 'A' + 1; + else if ('a' <= byte_length && byte_length <= 'z') + byte_length = byte_length - 'a' + 27; + else + goto corrupt; + /* if the input length was not multiple of 4, we would + * have filler at the end but the filler should never + * exceed 3 bytes + */ + if (max_byte_length < byte_length || + byte_length <= max_byte_length - 4) + goto corrupt; + newsize = fragment->size + byte_length; + delta = xrealloc(delta, newsize); + if (decode_85(delta + fragment->size, + buffer + 1, + byte_length)) + goto corrupt; + fragment->size = newsize; + buffer += llen; + size -= llen; + } + fragment->patch = delta; + return used; + corrupt: + return error("corrupt binary patch at line %d: %.*s", + linenr-1, llen-1, buffer); +} + static int parse_chunk(char *buffer, unsigned long size, struct patch *patch) { int hdrsize, patchsize; @@ -982,19 +1047,34 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch) "Files ", NULL, }; + static const char git_binary[] = "GIT binary patch\n"; int i; int hd = hdrsize + offset; unsigned long llen = linelen(buffer + hd, size - hd); - if (!memcmp(" differ\n", buffer + hd + llen - 8, 8)) + if (llen == sizeof(git_binary) - 1 && + !memcmp(git_binary, buffer + hd, llen)) { + int used; + linenr++; + used = parse_binary(buffer + hd + llen, + size - hd - llen, patch); + if (used) + patchsize = used + llen; + else + patchsize = 0; + } + else if (!memcmp(" differ\n", buffer + hd + llen - 8, 8)) { for (i = 0; binhdr[i]; i++) { int len = strlen(binhdr[i]); if (len < size - hd && !memcmp(binhdr[i], buffer + hd, len)) { + linenr++; patch->is_binary = 1; + patchsize = llen; break; } } + } /* Empty patch cannot be applied if: * - it is a binary patch and we do not do binary_replace, or @@ -1345,75 +1425,107 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag) return offset; } +static int apply_binary(struct buffer_desc *desc, struct patch *patch) +{ + const char *name = patch->old_name ? patch->old_name : patch->new_name; + unsigned char sha1[20]; + unsigned char hdr[50]; + int hdrlen; + + if (!allow_binary_replacement) + return error("cannot apply binary patch to '%s' " + "without --allow-binary-replacement", + name); + + /* For safety, we require patch index line to contain + * full 40-byte textual SHA1 for old and new, at least for now. + */ + if (strlen(patch->old_sha1_prefix) != 40 || + strlen(patch->new_sha1_prefix) != 40 || + get_sha1_hex(patch->old_sha1_prefix, sha1) || + get_sha1_hex(patch->new_sha1_prefix, sha1)) + return error("cannot apply binary patch to '%s' " + "without full index line", name); + + if (patch->old_name) { + /* See if the old one matches what the patch + * applies to. + */ + write_sha1_file_prepare(desc->buffer, desc->size, + blob_type, sha1, hdr, &hdrlen); + if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix)) + return error("the patch applies to '%s' (%s), " + "which does not match the " + "current contents.", + name, sha1_to_hex(sha1)); + } + else { + /* Otherwise, the old one must be empty. */ + if (desc->size) + return error("the patch applies to an empty " + "'%s' but it is not empty", name); + } + + if (desc->buffer) { + free(desc->buffer); + desc->alloc = desc->size = 0; + } + get_sha1_hex(patch->new_sha1_prefix, sha1); + if (!memcmp(sha1, null_sha1, 20)) + return 0; /* deletion patch */ + + if (has_sha1_file(sha1)) { + char type[10]; + unsigned long size; + + desc->buffer = read_sha1_file(sha1, type, &size); + if (!desc->buffer) + return error("the necessary postimage %s for " + "'%s' cannot be read", + patch->new_sha1_prefix, name); + desc->alloc = desc->size = size; + } + else { + char type[10]; + unsigned long src_size, dst_size; + void *src; + + get_sha1_hex(patch->old_sha1_prefix, sha1); + src = read_sha1_file(sha1, type, &src_size); + if (!src) + return error("the necessary preimage %s for " + "'%s' cannot be read", + patch->old_sha1_prefix, name); + + /* patch->fragment->patch has the delta data and + * we should apply it to the preimage. + */ + desc->buffer = patch_delta(src, src_size, + (void*) patch->fragments->patch, + patch->fragments->size, + &dst_size); + if (!desc->buffer) + return error("binary patch does not apply to '%s'", + name); + desc->size = desc->alloc = dst_size; + + /* verify that the result matches */ + write_sha1_file_prepare(desc->buffer, desc->size, blob_type, + sha1, hdr, &hdrlen); + if (strcmp(sha1_to_hex(sha1), patch->new_sha1_prefix)) + return error("binary patch to '%s' creates incorrect result", name); + } + + return 0; +} + static int apply_fragments(struct buffer_desc *desc, struct patch *patch) { struct fragment *frag = patch->fragments; const char *name = patch->old_name ? patch->old_name : patch->new_name; - if (patch->is_binary) { - unsigned char sha1[20]; - - if (!allow_binary_replacement) - return error("cannot apply binary patch to '%s' " - "without --allow-binary-replacement", - name); - - /* For safety, we require patch index line to contain - * full 40-byte textual SHA1 for old and new, at least for now. - */ - if (strlen(patch->old_sha1_prefix) != 40 || - strlen(patch->new_sha1_prefix) != 40 || - get_sha1_hex(patch->old_sha1_prefix, sha1) || - get_sha1_hex(patch->new_sha1_prefix, sha1)) - return error("cannot apply binary patch to '%s' " - "without full index line", name); - - if (patch->old_name) { - unsigned char hdr[50]; - int hdrlen; - - /* See if the old one matches what the patch - * applies to. - */ - write_sha1_file_prepare(desc->buffer, desc->size, - blob_type, sha1, hdr, &hdrlen); - if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix)) - return error("the patch applies to '%s' (%s), " - "which does not match the " - "current contents.", - name, sha1_to_hex(sha1)); - } - else { - /* Otherwise, the old one must be empty. */ - if (desc->size) - return error("the patch applies to an empty " - "'%s' but it is not empty", name); - } - - /* For now, we do not record post-image data in the patch, - * and require the object already present in the recipient's - * object database. - */ - if (desc->buffer) { - free(desc->buffer); - desc->alloc = desc->size = 0; - } - get_sha1_hex(patch->new_sha1_prefix, sha1); - - if (memcmp(sha1, null_sha1, 20)) { - char type[10]; - unsigned long size; - - desc->buffer = read_sha1_file(sha1, type, &size); - if (!desc->buffer) - return error("the necessary postimage %s for " - "'%s' does not exist", - patch->new_sha1_prefix, name); - desc->alloc = desc->size = size; - } - - return 0; - } + if (patch->is_binary) + return apply_binary(desc, patch); while (frag) { if (apply_one_fragment(desc, frag) < 0) diff --git a/cache.h b/cache.h index 9d0ddcff01..2f32f3d62a 100644 --- a/cache.h +++ b/cache.h @@ -363,4 +363,7 @@ extern int receive_keep_pack(int fd[2], const char *me, int quiet); /* pager.c */ extern void setup_pager(void); +/* base85 */ +int decode_85(char *dst, char *line, int linelen); + #endif /* CACHE_H */ diff --git a/diff.c b/diff.c index c845c87113..b14d897f19 100644 --- a/diff.c +++ b/diff.c @@ -8,6 +8,7 @@ #include "quote.h" #include "diff.h" #include "diffcore.h" +#include "delta.h" #include "xdiff-interface.h" static int use_size_cache; @@ -391,6 +392,90 @@ static void show_stats(struct diffstat_t* data) total_files, adds, dels); } +static void *encode_delta_size(void *data, unsigned long size) +{ + unsigned char *cp = data; + *cp++ = size; + size >>= 7; + while (size) { + cp[-1] |= 0x80; + *cp++ = size; + size >>= 7; + } + return cp; +} + +static void *safe_diff_delta(const unsigned char *src, unsigned long src_size, + const unsigned char *dst, unsigned long dst_size, + unsigned long *delta_size) +{ + unsigned long bufsize; + unsigned char *data; + unsigned char *cp; + + if (src_size && dst_size) + return diff_delta(src, src_size, dst, dst_size, delta_size, 0); + + /* diff-delta does not like to do delta with empty, so + * we do that by hand here. Sigh... + */ + + if (!src_size) + /* literal copy can be done only 127-byte at a time. + */ + bufsize = dst_size + (dst_size / 127) + 40; + else + bufsize = 40; + data = xmalloc(bufsize); + cp = encode_delta_size(data, src_size); + cp = encode_delta_size(cp, dst_size); + + if (dst_size) { + /* copy out literally */ + while (dst_size) { + int sz = (127 < dst_size) ? 127 : dst_size; + *cp++ = sz; + dst_size -= sz; + while (sz) { + *cp++ = *dst++; + sz--; + } + } + } + *delta_size = (cp - data); + return data; +} + +static void emit_binary_diff(mmfile_t *one, mmfile_t *two) +{ + void *delta, *cp; + unsigned long delta_size; + + printf("GIT binary patch\n"); + delta = safe_diff_delta(one->ptr, one->size, + two->ptr, two->size, + &delta_size); + if (!delta) + die("unable to generate binary diff"); + + /* emit delta encoded in base85 */ + cp = delta; + while (delta_size) { + int bytes = (52 < delta_size) ? 52 : delta_size; + char line[70]; + delta_size -= bytes; + if (bytes <= 26) + line[0] = bytes + 'A' - 1; + else + line[0] = bytes - 26 + 'a' - 1; + encode_85(line + 1, cp, bytes); + cp += bytes; + puts(line); + } + printf("\n"); + free(delta); +} + #define FIRST_FEW_BYTES 8000 static int mmfile_is_binary(mmfile_t *mf) { @@ -407,6 +492,7 @@ static void builtin_diff(const char *name_a, struct diff_filespec *one, struct diff_filespec *two, const char *xfrm_msg, + struct diff_options *o, int complete_rewrite) { mmfile_t mf1, mf2; @@ -451,8 +537,13 @@ static void builtin_diff(const char *name_a, if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) die("unable to read files to diff"); - if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) - printf("Binary files %s and %s differ\n", lbl[0], lbl[1]); + if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) { + if (o->full_index) + emit_binary_diff(&mf1, &mf2); + else + printf("Binary files %s and %s differ\n", + lbl[0], lbl[1]); + } else { /* Crazy xdl interfaces.. */ const char *diffopts = getenv("GIT_DIFF_OPTS"); @@ -928,6 +1019,7 @@ static void run_diff_cmd(const char *pgm, struct diff_filespec *one, struct diff_filespec *two, const char *xfrm_msg, + struct diff_options *o, int complete_rewrite) { if (pgm) { @@ -937,7 +1029,7 @@ static void run_diff_cmd(const char *pgm, } if (one && two) builtin_diff(name, other ? other : name, - one, two, xfrm_msg, complete_rewrite); + one, two, xfrm_msg, o, complete_rewrite); else printf("* Unmerged path %s\n", name); } @@ -971,7 +1063,7 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o) if (DIFF_PAIR_UNMERGED(p)) { /* unmerged */ - run_diff_cmd(pgm, p->one->path, NULL, NULL, NULL, NULL, 0); + run_diff_cmd(pgm, p->one->path, NULL, NULL, NULL, NULL, o, 0); return; } @@ -1041,14 +1133,14 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o) * needs to be split into deletion and creation. */ struct diff_filespec *null = alloc_filespec(two->path); - run_diff_cmd(NULL, name, other, one, null, xfrm_msg, 0); + run_diff_cmd(NULL, name, other, one, null, xfrm_msg, o, 0); free(null); null = alloc_filespec(one->path); - run_diff_cmd(NULL, name, other, null, two, xfrm_msg, 0); + run_diff_cmd(NULL, name, other, null, two, xfrm_msg, o, 0); free(null); } else - run_diff_cmd(pgm, name, other, one, two, xfrm_msg, + run_diff_cmd(pgm, name, other, one, two, xfrm_msg, o, complete_rewrite); free(name_munged); From 0660626caff6ac3745cd7b7908a2ca540141a2ec Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 02:41:53 -0700 Subject: [PATCH 15/15] binary diff: further updates. This updates the user interface and generated diff data format. * "diff --binary" is used to signal that we want an e-mailable binary patch. It implies --full-index and -p. * "apply --allow-binary-replacement" acquired a short synonym "apply --binary". * After the "GIT binary patch\n" header line there is a token to record which binary patch mechanism was used, so that we can extend it later. Currently there are two mechanisms defined: "literal" and "delta". The former records the deflated postimage and the latter records the deflated delta from the preimage to postimage. For purely implementation convenience, I added the deflated length after these "literal/delta" tokens (otherwise the decoding side needs to guess and reallocate the buffer while inflating). Improvement patches are very welcomed. Signed-off-by: Junio C Hamano --- apply.c | 130 +++++++++++++++++++++++++++++++++++++++-------------- base85.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ cache.h | 1 + diff.c | 132 +++++++++++++++++++++++++++++------------------------- diff.h | 1 + 5 files changed, 303 insertions(+), 95 deletions(-) create mode 100644 base85.c diff --git a/apply.c b/apply.c index e37c4ebf52..1b93aab8af 100644 --- a/apply.c +++ b/apply.c @@ -114,6 +114,9 @@ struct patch { char *new_name, *old_name, *def_name; unsigned int old_mode, new_mode; int is_rename, is_copy, is_new, is_delete, is_binary; +#define BINARY_DELTA_DEFLATED 1 +#define BINARY_LITERAL_DEFLATED 2 + unsigned long deflate_origlen; int lines_added, lines_deleted; int score; struct fragment *fragments; @@ -969,9 +972,11 @@ static inline int metadata_changes(struct patch *patch) static int parse_binary(char *buffer, unsigned long size, struct patch *patch) { - /* We have read "GIT binary patch\n"; what follows is a - * sequence of 'length-byte' followed by base-85 encoded - * delta data. + /* We have read "GIT binary patch\n"; what follows is a line + * that says the patch method (currently, either "deflated + * literal" or "deflated delta") and the length of data before + * deflating; a sequence of 'length-byte' followed by base-85 + * encoded data follows. * * Each 5-byte sequence of base-85 encodes up to 4 bytes, * and we would limit the patch line to 66 characters, @@ -982,11 +987,27 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch) */ int llen, used; struct fragment *fragment; - char *delta = NULL; + char *data = NULL; - patch->is_binary = 1; patch->fragments = fragment = xcalloc(1, sizeof(*fragment)); - used = 0; + + /* Grab the type of patch */ + llen = linelen(buffer, size); + used = llen; + linenr++; + + if (!strncmp(buffer, "delta ", 6)) { + patch->is_binary = BINARY_DELTA_DEFLATED; + patch->deflate_origlen = strtoul(buffer + 6, NULL, 10); + } + else if (!strncmp(buffer, "literal ", 8)) { + patch->is_binary = BINARY_LITERAL_DEFLATED; + patch->deflate_origlen = strtoul(buffer + 8, NULL, 10); + } + else + return error("unrecognized binary patch at line %d: %.*s", + linenr-1, llen-1, buffer); + buffer += llen; while (1) { int byte_length, max_byte_length, newsize; llen = linelen(buffer, size); @@ -1015,8 +1036,8 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch) byte_length <= max_byte_length - 4) goto corrupt; newsize = fragment->size + byte_length; - delta = xrealloc(delta, newsize); - if (decode_85(delta + fragment->size, + data = xrealloc(data, newsize); + if (decode_85(data + fragment->size, buffer + 1, byte_length)) goto corrupt; @@ -1024,7 +1045,7 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch) buffer += llen; size -= llen; } - fragment->patch = delta; + fragment->patch = data; return used; corrupt: return error("corrupt binary patch at line %d: %.*s", @@ -1425,6 +1446,61 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag) return offset; } +static char *inflate_it(const void *data, unsigned long size, + unsigned long inflated_size) +{ + z_stream stream; + void *out; + int st; + + memset(&stream, 0, sizeof(stream)); + + stream.next_in = (unsigned char *)data; + stream.avail_in = size; + stream.next_out = out = xmalloc(inflated_size); + stream.avail_out = inflated_size; + inflateInit(&stream); + st = inflate(&stream, Z_FINISH); + if ((st != Z_STREAM_END) || stream.total_out != inflated_size) { + free(out); + return NULL; + } + return out; +} + +static int apply_binary_fragment(struct buffer_desc *desc, struct patch *patch) +{ + unsigned long dst_size; + struct fragment *fragment = patch->fragments; + void *data; + void *result; + + data = inflate_it(fragment->patch, fragment->size, + patch->deflate_origlen); + if (!data) + return error("corrupt patch data"); + switch (patch->is_binary) { + case BINARY_DELTA_DEFLATED: + result = patch_delta(desc->buffer, desc->size, + data, + patch->deflate_origlen, + &dst_size); + free(desc->buffer); + desc->buffer = result; + free(data); + break; + case BINARY_LITERAL_DEFLATED: + free(desc->buffer); + desc->buffer = data; + dst_size = patch->deflate_origlen; + break; + } + if (!desc->buffer) + return -1; + desc->size = desc->alloc = dst_size; + return 0; +} + static int apply_binary(struct buffer_desc *desc, struct patch *patch) { const char *name = patch->old_name ? patch->old_name : patch->new_name; @@ -1466,18 +1542,20 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch) "'%s' but it is not empty", name); } - if (desc->buffer) { + get_sha1_hex(patch->new_sha1_prefix, sha1); + if (!memcmp(sha1, null_sha1, 20)) { free(desc->buffer); desc->alloc = desc->size = 0; - } - get_sha1_hex(patch->new_sha1_prefix, sha1); - if (!memcmp(sha1, null_sha1, 20)) + desc->buffer = NULL; return 0; /* deletion patch */ + } if (has_sha1_file(sha1)) { + /* We already have the postimage */ char type[10]; unsigned long size; + free(desc->buffer); desc->buffer = read_sha1_file(sha1, type, &size); if (!desc->buffer) return error("the necessary postimage %s for " @@ -1486,28 +1564,13 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch) desc->alloc = desc->size = size; } else { - char type[10]; - unsigned long src_size, dst_size; - void *src; - - get_sha1_hex(patch->old_sha1_prefix, sha1); - src = read_sha1_file(sha1, type, &src_size); - if (!src) - return error("the necessary preimage %s for " - "'%s' cannot be read", - patch->old_sha1_prefix, name); - - /* patch->fragment->patch has the delta data and - * we should apply it to the preimage. + /* We have verified desc matches the preimage; + * apply the patch data to it, which is stored + * in the patch->fragments->{patch,size}. */ - desc->buffer = patch_delta(src, src_size, - (void*) patch->fragments->patch, - patch->fragments->size, - &dst_size); - if (!desc->buffer) + if (apply_binary_fragment(desc, patch)) return error("binary patch does not apply to '%s'", name); - desc->size = desc->alloc = dst_size; /* verify that the result matches */ write_sha1_file_prepare(desc->buffer, desc->size, blob_type, @@ -2102,7 +2165,8 @@ int main(int argc, char **argv) diffstat = 1; continue; } - if (!strcmp(arg, "--allow-binary-replacement")) { + if (!strcmp(arg, "--allow-binary-replacement") || + !strcmp(arg, "--binary")) { allow_binary_replacement = 1; continue; } diff --git a/base85.c b/base85.c new file mode 100644 index 0000000000..b97f7f933a --- /dev/null +++ b/base85.c @@ -0,0 +1,134 @@ +#include "cache.h" + +#undef DEBUG_85 + +#ifdef DEBUG_85 +#define say(a) fprintf(stderr, a) +#define say1(a,b) fprintf(stderr, a, b) +#define say2(a,b,c) fprintf(stderr, a, b, c) +#else +#define say(a) do {} while(0) +#define say1(a,b) do {} while(0) +#define say2(a,b,c) do {} while(0) +#endif + +static const char en85[] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', + '!', '#', '$', '%', '&', '(', ')', '*', '+', '-', + ';', '<', '=', '>', '?', '@', '^', '_', '`', '{', + '|', '}', '~' +}; + +static char de85[256]; +static void prep_base85(void) +{ + int i; + if (de85['Z']) + return; + for (i = 0; i < ARRAY_SIZE(en85); i++) { + int ch = en85[i]; + de85[ch] = i + 1; + } +} + +int decode_85(char *dst, char *buffer, int len) +{ + prep_base85(); + + say2("decode 85 <%.*s>", len/4*5, buffer); + while (len) { + unsigned acc = 0; + int cnt; + for (cnt = 0; cnt < 5; cnt++, buffer++) { + int ch = *((unsigned char *)buffer); + int de = de85[ch]; + if (!de) + return error("invalid base85 alphabet %c", ch); + de--; + if (cnt == 4) { + /* + * Detect overflow. The largest + * 5-letter possible is "|NsC0" to + * encode 0xffffffff, and "|NsC" gives + * 0x03030303 at this point (i.e. + * 0xffffffff = 0x03030303 * 85). + */ + if (0x03030303 < acc || + (0x03030303 == acc && de)) + error("invalid base85 sequence %.5s", + buffer-3); + } + acc = acc * 85 + de; + say1(" <%08x>", acc); + } + say1(" %08x", acc); + for (cnt = 0; cnt < 4 && len; cnt++, len--) { + *dst++ = (acc >> 24) & 0xff; + acc = acc << 8; + } + } + say("\n"); + + return 0; +} + +void encode_85(char *buf, unsigned char *data, int bytes) +{ + prep_base85(); + + say("encode 85"); + while (bytes) { + unsigned acc = 0; + int cnt; + for (cnt = 0; cnt < 4 && bytes; cnt++, bytes--) { + int ch = *data++; + acc |= ch << ((3-cnt)*8); + } + say1(" %08x", acc); + for (cnt = 0; cnt < 5; cnt++) { + int val = acc % 85; + acc /= 85; + buf[4-cnt] = en85[val]; + } + buf += 5; + } + say("\n"); + + *buf = 0; +} + +#ifdef DEBUG_85 +int main(int ac, char **av) +{ + char buf[1024]; + + if (!strcmp(av[1], "-e")) { + int len = strlen(av[2]); + encode_85(buf, av[2], len); + if (len <= 26) len = len + 'A' - 1; + else len = len + 'a' - 26 + 1; + printf("encoded: %c%s\n", len, buf); + return 0; + } + if (!strcmp(av[1], "-d")) { + int len = *av[2]; + if ('A' <= len && len <= 'Z') len = len - 'A' + 1; + else len = len - 'a' + 26 + 1; + decode_85(buf, av[2]+1, len); + printf("decoded: %.*s\n", len, buf); + return 0; + } + if (!strcmp(av[1], "-t")) { + char t[4] = { -1,-1,-1,-1 }; + encode_85(buf, t, 4); + printf("encoded: D%s\n", buf); + return 0; + } +} +#endif diff --git a/cache.h b/cache.h index 2f32f3d62a..4b7a439253 100644 --- a/cache.h +++ b/cache.h @@ -365,5 +365,6 @@ extern void setup_pager(void); /* base85 */ int decode_85(char *dst, char *line, int linelen); +void encode_85(char *buf, unsigned char *data, int bytes); #endif /* CACHE_H */ diff --git a/diff.c b/diff.c index b14d897f19..bfe54c3e09 100644 --- a/diff.c +++ b/diff.c @@ -392,78 +392,78 @@ static void show_stats(struct diffstat_t* data) total_files, adds, dels); } -static void *encode_delta_size(void *data, unsigned long size) +static unsigned char *deflate_it(char *data, + unsigned long size, + unsigned long *result_size) { - unsigned char *cp = data; - *cp++ = size; - size >>= 7; - while (size) { - cp[-1] |= 0x80; - *cp++ = size; - size >>= 7; - } - return cp; -} + int bound; + unsigned char *deflated; + z_stream stream; -static void *safe_diff_delta(const unsigned char *src, unsigned long src_size, - const unsigned char *dst, unsigned long dst_size, - unsigned long *delta_size) -{ - unsigned long bufsize; - unsigned char *data; - unsigned char *cp; + memset(&stream, 0, sizeof(stream)); + deflateInit(&stream, Z_BEST_COMPRESSION); + bound = deflateBound(&stream, size); + deflated = xmalloc(bound); + stream.next_out = deflated; + stream.avail_out = bound; - if (src_size && dst_size) - return diff_delta(src, src_size, dst, dst_size, delta_size, 0); - - /* diff-delta does not like to do delta with empty, so - * we do that by hand here. Sigh... - */ - - if (!src_size) - /* literal copy can be done only 127-byte at a time. - */ - bufsize = dst_size + (dst_size / 127) + 40; - else - bufsize = 40; - data = xmalloc(bufsize); - cp = encode_delta_size(data, src_size); - cp = encode_delta_size(cp, dst_size); - - if (dst_size) { - /* copy out literally */ - while (dst_size) { - int sz = (127 < dst_size) ? 127 : dst_size; - *cp++ = sz; - dst_size -= sz; - while (sz) { - *cp++ = *dst++; - sz--; - } - } - } - *delta_size = (cp - data); - return data; + stream.next_in = (unsigned char *)data; + stream.avail_in = size; + while (deflate(&stream, Z_FINISH) == Z_OK) + ; /* nothing */ + deflateEnd(&stream); + *result_size = stream.total_out; + return deflated; } static void emit_binary_diff(mmfile_t *one, mmfile_t *two) { - void *delta, *cp; + void *cp; + void *delta; + void *deflated; + void *data; + unsigned long orig_size; unsigned long delta_size; + unsigned long deflate_size; + unsigned long data_size; printf("GIT binary patch\n"); - delta = safe_diff_delta(one->ptr, one->size, - two->ptr, two->size, - &delta_size); - if (!delta) - die("unable to generate binary diff"); + /* We could do deflated delta, or we could do just deflated two, + * whichever is smaller. + */ + delta = NULL; + deflated = deflate_it(two->ptr, two->size, &deflate_size); + if (one->size && two->size) { + delta = diff_delta(one->ptr, one->size, + two->ptr, two->size, + &delta_size, deflate_size); + if (delta) { + void *to_free = delta; + orig_size = delta_size; + delta = deflate_it(delta, delta_size, &delta_size); + free(to_free); + } + } - /* emit delta encoded in base85 */ - cp = delta; - while (delta_size) { - int bytes = (52 < delta_size) ? 52 : delta_size; + if (delta && delta_size < deflate_size) { + printf("delta %lu\n", orig_size); + free(deflated); + data = delta; + data_size = delta_size; + } + else { + printf("literal %lu\n", two->size); + free(delta); + data = deflated; + data_size = deflate_size; + } + + /* emit data encoded in base85 */ + cp = data; + while (data_size) { + int bytes = (52 < data_size) ? 52 : data_size; char line[70]; - delta_size -= bytes; + data_size -= bytes; if (bytes <= 26) line[0] = bytes + 'A' - 1; else @@ -473,7 +473,7 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two) puts(line); } printf("\n"); - free(delta); + free(data); } #define FIRST_FEW_BYTES 8000 @@ -538,7 +538,11 @@ static void builtin_diff(const char *name_a, die("unable to read files to diff"); if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) { - if (o->full_index) + /* Quite common confusing case */ + if (mf1.size == mf2.size && + !memcmp(mf1.ptr, mf2.ptr, mf1.size)) + goto free_ab_and_return; + if (o->binary) emit_binary_diff(&mf1, &mf2); else printf("Binary files %s and %s differ\n", @@ -1239,6 +1243,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->rename_limit = strtoul(arg+2, NULL, 10); else if (!strcmp(arg, "--full-index")) options->full_index = 1; + else if (!strcmp(arg, "--binary")) { + options->output_format = DIFF_FORMAT_PATCH; + options->full_index = options->binary = 1; + } else if (!strcmp(arg, "--name-only")) options->output_format = DIFF_FORMAT_NAME; else if (!strcmp(arg, "--name-status")) diff --git a/diff.h b/diff.h index b3b2c4dd28..d052608404 100644 --- a/diff.h +++ b/diff.h @@ -28,6 +28,7 @@ struct diff_options { with_raw:1, with_stat:1, tree_in_recursive:1, + binary:1, full_index:1, silent_on_remove:1, find_copies_harder:1;