Merge branch 'ag/rev-parse-all-exclude-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:23 +0000 (22:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:23 +0000 (22:37 +0900)
"git rev-parse --exclude=* --branches --branches" (i.e. first
saying "add only things that do not match '*' out of all branches"
and then adding all branches, without any exclusion this time")
worked as expected, but "--exclude=* --all --all" did not work the
same way, which has been fixed.

* ag/rev-parse-all-exclude-fix:
rev-parse: clear --exclude list after 'git rev-parse --all'

1  2 
builtin/rev-parse.c
t/t6018-rev-list-glob.sh
diff --combined builtin/rev-parse.c
index 455f62246d69ad0468ffde58e568732bd3339c63,f4847d3008767e25cb0ea427cebc37aeae072a44..10d4dab894e25a73d6a761205ce53c88019a4a8b
@@@ -14,7 -14,6 +14,7 @@@
  #include "revision.h"
  #include "split-index.h"
  #include "submodule.h"
 +#include "commit-reach.h"
  
  #define DO_REVS               1
  #define DO_NOREV      2
@@@ -160,7 -159,7 +160,7 @@@ static void show_rev(int type, const st
                }
        }
        else if (abbrev)
 -              show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
 +              show_with_type(type, find_unique_abbrev(oid, abbrev));
        else
                show_with_type(type, oid_to_hex(oid));
  }
@@@ -281,12 -280,8 +281,12 @@@ static int try_difference(const char *a
                if (symmetric) {
                        struct commit_list *exclude;
                        struct commit *a, *b;
 -                      a = lookup_commit_reference(&start_oid);
 -                      b = lookup_commit_reference(&end_oid);
 +                      a = lookup_commit_reference(the_repository, &start_oid);
 +                      b = lookup_commit_reference(the_repository, &end_oid);
 +                      if (!a || !b) {
 +                              *dotdot = '.';
 +                              return 0;
 +                      }
                        exclude = get_merge_bases(a, b);
                        while (exclude) {
                                struct commit *commit = pop_commit(&exclude);
@@@ -333,12 -328,12 +333,12 @@@ static int try_parent_shorthands(const 
                return 0;
  
        *dotdot = 0;
 -      if (get_oid_committish(arg, &oid)) {
 +      if (get_oid_committish(arg, &oid) ||
 +          !(commit = lookup_commit_reference(the_repository, &oid))) {
                *dotdot = '^';
                return 0;
        }
  
 -      commit = lookup_commit_reference(&oid);
        if (exclude_parent &&
            exclude_parent > commit_list_count(commit->parents)) {
                *dotdot = '^';
@@@ -765,6 -760,7 +765,7 @@@ int cmd_rev_parse(int argc, const char 
                        }
                        if (!strcmp(arg, "--all")) {
                                for_each_ref(show_reference, NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
                        if (skip_prefix(arg, "--disambiguate=", &arg)) {
                                continue;
                        }
                        if (!strcmp(arg, "--is-shallow-repository")) {
 -                              printf("%s\n", is_repository_shallow() ? "true"
 +                              printf("%s\n",
 +                                              is_repository_shallow(the_repository) ? "true"
                                                : "false");
                                continue;
                        }
                                if (read_cache() < 0)
                                        die(_("Could not read the index"));
                                if (the_index.split_index) {
 -                                      const unsigned char *sha1 = the_index.split_index->base_sha1;
 -                                      const char *path = git_path("sharedindex.%s", sha1_to_hex(sha1));
 +                                      const struct object_id *oid = &the_index.split_index->base_oid;
 +                                      const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
                                        strbuf_reset(&buf);
                                        puts(relative_path(path, prefix, &buf));
                                }
diff --combined t/t6018-rev-list-glob.sh
index db8a7834d88e6d01b3cc5106af749ede7b75866a,b28075b65d0e732cdd80da2e46818bc3ec6bb72b..270e579c2d3a30b2a08517bc63fe6edf5221af59
@@@ -141,6 -141,18 +141,18 @@@ test_expect_success 'rev-parse accumula
        compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
  '
  
+ test_expect_success 'rev-parse --branches clears --exclude' '
+       compare rev-parse "--exclude=* --branches --branches" "--branches"
+ '
+ test_expect_success 'rev-parse --tags clears --exclude' '
+       compare rev-parse "--exclude=* --tags --tags" "--tags"
+ '
+ test_expect_success 'rev-parse --all clears --exclude' '
+       compare rev-parse "--exclude=* --all --all" "--all"
+ '
  test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
  
        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
@@@ -255,28 -267,32 +267,28 @@@ test_expect_success 'rev-list accumulat
        compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
  '
  
 -test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
 -      >expect &&
 -      git rev-list --stdin <expect >actual &&
 -      test_cmp expect actual
 +test_expect_success 'rev-list should succeed with empty output on empty stdin' '
 +      git rev-list --stdin </dev/null >actual &&
 +      test_must_be_empty actual
  '
  
  test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
 -      >expect &&
        git rev-list --exclude=* --all >actual &&
 -      test_cmp expect actual
 +      test_must_be_empty actual
  '
  
  test_expect_success 'rev-list should succeed with empty output with empty --all' '
        (
                test_create_repo empty &&
                cd empty &&
 -              >expect &&
                git rev-list --all >actual &&
 -              test_cmp expect actual
 +              test_must_be_empty actual
        )
  '
  
  test_expect_success 'rev-list should succeed with empty output with empty glob' '
 -      >expect &&
        git rev-list --glob=does-not-match-anything >actual &&
 -      test_cmp expect actual
 +      test_must_be_empty actual
  '
  
  test_expect_success 'shortlog accepts --glob/--tags/--remotes' '