Merge branch 'jt/namespaced-ls-refs-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
Fix namespace support in protocol v2.

* jt/namespaced-ls-refs-fix:
ls-refs: filter refs using namespace-stripped name

1  2 
ls-refs.c
t/t5702-protocol-v2.sh
diff --combined ls-refs.c
index 9c9a7c647f26249d68319786449eefd7d6de1eba,7782bb054b09ff34dc4784185d3eeff6de9c4621..0a7dbc6442fad37fd9e2ce72866b04b134818181
+++ b/ls-refs.c
@@@ -5,7 -5,6 +5,7 @@@
  #include "argv-array.h"
  #include "ls-refs.h"
  #include "pkt-line.h"
 +#include "config.h"
  
  /*
   * Check if one of the prefixes is a prefix of the ref.
@@@ -41,10 -40,7 +41,10 @@@ static int send_ref(const char *refname
        const char *refname_nons = strip_namespace(refname);
        struct strbuf refline = STRBUF_INIT;
  
-       if (!ref_match(&data->prefixes, refname))
 +      if (ref_is_hidden(refname_nons, refname))
 +              return 0;
 +
+       if (!ref_match(&data->prefixes, refname_nons))
                return 0;
  
        strbuf_addf(&refline, "%s %s", oid_to_hex(oid), refname_nons);
        return 0;
  }
  
 +static int ls_refs_config(const char *var, const char *value, void *data)
 +{
 +      /*
 +       * We only serve fetches over v2 for now, so respect only "uploadpack"
 +       * config. This may need to eventually be expanded to "receive", but we
 +       * don't yet know how that information will be passed to ls-refs.
 +       */
 +      return parse_hide_refs_config(var, value, "uploadpack");
 +}
 +
  int ls_refs(struct repository *r, struct argv_array *keys,
            struct packet_reader *request)
  {
@@@ -90,8 -76,6 +90,8 @@@
  
        memset(&data, 0, sizeof(data));
  
 +      git_config(ls_refs_config, NULL);
 +
        while (packet_reader_read(request) != PACKET_READ_FLUSH) {
                const char *arg = request->line;
                const char *out;
diff --combined t/t5702-protocol-v2.sh
index 7ca1aab6b58bf405cfaf585ddd06d8b02393fe24,3d802aa58763bce005a12c9e86ca9ac8d95984ce..db4ae09f2f81ff77b9c29b99c21363e66c81f222
@@@ -471,53 -471,6 +471,53 @@@ test_expect_success 'upload-pack respec
        grep "fetch< version 2" trace
  '
  
 +test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
 +      rm -rf server client trace &&
 +
 +      test_create_repo server &&
 +      test_commit -C server one &&
 +      test_commit -C server two &&
 +      test_commit -C server three &&
 +      git clone --shallow-exclude two "file://$(pwd)/server" client &&
 +
 +      git -C server tag -a -m "an annotated tag" twotag two &&
 +
 +      # Triggers tag following (thus, 2 fetches in one process)
 +      GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
 +              fetch --shallow-exclude one origin &&
 +      # Ensure that protocol v2 is used
 +      grep "fetch< version 2" trace
 +'
 +
 +test_expect_success 'deepen-relative' '
 +      rm -rf server client trace &&
 +
 +      test_create_repo server &&
 +      test_commit -C server one &&
 +      test_commit -C server two &&
 +      test_commit -C server three &&
 +      git clone --depth 1 "file://$(pwd)/server" client &&
 +      test_commit -C server four &&
 +
 +      # Sanity check that only "three" is downloaded
 +      git -C client log --pretty=tformat:%s master >actual &&
 +      echo three >expected &&
 +      test_cmp expected actual &&
 +
 +      GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
 +              fetch --deepen=1 origin &&
 +      # Ensure that protocol v2 is used
 +      grep "fetch< version 2" trace &&
 +
 +      git -C client log --pretty=tformat:%s origin/master >actual &&
 +      cat >expected <<-\EOF &&
 +      four
 +      three
 +      two
 +      EOF
 +      test_cmp expected actual
 +'
 +
  # Test protocol v2 with 'http://' transport
  #
  . "$TEST_DIRECTORY"/lib-httpd.sh
@@@ -561,6 -514,27 +561,27 @@@ test_expect_success 'fetch with http:/
        grep "git< version 2" log
  '
  
+ test_expect_success 'fetch from namespaced repo respects namespaces' '
+       test_when_finished "rm -f log" &&
+       git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
+               update-ref refs/namespaces/ns/refs/heads/master one &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
+               fetch "$HTTPD_URL/smart_namespace/nsrepo" \
+               refs/heads/master:refs/heads/theirs &&
+       # Server responded using protocol v2
+       grep "fetch< version 2" log &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
+       git -C http_child rev-parse theirs >actual &&
+       test_cmp expect actual
+ '
  test_expect_success 'push with http:// and a config of v2 does not request v2' '
        test_when_finished "rm -f log" &&
        # Till v2 for push is designed, make sure that if a client has
@@@ -630,8 -604,8 +651,8 @@@ test_expect_success 'when server does n
        test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
                -c protocol.version=2 \
                fetch "$HTTPD_URL/one_time_sed/http_parent" 2> err &&
 -      grep "fetch< acknowledgments" log &&
 -      ! grep "fetch< ready" log &&
 +      grep "fetch< .*acknowledgments" log &&
 +      ! grep "fetch< .*ready" log &&
        test_i18ngrep "expected no other sections to be sent after no .ready." err
  '