Merge branch 'js/sleep-without-select'
authorJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2015 19:21:47 +0000 (12:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2015 19:21:47 +0000 (12:21 -0700)
Portability fix.

* js/sleep-without-select:
lockfile: wait using sleep_millisec() instead of select()
lockfile: convert retry timeout computations to millisecond
help.c: wrap wait-only poll() invocation in sleep_millisec()
lockfile: replace random() by rand()

1  2 
cache.h
help.c
lockfile.c
diff --combined cache.h
index 571c98f5e2406afad1352fcaddd1efff1af65cc1,328cdb73ee0a1de33ea7a0add8df6e2890699d39..fe840e34a591a4ecd2b11c611349127cc65e4ecf
+++ b/cache.h
@@@ -297,11 -297,8 +297,11 @@@ static inline unsigned int canon_mode(u
  #define RESOLVE_UNDO_CHANGED  (1 << 4)
  #define CACHE_TREE_CHANGED    (1 << 5)
  #define SPLIT_INDEX_ORDERED   (1 << 6)
 +#define UNTRACKED_CHANGED     (1 << 7)
  
  struct split_index;
 +struct untracked_cache;
 +
  struct index_state {
        struct cache_entry **cache;
        unsigned int version;
        struct hashmap name_hash;
        struct hashmap dir_hash;
        unsigned char sha1[20];
 +      struct untracked_cache *untracked;
  };
  
  extern struct index_state the_index;
@@@ -567,8 -563,6 +567,8 @@@ extern void fill_stat_data(struct stat_
   * INODE_CHANGED, and DATA_CHANGED.
   */
  extern int match_stat_data(const struct stat_data *sd, struct stat *st);
 +extern int match_stat_data_racy(const struct index_state *istate,
 +                              const struct stat_data *sd, struct stat *st);
  
  extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
  
@@@ -885,7 -879,6 +885,7 @@@ extern char *xdg_config_home(const cha
  
  /* object replacement */
  #define LOOKUP_REPLACE_OBJECT 1
 +#define LOOKUP_UNKNOWN_OBJECT 2
  extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
  static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
  {
@@@ -971,21 -964,15 +971,21 @@@ struct object_context 
        unsigned char tree[20];
        char path[PATH_MAX];
        unsigned mode;
 +      /*
 +       * symlink_path is only used by get_tree_entry_follow_symlinks,
 +       * and only for symlinks that point outside the repository.
 +       */
 +      struct strbuf symlink_path;
  };
  
 -#define GET_SHA1_QUIETLY        01
 -#define GET_SHA1_COMMIT         02
 -#define GET_SHA1_COMMITTISH     04
 -#define GET_SHA1_TREE          010
 -#define GET_SHA1_TREEISH       020
 -#define GET_SHA1_BLOB        040
 -#define GET_SHA1_ONLY_TO_DIE 04000
 +#define GET_SHA1_QUIETLY           01
 +#define GET_SHA1_COMMIT            02
 +#define GET_SHA1_COMMITTISH        04
 +#define GET_SHA1_TREE             010
 +#define GET_SHA1_TREEISH          020
 +#define GET_SHA1_BLOB             040
 +#define GET_SHA1_FOLLOW_SYMLINKS 0100
 +#define GET_SHA1_ONLY_TO_DIE    04000
  
  extern int get_sha1(const char *str, unsigned char *sha1);
  extern int get_sha1_commit(const char *str, unsigned char *sha1);
@@@ -1364,7 -1351,6 +1364,7 @@@ struct object_info 
        unsigned long *sizep;
        unsigned long *disk_sizep;
        unsigned char *delta_base_sha1;
 +      struct strbuf *typename;
  
        /* Response */
        enum {
@@@ -1553,13 -1539,9 +1553,13 @@@ extern const char *git_mailmap_blob
  extern void maybe_flush_or_die(FILE *, const char *);
  __attribute__((format (printf, 2, 3)))
  extern void fprintf_or_die(FILE *, const char *fmt, ...);
 +
 +#define COPY_READ_ERROR (-2)
 +#define COPY_WRITE_ERROR (-3)
  extern int copy_fd(int ifd, int ofd);
  extern int copy_file(const char *dst, const char *src, int mode);
  extern int copy_file_with_time(const char *dst, const char *src, int mode);
 +
  extern void write_or_die(int fd, const void *buf, size_t count);
  extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
  extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
@@@ -1698,5 -1680,6 +1698,6 @@@ int stat_validity_check(struct stat_val
  void stat_validity_update(struct stat_validity *sv, int fd);
  
  int versioncmp(const char *s1, const char *s2);
+ void sleep_millisec(int millisec);
  
  #endif /* CACHE_H */
diff --combined help.c
index 80ca8ee68d5af25b43314d351bc7ad09d9d9d03b,de1279b4227c450ad9229aec36ea1ae7b0079410..d996b340669a66d0b1619472fedf5c11b940d7c5
--- 1/help.c
--- 2/help.c
+++ b/help.c
@@@ -218,39 -218,17 +218,39 @@@ void list_commands(unsigned int colopts
        }
  }
  
 +static int cmd_group_cmp(const void *elem1, const void *elem2)
 +{
 +      const struct cmdname_help *e1 = elem1;
 +      const struct cmdname_help *e2 = elem2;
 +
 +      if (e1->group < e2->group)
 +              return -1;
 +      if (e1->group > e2->group)
 +              return 1;
 +      return strcmp(e1->name, e2->name);
 +}
 +
  void list_common_cmds_help(void)
  {
        int i, longest = 0;
 +      int current_grp = -1;
  
        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
                if (longest < strlen(common_cmds[i].name))
                        longest = strlen(common_cmds[i].name);
        }
  
 -      puts(_("The most commonly used git commands are:"));
 +      qsort(common_cmds, ARRAY_SIZE(common_cmds),
 +              sizeof(common_cmds[0]), cmd_group_cmp);
 +
 +      puts(_("These are common Git commands used in various situations:"));
 +
        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
 +              if (common_cmds[i].group != current_grp) {
 +                      printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group]));
 +                      current_grp = common_cmds[i].group;
 +              }
 +
                printf("   %s   ", common_cmds[i].name);
                mput_char(' ', longest - strlen(common_cmds[i].name));
                puts(_(common_cmds[i].help));
@@@ -394,7 -372,7 +394,7 @@@ const char *help_unknown_cmd(const cha
                if (autocorrect > 0) {
                        fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
                                (float)autocorrect/10.0);
-                       poll(NULL, 0, autocorrect * 100);
+                       sleep_millisec(autocorrect * 100);
                }
                return assumed;
        }
@@@ -429,7 -407,7 +429,7 @@@ struct similar_ref_cb 
        struct string_list *similar_refs;
  };
  
 -static int append_similar_ref(const char *refname, const unsigned char *sha1,
 +static int append_similar_ref(const char *refname, const struct object_id *oid,
                              int flags, void *cb_data)
  {
        struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
diff --combined lockfile.c
index 5a93bc7bc2425bf01e88f55024854225d6a78aca,fb78bda495574d57701dd5148557b4e6badefbc9..993bb8274833651159cec6f0571b5b555ea073ca
@@@ -157,14 -157,6 +157,6 @@@ static int lock_file(struct lock_file *
        return lk->fd;
  }
  
- static int sleep_microseconds(long us)
- {
-       struct timeval tv;
-       tv.tv_sec = 0;
-       tv.tv_usec = us;
-       return select(0, NULL, NULL, NULL, &tv);
- }
  /*
   * Constants defining the gaps between attempts to lock a file. The
   * first backoff period is approximately INITIAL_BACKOFF_MS
@@@ -184,27 -176,22 +176,22 @@@ static int lock_file_timeout(struct loc
  {
        int n = 1;
        int multiplier = 1;
-       long remaining_us = 0;
+       long remaining_ms = 0;
        static int random_initialized = 0;
  
        if (timeout_ms == 0)
                return lock_file(lk, path, flags);
  
        if (!random_initialized) {
-               srandom((unsigned int)getpid());
+               srand((unsigned int)getpid());
                random_initialized = 1;
        }
  
-       if (timeout_ms > 0) {
-               /* avoid overflow */
-               if (timeout_ms <= LONG_MAX / 1000)
-                       remaining_us = timeout_ms * 1000;
-               else
-                       remaining_us = LONG_MAX;
-       }
+       if (timeout_ms > 0)
+               remaining_ms = timeout_ms;
  
        while (1) {
-               long backoff_ms, wait_us;
+               long backoff_ms, wait_ms;
                int fd;
  
                fd = lock_file(lk, path, flags);
                        return fd; /* success */
                else if (errno != EEXIST)
                        return -1; /* failure other than lock held */
-               else if (timeout_ms > 0 && remaining_us <= 0)
+               else if (timeout_ms > 0 && remaining_ms <= 0)
                        return -1; /* failure due to timeout */
  
                backoff_ms = multiplier * INITIAL_BACKOFF_MS;
                /* back off for between 0.75*backoff_ms and 1.25*backoff_ms */
-               wait_us = (750 + random() % 500) * backoff_ms;
-               sleep_microseconds(wait_us);
-               remaining_us -= wait_us;
+               wait_ms = (750 + rand() % 500) * backoff_ms / 1000;
+               sleep_millisec(wait_ms);
+               remaining_ms -= wait_ms;
  
                /* Recursion: (n+1)^2 = n^2 + 2n + 1 */
                multiplier += 2*n + 1;
@@@ -289,7 -276,7 +276,7 @@@ int hold_lock_file_for_append(struct lo
                int save_errno = errno;
  
                if (flags & LOCK_DIE_ON_ERROR)
 -                      exit(128);
 +                      die("failed to prepare '%s' for appending", path);
                close(orig_fd);
                rollback_lock_file(lk);
                errno = save_errno;