aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-04-26 18:32:45 -0700
committerJunio C Hamano <junkio@cox.net>2006-04-26 18:32:45 -0700
commite7afa1115beb071512ac2b8d6b7487eadbfccc74 (patch)
treee1473acf5c9da91c36ab64d8c941fe7bd632090e
parentb8ed7f0f40743dae6111c8950ba55051933298ca (diff)
parent9af0b8dbe2fb252262412a11254e2bcc6ffb87bb (diff)
downloadgit-e7afa1115beb071512ac2b8d6b7487eadbfccc74.tar.gz
git-e7afa1115beb071512ac2b8d6b7487eadbfccc74.tar.xz
Merge branch 'master' into jc/cache-tree
* master: t0000-basic: more commit-tree tests. commit-tree.c: check_valid() microoptimization. Fix filename verification when in a subdirectory rebase: typofix. socksetup: don't return on set_reuse_addr() error
-rw-r--r--cache.h1
-rw-r--r--commit-tree.c11
-rwxr-xr-xgit-rebase.sh2
-rw-r--r--rev-parse.c15
-rw-r--r--revision.c8
-rw-r--r--setup.c23
-rwxr-xr-xt/t0000-basic.sh28
7 files changed, 63 insertions, 25 deletions
diff --git a/cache.h b/cache.h
index a080727b0..00b8804da 100644
--- a/cache.h
+++ b/cache.h
@@ -135,6 +135,7 @@ extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
extern const char *prefix_path(const char *prefix, int len, const char *path);
extern const char *prefix_filename(const char *prefix, int len, const char *path);
+extern void verify_filename(const char *prefix, const char *name);
#define alloc_nr(x) (((x)+16)*3/2)
diff --git a/commit-tree.c b/commit-tree.c
index e91af4bd3..bad72e89e 100644
--- a/commit-tree.c
+++ b/commit-tree.c
@@ -45,14 +45,13 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
static void check_valid(unsigned char *sha1, const char *expect)
{
- void *buf;
char type[20];
- unsigned long size;
- buf = read_sha1_file(sha1, type, &size);
- if (!buf || strcmp(type, expect))
- die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect);
- free(buf);
+ if (sha1_object_info(sha1, type, NULL))
+ die("%s is not a valid object", sha1_to_hex(sha1));
+ if (expect && strcmp(type, expect))
+ die("%s is not a valid '%s' object", sha1_to_hex(sha1),
+ expect);
}
/*
diff --git a/git-rebase.sh b/git-rebase.sh
index 86dfe9cb9..f7b2b9401 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -107,7 +107,7 @@ onto=$(git-rev-parse --verify "${onto_name}^0") || exit
# Check if we are already based on $onto, but this should be
# done only when upstream and onto are the same.
-if test "$upstream" = "onto"
+if test "$upstream" = "$onto"
then
mb=$(git-merge-base "$onto" "$branch")
if test "$mb" = "$onto"
diff --git a/rev-parse.c b/rev-parse.c
index 7f66ae2db..62e16af33 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -160,14 +160,6 @@ static int show_file(const char *arg)
return 0;
}
-static void die_badfile(const char *arg)
-{
- if (errno != ENOENT)
- die("'%s': %s", arg, strerror(errno));
- die("'%s' is ambiguous - revision name or file/directory name?\n"
- "Please put '--' before the list of filenames.", arg);
-}
-
int main(int argc, char **argv)
{
int i, as_is = 0, verify = 0;
@@ -177,14 +169,12 @@ int main(int argc, char **argv)
git_config(git_default_config);
for (i = 1; i < argc; i++) {
- struct stat st;
char *arg = argv[i];
char *dotdot;
if (as_is) {
if (show_file(arg) && as_is < 2)
- if (lstat(arg, &st) < 0)
- die_badfile(arg);
+ verify_filename(prefix, arg);
continue;
}
if (!strcmp(arg,"-n")) {
@@ -350,8 +340,7 @@ int main(int argc, char **argv)
continue;
if (verify)
die("Needed a single revision");
- if (lstat(arg, &st) < 0)
- die_badfile(arg);
+ verify_filename(prefix, arg);
}
show_default();
if (verify && revs_count != 1)
diff --git a/revision.c b/revision.c
index f9c7d15f5..f2a9f25fe 100644
--- a/revision.c
+++ b/revision.c
@@ -752,17 +752,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
arg++;
}
if (get_sha1(arg, sha1) < 0) {
- struct stat st;
int j;
if (seen_dashdash || local_flags)
die("bad revision '%s'", arg);
/* If we didn't have a "--", all filenames must exist */
- for (j = i; j < argc; j++) {
- if (lstat(argv[j], &st) < 0)
- die("'%s': %s", argv[j], strerror(errno));
- }
+ for (j = i; j < argc; j++)
+ verify_filename(revs->prefix, argv[j]);
+
revs->prune_data = get_pathspec(revs->prefix, argv + i);
break;
}
diff --git a/setup.c b/setup.c
index 36ede3d87..cce9bb806 100644
--- a/setup.c
+++ b/setup.c
@@ -62,6 +62,29 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
return path;
}
+/*
+ * Verify a filename that we got as an argument for a pathspec
+ * entry. Note that a filename that begins with "-" never verifies
+ * as true, because even if such a filename were to exist, we want
+ * it to be preceded by the "--" marker (or we want the user to
+ * use a format like "./-filename")
+ */
+void verify_filename(const char *prefix, const char *arg)
+{
+ const char *name;
+ struct stat st;
+
+ if (*arg == '-')
+ die("bad flag '%s' used after filename", arg);
+ name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
+ if (!lstat(name, &st))
+ return;
+ if (errno == ENOENT)
+ die("ambiguous argument '%s': unknown revision or filename\n"
+ "Use '--' to separate filenames from revisions", arg);
+ die("'%s': %s", arg, strerror(errno));
+}
+
const char **get_pathspec(const char *prefix, const char **pathspec)
{
const char *entry = *pathspec;
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index c69706fb3..cf33989b5 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -226,4 +226,32 @@ test_expect_success \
'no diff after checkout and git-update-index --refresh.' \
'git-diff-files >current && cmp -s current /dev/null'
+################################################################
+P=087704a96baf1c2d1c869a8b084481e121c88b5b
+test_expect_success \
+ 'git-commit-tree records the correct tree in a commit.' \
+ 'commit0=$(echo NO | git-commit-tree $P) &&
+ tree=$(git show --pretty=raw $commit0 |
+ sed -n -e "s/^tree //p" -e "/^author /q") &&
+ test "z$tree" = "z$P"'
+
+test_expect_success \
+ 'git-commit-tree records the correct parent in a commit.' \
+ 'commit1=$(echo NO | git-commit-tree $P -p $commit0) &&
+ parent=$(git show --pretty=raw $commit1 |
+ sed -n -e "s/^parent //p" -e "/^author /q") &&
+ test "z$commit0" = "z$parent"'
+
+test_expect_success \
+ 'git-commit-tree omits duplicated parent in a commit.' \
+ 'commit2=$(echo NO | git-commit-tree $P -p $commit0 -p $commit0) &&
+ parent=$(git show --pretty=raw $commit2 |
+ sed -n -e "s/^parent //p" -e "/^author /q" |
+ sort -u) &&
+ test "z$commit0" = "z$parent" &&
+ numparent=$(git show --pretty=raw $commit2 |
+ sed -n -e "s/^parent //p" -e "/^author /q" |
+ wc -l) &&
+ test $numparent = 1'
+
test_done