From 9f92f15f897fa1a943bcec324032cc4ca1f73ecf Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Sep 2005 00:53:02 -0700 Subject: [PATCH 01/11] Make 'git diff --cached' synonymous to 'git diff --cached HEAD'. When making changes to different files (i.e. dirty working tree) and committing logically separate changes in groups, often it is necessary to run 'git diff --cached HEAD' to make sure that the changes being committed makes sense. Saying 'git diff --cached' by mistake gives rather uninformative error message from git-diff-files complaining it does not understand --cached flag. Signed-off-by: Junio C Hamano --- git-diff.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/git-diff.sh b/git-diff.sh index 9732c8ac31..84a152af20 100755 --- a/git-diff.sh +++ b/git-diff.sh @@ -9,9 +9,21 @@ files=$(git-rev-parse --no-revs --no-flags --sq "$@") : ${flags:="'-M' '-p'"} +# I often say 'git diff --cached -p' and get scolded by git-diff-files, but +# obviously I mean 'git diff --cached -p HEAD' in that case. +case "$rev" in +'') + case " $flags " in + *" '--cached' "*) + rev='HEAD ' + ;; + esac +esac + case "$rev" in ?*' '?*' '?*) - die "I don't understand" + echo >&2 "I don't understand" + exit 1 ;; ?*' '^?*) begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') && From e20b134d72dd02b51d81144fe082c55da31b27cd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Sep 2005 14:02:57 -0700 Subject: [PATCH 02/11] Ignore a bit more generated files. Signed-off-by: Junio C Hamano --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 0fd59b9ff2..92deccb291 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,7 @@ git-verify-pack git-verify-tag git-whatchanged git-write-tree +#*.tar.gz +#*.dsc +#*.deb +#git-core.spec From ff8489cb0ad4274315fecffc1fb187b7951a51b5 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Fri, 23 Sep 2005 11:06:04 +0100 Subject: [PATCH 03/11] [PATCH] document command to show diff of a commit Document the best way to show the change introduced by a commit, based on the suggestion by Linus on the list. Signed-off-by: Junio C Hamano --- Documentation/git-diff-tree.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index 9ec4b29ff7..816c592ebf 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -9,12 +9,15 @@ git-diff-tree - Compares the content and mode of blobs found via two tree object SYNOPSIS -------- -'git-diff-tree' [--stdin] [-m] [-s] [-v] [--pretty] [-t] [] [...] +'git-diff-tree' [--stdin] [-m] [-s] [-v] [--pretty] [-t] [] [] [...] DESCRIPTION ----------- Compares the content and mode of the blobs found via two tree objects. +If there is only one given, the commit is compared with its parents +(see --stdin below). + Note that "git-diff-tree" can use the tree encapsulated in a commit object. OPTIONS From a95cb6fb6b247cf90bd0b1a8bf989a0b42ada775 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:13 +0400 Subject: [PATCH 04/11] [PATCH] fetch.c: Do not build object ref lists The fetch code does not need object ref lists; by disabling them we can save some time and memory. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- fetch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fetch.c b/fetch.c index e6fd624c12..62f30d1055 100644 --- a/fetch.c +++ b/fetch.c @@ -206,6 +206,7 @@ int pull(char *target) int fd = -1; save_commit_buffer = 0; + track_object_refs = 0; if (write_ref && current_ref) { fd = lock_ref_sha1(write_ref, current_ref); if (fd < 0) From d35bbe0b2e3765639c23978783a5319dfad33992 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:18 +0400 Subject: [PATCH 05/11] [PATCH] fetch.c: Plug memory leak in process_tree() When freeing a tree entry, must free its name too. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- fetch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fetch.c b/fetch.c index 62f30d1055..1a33ae984f 100644 --- a/fetch.c +++ b/fetch.c @@ -48,6 +48,7 @@ static int process_tree(struct tree *tree) struct tree_entry_list *next = entry->next; if (process(entry->item.any)) return -1; + free(entry->name); free(entry); entry = next; } From 8be707de55e473a5d850a1fcdc6e30589a37d548 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:23 +0400 Subject: [PATCH 06/11] [PATCH] git-local-fetch: Fix error checking and leak in setup_indices() setup_indices() did not check the return value of opendir(), and did not have a corresponding closedir() call. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- local-fetch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/local-fetch.c b/local-fetch.c index 8176532320..b3947a9657 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -38,6 +38,8 @@ static int setup_indices(void) unsigned char sha1[20]; sprintf(filename, "%s/objects/pack/", path); dir = opendir(filename); + if (!dir) + return -1; while ((de = readdir(dir)) != NULL) { int namelen = strlen(de->d_name); if (namelen != 50 || @@ -46,6 +48,7 @@ static int setup_indices(void) get_sha1_hex(de->d_name + 5, sha1); setup_index(sha1); } + closedir(dir); return 0; } From 1a951815ddaa4e4b570cc67e204f45e9a12841e0 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:28 +0400 Subject: [PATCH 07/11] [PATCH] git-local-fetch: Avoid calling close(-1) After open() failure, copy_file() called close(ifd) with ifd == -1 (harmless, but causes Valgrind noise). The same thing was possible for the destination file descriptor. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- local-fetch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/local-fetch.c b/local-fetch.c index b3947a9657..a3e35f9c81 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -75,7 +75,8 @@ static int copy_file(const char *source, const char *dest, const char *hex) void *map; ifd = open(source, O_RDONLY); if (ifd < 0 || fstat(ifd, &st) < 0) { - close(ifd); + if (ifd >= 0) + close(ifd); fprintf(stderr, "cannot open %s\n", source); return -1; } @@ -89,7 +90,8 @@ static int copy_file(const char *source, const char *dest, const char *hex) status = ((ofd < 0) || (write(ofd, map, st.st_size) != st.st_size)); munmap(map, st.st_size); - close(ofd); + if (ofd >= 0) + close(ofd); if (status) fprintf(stderr, "cannot write %s\n", dest); else From e2b77f026a251a47ebdf634107e76f7b457087af Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:33 +0400 Subject: [PATCH 08/11] [PATCH] Fix "git-local-fetch -s" with packed source repository "git-local-fetch -s" did not work with a packed repository, because symlink() happily created a link to a non-existing object file, therefore fetch_file() always returned success, and fetch_pack() was not called. Fixed by calling stat() before symlink() to ensure the file really exists. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- local-fetch.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/local-fetch.c b/local-fetch.c index a3e35f9c81..6216c68a4c 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -65,9 +65,17 @@ static int copy_file(const char *source, const char *dest, const char *hex) return -1; } } - if (use_symlink && !symlink(source, dest)) { - pull_say("symlink %s\n", hex); - return 0; + if (use_symlink) { + struct stat st; + if (stat(source, &st)) { + fprintf(stderr, "cannot stat %s: %s\n", source, + strerror(errno)); + return -1; + } + if (!symlink(source, dest)) { + pull_say("symlink %s\n", hex); + return 0; + } } if (use_filecopy) { int ifd, ofd, status; From 628cd5430fdf71a75c02af88ab7b557d29687db5 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 23 Sep 2005 16:28:38 +0400 Subject: [PATCH 09/11] [PATCH] git-local-fetch: Avoid confusing error messages on packed repositories If the source repository was packed, and git-local-fetch needed to fetch a pack file, it spewed a misleading error message about not being able to find the unpacked object. Fixed by adding the warn_if_not_exists argument to copy_file(), which controls printing of error messages in case the source file does not exist. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- local-fetch.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/local-fetch.c b/local-fetch.c index 6216c68a4c..0dbed8910b 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -52,7 +52,8 @@ static int setup_indices(void) return 0; } -static int copy_file(const char *source, const char *dest, const char *hex) +static int copy_file(const char *source, const char *dest, const char *hex, + int warn_if_not_exists) { if (use_link) { if (!link(source, dest)) { @@ -61,13 +62,16 @@ static int copy_file(const char *source, const char *dest, const char *hex) } /* If we got ENOENT there is no point continuing. */ if (errno == ENOENT) { - fprintf(stderr, "does not exist %s\n", source); + if (warn_if_not_exists) + fprintf(stderr, "does not exist %s\n", source); return -1; } } if (use_symlink) { struct stat st; if (stat(source, &st)) { + if (!warn_if_not_exists && errno == ENOENT) + return -1; fprintf(stderr, "cannot stat %s: %s\n", source, strerror(errno)); return -1; @@ -83,8 +87,11 @@ static int copy_file(const char *source, const char *dest, const char *hex) void *map; ifd = open(source, O_RDONLY); if (ifd < 0 || fstat(ifd, &st) < 0) { + int err = errno; if (ifd >= 0) close(ifd); + if (!warn_if_not_exists && err == ENOENT) + return -1; fprintf(stderr, "cannot open %s\n", source); return -1; } @@ -129,11 +136,11 @@ static int fetch_pack(const unsigned char *sha1) sprintf(filename, "%s/objects/pack/pack-%s.pack", path, sha1_to_hex(target->sha1)); copy_file(filename, sha1_pack_name(target->sha1), - sha1_to_hex(target->sha1)); + sha1_to_hex(target->sha1), 1); sprintf(filename, "%s/objects/pack/pack-%s.idx", path, sha1_to_hex(target->sha1)); copy_file(filename, sha1_pack_index_name(target->sha1), - sha1_to_hex(target->sha1)); + sha1_to_hex(target->sha1), 1); install_packed_git(target); return 0; } @@ -154,7 +161,7 @@ static int fetch_file(const unsigned char *sha1) filename[object_name_start+1] = hex[1]; filename[object_name_start+2] = '/'; strcpy(filename + object_name_start + 3, hex + 2); - return copy_file(filename, dest_filename, hex); + return copy_file(filename, dest_filename, hex, 0); } int fetch(unsigned char *sha1) From e433b071fed7dbdf91437b489e261b86288542d8 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 23 Sep 2005 16:30:50 -0700 Subject: [PATCH 10/11] [PATCH] rsh.c unterminated string The change I made to rsh.c would leave the string unterminated under certain conditions, which unfortunately always applied! This patch fixes this. For some reason this never bit on i386 or ppc, but bit me on x86-64. Fix situation where the buffer was not properly null-terminated. Signed-off-by: H. Peter Anvin Signed-off-by: Junio C Hamano --- rsh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rsh.c b/rsh.c index 1c636861dd..bad5cff2c2 100644 --- a/rsh.c +++ b/rsh.c @@ -53,6 +53,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote) char *p = *ptrp; int size = *sizep; int oc; + int err = 0; if ( quote ) { oc = shell_quote(p, size, str); @@ -62,15 +63,14 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote) } if ( oc >= size ) { - p[size-1] = '\0'; - *ptrp += size-1; - *sizep = 1; - return 1; /* Overflow, string unusable */ + err = 1; + oc = size-1; } *ptrp += oc; + **ptrp = '\0'; *sizep -= oc; - return 0; + return err; } int setup_connection(int *fd_in, int *fd_out, const char *remote_prog, From dc56bc034176d76ce95e9ba7636e3551d51dc897 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Sep 2005 18:43:53 -0700 Subject: [PATCH 11/11] Further clarify licensing status of compat/subprocess.py. PSF license explicitly states the files in Python distribution is compatible with GPL, and upstream clarified the licensing terms by shortening its file header. This version is a verbatim copy from release24-maint branch form Python CVS. Signed-off-by: Junio C Hamano --- compat/subprocess.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/compat/subprocess.py b/compat/subprocess.py index d115e87cc6..bbd26c7b0e 100644 --- a/compat/subprocess.py +++ b/compat/subprocess.py @@ -2,28 +2,12 @@ # # For more information about this module, see PEP 324. # -# Copyright (c) 2003-2004 by Peter Astrand +# This module should remain compatible with Python 2.2, see PEP 291. # -# By obtaining, using, and/or copying this software and/or its -# associated documentation, you agree that you have read, understood, -# and will comply with the following terms and conditions: +# Copyright (c) 2003-2005 by Peter Astrand # -# Permission to use, copy, modify, and distribute this software and -# its associated documentation for any purpose and without fee is -# hereby granted, provided that the above copyright notice appears in -# all copies, and that both that copyright notice and this permission -# notice appear in supporting documentation, and that the name of the -# author not be used in advertising or publicity pertaining to -# distribution of the software without specific, written prior -# permission. -# -# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR -# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# Licensed to PSF under a Contributor Agreement. +# See http://www.python.org/2.4/license for licensing details. r"""subprocess - Subprocesses with accessible I/O streams