From: Shawn O. Pearce Date: Fri, 19 Oct 2007 05:18:55 +0000 (-0400) Subject: Merge branch 'maint' X-Git-Tag: v1.5.4-rc0~338 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f5bf6feb05b8c89c448ded6e6fad0eb58ef35463?ds=inline;hp=-c Merge branch 'maint' * maint: Further 1.5.3.5 fixes described in release notes Avoid invoking diff drivers during git-stash attr: fix segfault in gitattributes parsing code Define NI_MAXSERV if not defined by operating system Ensure we add directories in the correct order Avoid scary errors about tagged trees/blobs during git-fetch --- f5bf6feb05b8c89c448ded6e6fad0eb58ef35463 diff --combined attr.c index 92704a3f61,6e82507be7..741db3b468 --- a/attr.c +++ b/attr.c @@@ -160,7 -160,12 +160,7 @@@ static const char *parse_attr(const cha else if (!equals) e->setto = ATTR__TRUE; else { - char *value; - int vallen = ep - equals; - value = xmalloc(vallen); - memcpy(value, equals+1, vallen-1); - value[vallen-1] = 0; - e->setto = value; + e->setto = xmemdupz(equals + 1, ep - equals - 1); } e->attr = git_attr(cp, len); } @@@ -209,8 -214,11 +209,11 @@@ static struct match_attr *parse_attr_li num_attr = 0; cp = name + namelen; cp = cp + strspn(cp, blank); - while (*cp) + while (*cp) { cp = parse_attr(src, lineno, cp, &num_attr, res); + if (!cp) + return NULL; + } if (pass) break; res = xcalloc(1, diff --combined builtin-fetch--tool.c index 1e43d79221,db133348a8..e26817de21 --- a/builtin-fetch--tool.c +++ b/builtin-fetch--tool.c @@@ -3,14 -3,26 +3,14 @@@ #include "refs.h" #include "commit.h" -#define CHUNK_SIZE 1024 - static char *get_stdin(void) { - size_t offset = 0; - char *data = xmalloc(CHUNK_SIZE); - - while (1) { - ssize_t cnt = xread(0, data + offset, CHUNK_SIZE); - if (cnt < 0) - die("error reading standard input: %s", - strerror(errno)); - if (cnt == 0) { - data[offset] = 0; - break; - } - offset += cnt; - data = xrealloc(data, offset + CHUNK_SIZE); + struct strbuf buf; + strbuf_init(&buf, 0); + if (strbuf_read(&buf, 0, 1024) < 0) { + die("error reading standard input: %s", strerror(errno)); } - return data; + return strbuf_detach(&buf, NULL); } static void show_new(enum object_type type, unsigned char *sha1_new) @@@ -19,19 -31,24 +19,19 @@@ find_unique_abbrev(sha1_new, DEFAULT_ABBREV)); } -static int update_ref(const char *action, +static int update_ref_env(const char *action, const char *refname, unsigned char *sha1, unsigned char *oldval) { char msg[1024]; char *rla = getenv("GIT_REFLOG_ACTION"); - static struct ref_lock *lock; if (!rla) rla = "(reflog update)"; - snprintf(msg, sizeof(msg), "%s: %s", rla, action); - lock = lock_any_ref_for_update(refname, oldval, 0); - if (!lock) - return 1; - if (write_ref_sha1(lock, sha1, msg) < 0) - return 1; - return 0; + if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg)) + warning("reflog message too long: %.*s...", 50, msg); + return update_ref(msg, refname, sha1, oldval, 0, QUIET_ON_ERR); } static int update_local_ref(const char *name, @@@ -71,7 -88,7 +71,7 @@@ fprintf(stderr, "* %s: storing %s\n", name, note); show_new(type, sha1_new); - return update_ref(msg, name, sha1_new, NULL); + return update_ref_env(msg, name, sha1_new, NULL); } if (!hashcmp(sha1_old, sha1_new)) { @@@ -85,7 -102,7 +85,7 @@@ if (!strncmp(name, "refs/tags/", 10)) { fprintf(stderr, "* %s: updating with %s\n", name, note); show_new(type, sha1_new); - return update_ref("updating tag", name, sha1_new, NULL); + return update_ref_env("updating tag", name, sha1_new, NULL); } current = lookup_commit_reference(sha1_old); @@@ -100,7 -117,7 +100,7 @@@ fprintf(stderr, "* %s: fast forward to %s\n", name, note); fprintf(stderr, " old..new: %s..%s\n", oldh, newh); - return update_ref("fast forward", name, sha1_new, sha1_old); + return update_ref_env("fast forward", name, sha1_new, sha1_old); } if (!force) { fprintf(stderr, @@@ -114,7 -131,7 +114,7 @@@ "* %s: forcing update to non-fast forward %s\n", name, note); fprintf(stderr, " old...new: %s...%s\n", oldh, newh); - return update_ref("forced-update", name, sha1_new, sha1_old); + return update_ref_env("forced-update", name, sha1_new, sha1_old); } static int append_fetch_head(FILE *fp, @@@ -131,7 -148,7 +131,7 @@@ if (get_sha1(head, sha1)) return error("Not a valid object name: %s", head); - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference_gently(sha1, 1); if (!commit) not_for_merge = 1; @@@ -222,15 -239,19 +222,15 @@@ static char *find_local_name(const cha } if (!strncmp(remote_name, ref, len) && ref[len] == ':') { const char *local_part = ref + len + 1; - char *ret; int retlen; if (!next) retlen = strlen(local_part); else retlen = next - local_part; - ret = xmalloc(retlen + 1); - memcpy(ret, local_part, retlen); - ret[retlen] = 0; *force_p = single_force; *not_for_merge_p = not_for_merge; - return ret; + return xmemdupz(local_part, retlen); } ref = next; } diff --combined git-cvsexportcommit.perl index 7a955d4530,7b19a33ad1..f284c88a46 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@@ -30,6 -30,11 +30,6 @@@ if ($opt_d) @cvs = ('cvs'); } -# setup a tempdir -our ($tmpdir, $tmpdirname) = tempdir('git-cvsapplycommit-XXXXXX', - TMPDIR => 1, - CLEANUP => 1); - # resolve target commit my $commit; $commit = pop @ARGV; @@@ -129,7 -134,7 +129,7 @@@ my $context = $opt_p ? '' : '-C1' print "Checking if patch will apply\n"; my @stat; -open APPLY, "GIT_DIR= git-apply $context --binary --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch"; +open APPLY, "GIT_DIR= git-apply $context --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch"; @stat=; close APPLY || die "Cannot patch"; my (@bfiles,@files,@afiles,@dfiles); @@@ -215,10 -220,21 +215,21 @@@ if ($dirty) } print "Applying\n"; -`GIT_DIR= git-apply $context --binary --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch"; +`GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch"; print "Patch applied successfully. Adding new files and directories to CVS\n"; my $dirtypatch = 0; + + # + # We have to add the directories in order otherwise we will have + # problems when we try and add the sub-directory of a directory we + # have not added yet. + # + # Luckily this is easy to deal with by sorting the directories and + # dealing with the shortest ones first. + # + @dirs = sort { length $a <=> length $b} @dirs; + foreach my $d (@dirs) { if (system(@cvs,'add',$d)) { $dirtypatch = 1;