Code

Merge branch 'xx/trivial' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 6 Sep 2010 07:11:59 +0000 (00:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Sep 2010 07:11:59 +0000 (00:11 -0700)
* xx/trivial:
  tag.c: whitespace breakages fix
  Fix whitespace issue in object.c
  t5505: add missing &&

1  2 
object.c
t/t5505-remote.sh
tag.c

diff --combined object.c
index 277b3ddba7dc5387cd97cb35c23d3358727898be,a23fbeaebb530fd434845182113d5a494589ebb1..2eda53cc6144430f5fcf4b93e80fac9b9e147bfd
+++ b/object.c
@@@ -211,12 -211,33 +211,12 @@@ struct object_list *object_list_insert(
                                       struct object_list **list_p)
  {
        struct object_list *new_list = xmalloc(sizeof(struct object_list));
-         new_list->item = item;
-         new_list->next = *list_p;
-         *list_p = new_list;
-         return new_list;
+       new_list->item = item;
+       new_list->next = *list_p;
+       *list_p = new_list;
+       return new_list;
  }
  
 -void object_list_append(struct object *item,
 -                      struct object_list **list_p)
 -{
 -      while (*list_p) {
 -              list_p = &((*list_p)->next);
 -      }
 -      *list_p = xmalloc(sizeof(struct object_list));
 -      (*list_p)->next = NULL;
 -      (*list_p)->item = item;
 -}
 -
 -unsigned object_list_length(struct object_list *list)
 -{
 -      unsigned ret = 0;
 -      while (list) {
 -              list = list->next;
 -              ret++;
 -      }
 -      return ret;
 -}
 -
  int object_list_contains(struct object_list *list, struct object *obj)
  {
        while (list) {
@@@ -252,10 -273,10 +252,10 @@@ void add_object_array_with_mode(struct 
  
  void object_array_remove_duplicates(struct object_array *array)
  {
 -      int ref, src, dst;
 +      unsigned int ref, src, dst;
        struct object_array_entry *objects = array->objects;
  
 -      for (ref = 0; ref < array->nr - 1; ref++) {
 +      for (ref = 0; ref + 1 < array->nr; ref++) {
                for (src = ref + 1, dst = src;
                     src < array->nr;
                     src++) {
diff --combined t/t5505-remote.sh
index 4c498b1902e4b0c74ea8d6bfc039d583bcc4364e,4b6befe7237c23c0f335c222bfc33810d5be2717..5d1c66ea7166b0b4d631b681f344e0eefb84d899
@@@ -110,18 -110,17 +110,18 @@@ test_expect_success 'remove remote' 
  test_expect_success 'remove remote protects non-remote branches' '
  (
        cd test &&
 -      (cat >expect1 <<EOF
 +      cat >expect1 <<EOF
  Note: A non-remote branch was not removed; to delete it, use:
    git branch -d master
  EOF
 -    cat >expect2 <<EOF
 +      } &&
 +      { cat >expect2 <<EOF
  Note: Non-remote branches were not removed; to delete them, use:
    git branch -d foobranch
    git branch -d master
  EOF
 -) &&
 -      git tag footag
 +      } &&
 +      git tag footag &&
        git config --add remote.oops.fetch "+refs/*:refs/*" &&
        git remote rm oops 2>actual1 &&
        git branch foobranch &&
@@@ -320,69 -319,6 +320,69 @@@ test_expect_success 'add alt && prune' 
         git rev-parse --verify refs/remotes/origin/side2)
  '
  
 +cat >test/expect <<\EOF
 +some-tag
 +EOF
 +
 +test_expect_success 'add with reachable tags (default)' '
 +      (cd one &&
 +       >foobar &&
 +       git add foobar &&
 +       git commit -m "Foobar" &&
 +       git tag -a -m "Foobar tag" foobar-tag &&
 +       git reset --hard HEAD~1 &&
 +       git tag -a -m "Some tag" some-tag) &&
 +      (mkdir add-tags &&
 +       cd add-tags &&
 +       git init &&
 +       git remote add -f origin ../one &&
 +       git tag -l some-tag >../test/output &&
 +       git tag -l foobar-tag >>../test/output &&
 +       test_must_fail git config remote.origin.tagopt) &&
 +      test_cmp test/expect test/output
 +'
 +
 +cat >test/expect <<\EOF
 +some-tag
 +foobar-tag
 +--tags
 +EOF
 +
 +test_expect_success 'add --tags' '
 +      (rm -rf add-tags &&
 +       mkdir add-tags &&
 +       cd add-tags &&
 +       git init &&
 +       git remote add -f --tags origin ../one &&
 +       git tag -l some-tag >../test/output &&
 +       git tag -l foobar-tag >>../test/output &&
 +       git config remote.origin.tagopt >>../test/output) &&
 +      test_cmp test/expect test/output
 +'
 +
 +cat >test/expect <<\EOF
 +--no-tags
 +EOF
 +
 +test_expect_success 'add --no-tags' '
 +      (rm -rf add-tags &&
 +       mkdir add-no-tags &&
 +       cd add-no-tags &&
 +       git init &&
 +       git remote add -f --no-tags origin ../one &&
 +       git tag -l some-tag >../test/output &&
 +       git tag -l foobar-tag >../test/output &&
 +       git config remote.origin.tagopt >>../test/output) &&
 +      (cd one &&
 +       git tag -d some-tag foobar-tag) &&
 +      test_cmp test/expect test/output
 +'
 +
 +test_expect_success 'reject --no-no-tags' '
 +      (cd add-no-tags &&
 +       test_must_fail git remote add -f --no-no-tags neworigin ../one)
 +'
 +
  cat > one/expect << EOF
    apis/master
    apis/side
@@@ -435,7 -371,7 +435,7 @@@ test_expect_success 'update --prune' 
         git branch -m side2 side3) &&
        (cd test &&
         git remote update --prune &&
-        (cd ../one && git branch -m side3 side2)
+        (cd ../one && git branch -m side3 side2) &&
         git rev-parse refs/remotes/origin/side3 &&
         test_must_fail git rev-parse refs/remotes/origin/side2)
  '
@@@ -571,15 -507,15 +571,15 @@@ test_expect_success 'remote prune to ca
        (
                cd seven &&
                git remote prune origin
 -      ) 2>err &&
 +      ) >err 2>&1 &&
        grep "has become dangling" err &&
  
 -      : And the dangling symref will not cause other annoying errors
 +      : And the dangling symref will not cause other annoying errors &&
        (
                cd seven &&
                git branch -a
        ) 2>err &&
 -      ! grep "points nowhere" err
 +      ! grep "points nowhere" err &&
        (
                cd seven &&
                test_must_fail git branch nomore origin
@@@ -597,271 -533,5 +597,271 @@@ test_expect_success 'show empty remote
        )
  '
  
 -test_done
 +test_expect_success 'remote set-branches requires a remote' '
 +      test_must_fail git remote set-branches &&
 +      test_must_fail git remote set-branches --add
 +'
 +
 +test_expect_success 'remote set-branches' '
 +      echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
 +      sort <<-\EOF >expect.add &&
 +      +refs/heads/*:refs/remotes/scratch/*
 +      +refs/heads/other:refs/remotes/scratch/other
 +      EOF
 +      sort <<-\EOF >expect.replace &&
 +      +refs/heads/maint:refs/remotes/scratch/maint
 +      +refs/heads/master:refs/remotes/scratch/master
 +      +refs/heads/next:refs/remotes/scratch/next
 +      EOF
 +      sort <<-\EOF >expect.add-two &&
 +      +refs/heads/maint:refs/remotes/scratch/maint
 +      +refs/heads/master:refs/remotes/scratch/master
 +      +refs/heads/next:refs/remotes/scratch/next
 +      +refs/heads/pu:refs/remotes/scratch/pu
 +      +refs/heads/t/topic:refs/remotes/scratch/t/topic
 +      EOF
 +      sort <<-\EOF >expect.setup-ffonly &&
 +      refs/heads/master:refs/remotes/scratch/master
 +      +refs/heads/next:refs/remotes/scratch/next
 +      EOF
 +      sort <<-\EOF >expect.respect-ffonly &&
 +      refs/heads/master:refs/remotes/scratch/master
 +      +refs/heads/next:refs/remotes/scratch/next
 +      +refs/heads/pu:refs/remotes/scratch/pu
 +      EOF
 +
 +      git clone .git/ setbranches &&
 +      (
 +              cd setbranches &&
 +              git remote rename origin scratch &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.initial &&
 +
 +              git remote set-branches scratch --add other &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.add &&
 +
 +              git remote set-branches scratch maint master next &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.replace &&
 +
 +              git remote set-branches --add scratch pu t/topic &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.add-two &&
 +
 +              git config --unset-all remote.scratch.fetch &&
 +              git config remote.scratch.fetch \
 +                      refs/heads/master:refs/remotes/scratch/master &&
 +              git config --add remote.scratch.fetch \
 +                      +refs/heads/next:refs/remotes/scratch/next &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.setup-ffonly &&
 +
 +              git remote set-branches --add scratch pu &&
 +              git config --get-all remote.scratch.fetch >config-result &&
 +              sort <config-result >../actual.respect-ffonly
 +      ) &&
 +      test_cmp expect.initial actual.initial &&
 +      test_cmp expect.add actual.add &&
 +      test_cmp expect.replace actual.replace &&
 +      test_cmp expect.add-two actual.add-two &&
 +      test_cmp expect.setup-ffonly actual.setup-ffonly &&
 +      test_cmp expect.respect-ffonly actual.respect-ffonly
 +'
  
 +test_expect_success 'remote set-branches with --mirror' '
 +      echo "+refs/*:refs/*" >expect.initial &&
 +      echo "+refs/heads/master:refs/heads/master" >expect.replace &&
 +      git clone --mirror .git/ setbranches-mirror &&
 +      (
 +              cd setbranches-mirror &&
 +              git remote rename origin scratch &&
 +              git config --get-all remote.scratch.fetch >../actual.initial &&
 +
 +              git remote set-branches scratch heads/master &&
 +              git config --get-all remote.scratch.fetch >../actual.replace
 +      ) &&
 +      test_cmp expect.initial actual.initial &&
 +      test_cmp expect.replace actual.replace
 +'
 +
 +test_expect_success 'new remote' '
 +      git remote add someremote foo &&
 +      echo foo >expect &&
 +      git config --get-all remote.someremote.url >actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url bar' '
 +      git remote set-url someremote bar &&
 +      echo bar >expect &&
 +      git config --get-all remote.someremote.url >actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url baz bar' '
 +      git remote set-url someremote baz bar &&
 +      echo baz >expect &&
 +      git config --get-all remote.someremote.url >actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url zot bar' '
 +      test_must_fail git remote set-url someremote zot bar &&
 +      echo baz >expect &&
 +      git config --get-all remote.someremote.url >actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push zot baz' '
 +      test_must_fail git remote set-url --push someremote zot baz &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push zot' '
 +      git remote set-url --push someremote zot &&
 +      echo zot >expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push qux zot' '
 +      git remote set-url --push someremote qux zot &&
 +      echo qux >expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push foo qu+x' '
 +      git remote set-url --push someremote foo qu+x &&
 +      echo foo >expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push --add aaa' '
 +      git remote set-url --push --add someremote aaa &&
 +      echo foo >expect &&
 +      echo aaa >>expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push bar aaa' '
 +      git remote set-url --push someremote bar aaa &&
 +      echo foo >expect &&
 +      echo bar >>expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push --delete bar' '
 +      git remote set-url --push --delete someremote bar &&
 +      echo foo >expect &&
 +      echo "YYY" >>expect &&
 +      echo baz >>expect &&
 +      git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --push --delete foo' '
 +      git remote set-url --push --delete someremote foo &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --add bbb' '
 +      git remote set-url --add someremote bbb &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      echo bbb >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --delete .*' '
 +      test_must_fail git remote set-url --delete someremote .\* &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      echo bbb >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --delete bbb' '
 +      git remote set-url --delete someremote bbb &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --delete baz' '
 +      test_must_fail git remote set-url --delete someremote baz &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --add ccc' '
 +      git remote set-url --add someremote ccc &&
 +      echo "YYY" >expect &&
 +      echo baz >>expect &&
 +      echo ccc >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_expect_success 'remote set-url --delete baz' '
 +      git remote set-url --delete someremote baz &&
 +      echo "YYY" >expect &&
 +      echo ccc >>expect &&
 +      test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 +      echo "YYY" >>actual &&
 +      git config --get-all remote.someremote.url >>actual &&
 +      cmp expect actual
 +'
 +
 +test_done
diff --combined tag.c
index 85607c219e25d63b0d1f3344649104c60f5b96e2,f2dd1d0e03c28bc7c73639b4d62bb2ba951648f1..28641cf85a0d32357269129f0e8b92bb9e21f399
--- 1/tag.c
--- 2/tag.c
+++ b/tag.c
@@@ -28,38 -28,21 +28,38 @@@ struct tag *lookup_tag(const unsigned c
                return create_object(sha1, OBJ_TAG, alloc_tag_node());
        if (!obj->type)
                obj->type = OBJ_TAG;
-         if (obj->type != OBJ_TAG) {
-                 error("Object %s is a %s, not a tag",
-                       sha1_to_hex(sha1), typename(obj->type));
-                 return NULL;
-         }
-         return (struct tag *) obj;
+       if (obj->type != OBJ_TAG) {
+               error("Object %s is a %s, not a tag",
+                     sha1_to_hex(sha1), typename(obj->type));
+               return NULL;
+       }
+       return (struct tag *) obj;
  }
  
 +static unsigned long parse_tag_date(const char *buf, const char *tail)
 +{
 +      const char *dateptr;
 +
 +      while (buf < tail && *buf++ != '>')
 +              /* nada */;
 +      if (buf >= tail)
 +              return 0;
 +      dateptr = buf;
 +      while (buf < tail && *buf++ != '\n')
 +              /* nada */;
 +      if (buf >= tail)
 +              return 0;
 +      /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
 +      return strtoul(dateptr, NULL, 10);
 +}
 +
  int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
  {
 -      int typelen, taglen;
        unsigned char sha1[20];
 -      const char *type_line, *tag_line, *sig_line;
        char type[20];
 -      const char *start = data;
 +      const char *bufptr = data;
 +      const char *tail = bufptr + size;
 +      const char *nl;
  
        if (item->object.parsed)
                return 0;
  
        if (size < 64)
                return -1;
 -      if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, sha1))
 +      if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n')
                return -1;
 +      bufptr += 48; /* "object " + sha1 + "\n" */
  
 -      type_line = (char *) data + 48;
 -      if (memcmp("\ntype ", type_line-1, 6))
 +      if (prefixcmp(bufptr, "type "))
                return -1;
 -
 -      tag_line = memchr(type_line, '\n', size - (type_line - start));
 -      if (!tag_line || memcmp("tag ", ++tag_line, 4))
 +      bufptr += 5;
 +      nl = memchr(bufptr, '\n', tail - bufptr);
 +      if (!nl || sizeof(type) <= (nl - bufptr))
                return -1;
 -
 -      sig_line = memchr(tag_line, '\n', size - (tag_line - start));
 -      if (!sig_line)
 -              return -1;
 -      sig_line++;
 -
 -      typelen = tag_line - type_line - strlen("type \n");
 -      if (typelen >= 20)
 -              return -1;
 -      memcpy(type, type_line + 5, typelen);
 -      type[typelen] = '\0';
 -      taglen = sig_line - tag_line - strlen("tag \n");
 -      item->tag = xmemdupz(tag_line + 4, taglen);
 +      strncpy(type, bufptr, nl - bufptr);
 +      type[nl - bufptr] = '\0';
 +      bufptr = nl + 1;
  
        if (!strcmp(type, blob_type)) {
                item->tagged = &lookup_blob(sha1)->object;
                item->tagged = NULL;
        }
  
 +      if (prefixcmp(bufptr, "tag "))
 +              return -1;
 +      bufptr += 4;
 +      nl = memchr(bufptr, '\n', tail - bufptr);
 +      if (!nl)
 +              return -1;
 +      item->tag = xmemdupz(bufptr, nl - bufptr);
 +      bufptr = nl + 1;
 +
 +      if (!prefixcmp(bufptr, "tagger "))
 +              item->date = parse_tag_date(bufptr, tail);
 +      else
 +              item->date = 0;
 +
        return 0;
  }