]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/mailmap-incomplete-line' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2013 18:57:32 +0000 (11:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2013 18:57:33 +0000 (11:57 -0700)
* jk/mailmap-incomplete-line:
  mailmap: handle mailmap blobs without trailing newlines

1  2 
mailmap.c
t/t4203-mailmap.sh

diff --combined mailmap.c
index 44614fc411fa7948d710c07a0262454aa0e76d0b,d2f28b0f35f497510498252130438fc3127e9f7f..30614343213442806c5fbc28e904639d35c670cf
+++ b/mailmap.c
@@@ -5,10 -5,8 +5,10 @@@
  #define DEBUG_MAILMAP 0
  #if DEBUG_MAILMAP
  #define debug_mm(...) fprintf(stderr, __VA_ARGS__)
 +#define debug_str(X) ((X) ? (X) : "(none)")
  #else
  static inline void debug_mm(const char *format, ...) {}
 +static inline const char *debug_str(const char *s) { return s; }
  #endif
  
  const char *git_mailmap_file;
@@@ -31,8 -29,7 +31,8 @@@ struct mailmap_entry 
  static void free_mailmap_info(void *p, const char *s)
  {
        struct mailmap_info *mi = (struct mailmap_info *)p;
 -      debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, mi->name, mi->email);
 +      debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n",
 +               s, debug_str(mi->name), debug_str(mi->email));
        free(mi->name);
        free(mi->email);
  }
  static void free_mailmap_entry(void *p, const char *s)
  {
        struct mailmap_entry *me = (struct mailmap_entry *)p;
 -      debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n", s, me->namemap.nr);
 -      debug_mm("mailmap: - simple: '%s' <%s>\n", me->name, me->email);
 +      debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n",
 +               s, me->namemap.nr);
 +      debug_mm("mailmap: - simple: '%s' <%s>\n",
 +               debug_str(me->name), debug_str(me->email));
 +
        free(me->name);
        free(me->email);
  
  }
  
  static void add_mapping(struct string_list *map,
 -                      char *new_name, char *new_email, char *old_name, char *old_email)
 +                      char *new_name, char *new_email,
 +                      char *old_name, char *old_email)
  {
        struct mailmap_entry *me;
        int index;
 -      char *p;
 -
 -      if (old_email)
 -              for (p = old_email; *p; p++)
 -                      *p = tolower(*p);
 -      if (new_email)
 -              for (p = new_email; *p; p++)
 -                      *p = tolower(*p);
  
        if (old_email == NULL) {
                old_email = new_email;
        if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) {
                /* mailmap entry exists, invert index value */
                index = -1 - index;
 +              me = (struct mailmap_entry *)map->items[index].util;
        } else {
                /* create mailmap entry */
 -              struct string_list_item *item = string_list_insert_at_index(map, index, old_email);
 -              item->util = xcalloc(1, sizeof(struct mailmap_entry));
 -              ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;
 +              struct string_list_item *item;
 +
 +              item = string_list_insert_at_index(map, index, old_email);
 +              me = xcalloc(1, sizeof(struct mailmap_entry));
 +              me->namemap.strdup_strings = 1;
 +              me->namemap.cmp = strcasecmp;
 +              item->util = me;
        }
 -      me = (struct mailmap_entry *)map->items[index].util;
  
        if (old_name == NULL) {
 -              debug_mm("mailmap: adding (simple) entry for %s at index %d\n", old_email, index);
 +              debug_mm("mailmap: adding (simple) entry for %s at index %d\n",
 +                       old_email, index);
                /* Replace current name and new email for simple entry */
                if (new_name) {
                        free(me->name);
@@@ -93,8 -89,7 +93,8 @@@
                }
        } else {
                struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
 -              debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index);
 +              debug_mm("mailmap: adding (complex) entry for %s at index %d\n",
 +                       old_email, index);
                if (new_name)
                        mi->name = xstrdup(new_name);
                if (new_email)
        }
  
        debug_mm("mailmap:  '%s' <%s> -> '%s' <%s>\n",
 -               old_name, old_email, new_name, new_email);
 +               debug_str(old_name), old_email,
 +               debug_str(new_name), debug_str(new_email));
  }
  
  static char *parse_name_and_email(char *buffer, char **name,
 -              char **email, int allow_empty_email)
 +                                char **email, int allow_empty_email)
  {
        char *left, *right, *nstart, *nend;
        *name = *email = NULL;
        while (nend > nstart && isspace(*nend))
                --nend;
  
 -      *name = (nstart < nend ? nstart : NULL);
 +      *name = (nstart <= nend ? nstart : NULL);
        *email = left+1;
        *(nend+1) = '\0';
        *right++ = '\0';
@@@ -193,20 -187,17 +193,17 @@@ static int read_mailmap_file(struct str
        return 0;
  }
  
- static void read_mailmap_buf(struct string_list *map,
-                            const char *buf, unsigned long len,
-                            char **repo_abbrev)
+ static void read_mailmap_string(struct string_list *map, char *buf,
+                               char **repo_abbrev)
  {
-       while (len) {
-               const char *end = strchrnul(buf, '\n');
-               unsigned long linelen = end - buf + 1;
-               char *line = xmemdupz(buf, linelen);
+       while (*buf) {
+               char *end = strchrnul(buf, '\n');
  
-               read_mailmap_line(map, line, repo_abbrev);
+               if (*end)
+                       *end++ = '\0';
  
-               free(line);
-               buf += linelen;
-               len -= linelen;
+               read_mailmap_line(map, buf, repo_abbrev);
+               buf = end;
        }
  }
  
@@@ -230,7 -221,7 +227,7 @@@ static int read_mailmap_blob(struct str
        if (type != OBJ_BLOB)
                return error("mailmap is not a blob: %s", name);
  
-       read_mailmap_buf(map, buf, size, repo_abbrev);
+       read_mailmap_string(map, buf, repo_abbrev);
  
        free(buf);
        return 0;
@@@ -312,25 -303,21 +309,25 @@@ static struct string_list_item *lookup_
  }
  
  int map_user(struct string_list *map,
 -                       const char **email, size_t *emaillen,
 -                       const char **name, size_t *namelen)
 +           const char **email, size_t *emaillen,
 +           const char **name, size_t *namelen)
  {
        struct string_list_item *item;
        struct mailmap_entry *me;
  
        debug_mm("map_user: map '%.*s' <%.*s>\n",
 -               *name, *namelen, *emaillen, *email);
 +               (int)*namelen, debug_str(*name),
 +               (int)*emaillen, debug_str(*email));
  
        item = lookup_prefix(map, *email, *emaillen);
        if (item != NULL) {
                me = (struct mailmap_entry *)item->util;
                if (me->namemap.nr) {
 -                      /* The item has multiple items, so we'll look up on name too */
 -                      /* If the name is not found, we choose the simple entry      */
 +                      /*
 +                       * The item has multiple items, so we'll look up on
 +                       * name too. If the name is not found, we choose the
 +                       * simple entry.
 +                       */
                        struct string_list_item *subitem;
                        subitem = lookup_prefix(&me->namemap, *name, *namelen);
                        if (subitem)
                                *name = mi->name;
                                *namelen = strlen(*name);
                }
 -              debug_mm("map_user:  to '%.*s' <.*%s>\n", *namelen, *name,
 -                               *emaillen, *email);
 +              debug_mm("map_user:  to '%.*s' <%.*s>\n",
 +                       (int)*namelen, debug_str(*name),
 +                       (int)*emaillen, debug_str(*email));
                return 1;
        }
        debug_mm("map_user:  --\n");
diff --combined t/t4203-mailmap.sh
index baa4685dcce59f17223161706a8cf059ecdabcd1,d5a8ff3f882be670099b382f85cc3bce2eb57fba..ce3eace065be81612e1ab2f994909b9352d5a06c
@@@ -13,11 -13,6 +13,11 @@@ fuzz_blame () 
  }
  
  test_expect_success setup '
 +      cat >contacts <<-\EOF &&
 +      A U Thor <author@example.com>
 +      nick1 <bugs@company.xx>
 +      EOF
 +
        echo one >one &&
        git add one &&
        test_tick &&
        git commit --author "nick1 <bugs@company.xx>" -m second
  '
  
 +test_expect_success 'check-mailmap no arguments' '
 +      test_must_fail git check-mailmap
 +'
 +
 +test_expect_success 'check-mailmap arguments' '
 +      cat >expect <<-\EOF &&
 +      A U Thor <author@example.com>
 +      nick1 <bugs@company.xx>
 +      EOF
 +      git check-mailmap \
 +              "A U Thor <author@example.com>" \
 +              "nick1 <bugs@company.xx>" >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'check-mailmap --stdin' '
 +      cat >expect <<-\EOF &&
 +      A U Thor <author@example.com>
 +      nick1 <bugs@company.xx>
 +      EOF
 +      git check-mailmap --stdin <contacts >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'check-mailmap --stdin arguments' '
 +      cat >expect <<-\EOF &&
 +      Internal Guy <bugs@company.xy>
 +      EOF
 +      cat <contacts >>expect &&
 +      git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
 +              <contacts >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'check-mailmap bogus contact' '
 +      test_must_fail git check-mailmap bogus
 +'
 +
  cat >expect <<\EOF
  A U Thor (1):
        initial
@@@ -202,7 -159,8 +202,8 @@@ test_expect_success 'setup mailmap blo
        Blob Guy <author@example.com>
        Blob Guy <bugs@company.xx>
        EOF
-       git add just-bugs both &&
+       printf "Tricky Guy <author@example.com>" >no-newline &&
+       git add just-bugs both no-newline &&
        git commit -m "my mailmaps" &&
        echo "Repo Guy <author@example.com>" >.mailmap &&
        echo "Internal Guy <author@example.com>" >internal.map
@@@ -286,28 -244,23 +287,41 @@@ test_expect_success 'mailmap.blob defau
        )
  '
  
+ test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
+       cat >expect <<-\EOF &&
+       Tricky Guy (1):
+             initial
+       nick1 (1):
+             second
+       EOF
+       git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
+       test_cmp expect actual
+ '
  test_expect_success 'cleanup after mailmap.blob tests' '
        rm -f .mailmap
  '
  
 +test_expect_success 'single-character name' '
 +      echo "     1    A <author@example.com>" >expect &&
 +      echo "     1    nick1 <bugs@company.xx>" >>expect &&
 +      echo "A <author@example.com>" >.mailmap &&
 +      test_when_finished "rm .mailmap" &&
 +      git shortlog -es HEAD >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'preserve canonical email case' '
 +      echo "     1    A U Thor <AUTHOR@example.com>" >expect &&
 +      echo "     1    nick1 <bugs@company.xx>" >>expect &&
 +      echo "<AUTHOR@example.com> <author@example.com>" >.mailmap &&
 +      test_when_finished "rm .mailmap" &&
 +      git shortlog -es HEAD >actual &&
 +      test_cmp expect actual
 +'
 +
  # Extended mailmap configurations should give us the following output for shortlog
  cat >expect <<\EOF
  A U Thor <author@example.com> (1):