Merge branch 'mm/diag-path-in-treeish'
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Jan 2010 16:52:10 +0000 (08:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Jan 2010 16:52:10 +0000 (08:52 -0800)
* mm/diag-path-in-treeish:
Detailed diagnosis when parsing an object name fails.

1  2 
setup.c
diff --combined setup.c
index 2cf0f1993718fd737cd87e79d2f4950832c59c9f,5792eb7ddfbe9a3e520dcf33081a6c098061d643..3a07aa4df710f5d9584d4ddf412e3debc0e64db4
+++ b/setup.c
@@@ -18,12 -18,9 +18,12 @@@ const char *prefix_path(const char *pre
        if (normalize_path_copy(sanitized, sanitized))
                goto error_out;
        if (is_absolute_path(orig)) {
 +              size_t len, total;
                const char *work_tree = get_git_work_tree();
 -              size_t len = strlen(work_tree);
 -              size_t total = strlen(sanitized) + 1;
 +              if (!work_tree)
 +                      goto error_out;
 +              len = strlen(work_tree);
 +              total = strlen(sanitized) + 1;
                if (strncmp(sanitized, work_tree, len) ||
                    (sanitized[len] != '\0' && sanitized[len] != '/')) {
                error_out:
@@@ -77,6 -74,18 +77,18 @@@ int check_filename(const char *prefix, 
        die_errno("failed to stat '%s'", arg);
  }
  
+ static void NORETURN die_verify_filename(const char *prefix, const char *arg)
+ {
+       unsigned char sha1[20];
+       unsigned mode;
+       /* try a detailed diagnostic ... */
+       get_sha1_with_mode_1(arg, sha1, &mode, 0, prefix);
+       /* ... or fall back the most general message. */
+       die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
+           "Use '--' to separate paths from revisions", arg);
+ }
  /*
   * Verify a filename that we got as an argument for a pathspec
   * entry. Note that a filename that begins with "-" never verifies
@@@ -90,8 -99,7 +102,7 @@@ void verify_filename(const char *prefix
                die("bad flag '%s' used after filename", arg);
        if (check_filename(prefix, arg))
                return;
-       die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
-           "Use '--' to separate paths from revisions", arg);
+       die_verify_filename(prefix, arg);
  }
  
  /*