Merge branch 'jc/cocci-preincr'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Oct 2018 06:43:48 +0000 (15:43 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Oct 2018 06:43:48 +0000 (15:43 +0900)
Code cleanup.

* jc/cocci-preincr:
fsck: s/++i > 1/i++/
cocci: simplify "if (++u > 1)" to "if (u++)"

1  2 
fsck.c
diff --combined fsck.c
index 38624d251126ed5a75cd6b8e8b7adfddbb29b283,d44c46c5275b137880b0d02da51024553feefe1b..68502ce85b11bf0ef4445f2b1688b3834301ba53
--- 1/fsck.c
--- 2/fsck.c
+++ b/fsck.c
@@@ -10,6 -10,7 +10,6 @@@
  #include "fsck.h"
  #include "refs.h"
  #include "utf8.h"
 -#include "sha1-array.h"
  #include "decorate.h"
  #include "oidset.h"
  #include "packfile.h"
@@@ -183,37 -184,40 +183,37 @@@ static int fsck_msg_type(enum fsck_msg_
  
  static void init_skiplist(struct fsck_options *options, const char *path)
  {
 -      static struct oid_array skiplist = OID_ARRAY_INIT;
 -      int sorted, fd;
 -      char buffer[GIT_MAX_HEXSZ + 1];
 +      FILE *fp;
 +      struct strbuf sb = STRBUF_INIT;
        struct object_id oid;
  
 -      if (options->skiplist)
 -              sorted = options->skiplist->sorted;
 -      else {
 -              sorted = 1;
 -              options->skiplist = &skiplist;
 -      }
 -
 -      fd = open(path, O_RDONLY);
 -      if (fd < 0)
 +      fp = fopen(path, "r");
 +      if (!fp)
                die("Could not open skip list: %s", path);
 -      for (;;) {
 +      while (!strbuf_getline(&sb, fp)) {
                const char *p;
 -              int result = read_in_full(fd, buffer, sizeof(buffer));
 -              if (result < 0)
 -                      die_errno("Could not read '%s'", path);
 -              if (!result)
 -                      break;
 -              if (parse_oid_hex(buffer, &oid, &p) || *p != '\n')
 -                      die("Invalid SHA-1: %s", buffer);
 -              oid_array_append(&skiplist, &oid);
 -              if (sorted && skiplist.nr > 1 &&
 -                              oidcmp(&skiplist.oid[skiplist.nr - 2],
 -                                     &oid) > 0)
 -                      sorted = 0;
 -      }
 -      close(fd);
 +              const char *hash;
 +
 +              /*
 +               * Allow trailing comments, leading whitespace
 +               * (including before commits), and empty or whitespace
 +               * only lines.
 +               */
 +              hash = strchr(sb.buf, '#');
 +              if (hash)
 +                      strbuf_setlen(&sb, hash - sb.buf);
 +              strbuf_trim(&sb);
 +              if (!sb.len)
 +                      continue;
  
 -      if (sorted)
 -              skiplist.sorted = 1;
 +              if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
 +                      die("Invalid SHA-1: %s", sb.buf);
 +              oidset_insert(&options->skiplist, &oid);
 +      }
 +      if (ferror(fp))
 +              die_errno("Could not read '%s'", path);
 +      fclose(fp);
 +      strbuf_release(&sb);
  }
  
  static int parse_msg_type(const char *str)
@@@ -318,7 -322,9 +318,7 @@@ static void append_msg_id(struct strbu
  
  static int object_on_skiplist(struct fsck_options *opts, struct object *obj)
  {
 -      if (opts && opts->skiplist && obj)
 -              return oid_array_lookup(opts->skiplist, &obj->oid) >= 0;
 -      return 0;
 +      return opts && obj && oidset_contains(&opts->skiplist, &obj->oid);
  }
  
  __attribute__((format (printf, 4, 5)))
@@@ -479,7 -485,7 +479,7 @@@ static int fsck_walk_commit(struct comm
                if (name) {
                        struct object *obj = &parents->item->object;
  
-                       if (++counter > 1)
+                       if (counter++)
                                put_object_name(options, obj, "%s^%d",
                                        name, counter);
                        else if (generation > 0)