[BACK]Return to file.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Diff for /src/usr.bin/cvs/file.c between version 1.15 and 1.16

version 1.15, 2004/07/31 01:13:41 version 1.16, 2004/08/02 13:54:01
Line 97 
Line 97 
   
 static int        cvs_file_getdir  (CVSFILE *, int);  static int        cvs_file_getdir  (CVSFILE *, int);
 static void       cvs_file_freedir (struct cvs_dir *);  static void       cvs_file_freedir (struct cvs_dir *);
 static int        cvs_file_sort    (struct cvs_flist *);  static int        cvs_file_sort    (struct cvs_flist *, u_int);
 static int        cvs_file_cmp     (const void *, const void *);  static int        cvs_file_cmp     (const void *, const void *);
 static CVSFILE*   cvs_file_alloc   (const char *, u_int);  static CVSFILE*   cvs_file_alloc   (const char *, u_int);
 static CVSFILE*   cvs_file_lget    (const char *, int, CVSFILE *);  static CVSFILE*   cvs_file_lget    (const char *, int, CVSFILE *);
Line 366 
Line 366 
 cvs_file_getdir(CVSFILE *cf, int flags)  cvs_file_getdir(CVSFILE *cf, int flags)
 {  {
         int ret, fd;          int ret, fd;
           u_int ndirs;
         long base;          long base;
         void *dp, *ep;          void *dp, *ep;
         char fbuf[2048], pbuf[MAXPATHLEN];          char fbuf[2048], pbuf[MAXPATHLEN];
Line 425 
Line 426 
                             cf->cf_path, ent->d_name);                              cf->cf_path, ent->d_name);
                         cfp = cvs_file_lget(pbuf, flags, cf);                          cfp = cvs_file_lget(pbuf, flags, cf);
                         if (cfp != NULL) {                          if (cfp != NULL) {
                                 cfp->cf_parent = cf;                                  if (cfp->cf_type == DT_DIR) {
                                 if (cfp->cf_type == DT_DIR)  
                                         TAILQ_INSERT_HEAD(&dirs, cfp, cf_list);                                          TAILQ_INSERT_HEAD(&dirs, cfp, cf_list);
                                 else                                          ndirs++;
                                   }
                                   else {
                                         TAILQ_INSERT_HEAD(&(cdp->cd_files), cfp,                                          TAILQ_INSERT_HEAD(&(cdp->cd_files), cfp,
                                             cf_list);                                              cf_list);
                                           cdp->cd_nfiles++;
                                   }
                         }                          }
                 }                  }
         } while (ret > 0);          } while (ret > 0);
Line 442 
Line 446 
         }          }
   
         if (flags & CF_SORT) {          if (flags & CF_SORT) {
                 cvs_file_sort(&(cdp->cd_files));                  cvs_file_sort(&(cdp->cd_files), cdp->cd_nfiles);
                 cvs_file_sort(&dirs);                  cvs_file_sort(&dirs, ndirs);
         }          }
         TAILQ_FOREACH(cfp, &dirs, cf_list)          TAILQ_FOREACH(cfp, &dirs, cf_list)
                 TAILQ_INSERT_TAIL(&(cdp->cd_files), cfp, cf_list);                  TAILQ_INSERT_TAIL(&(cdp->cd_files), cfp, cf_list);
           cdp->cd_nfiles += ndirs;
   
         (void)close(fd);          (void)close(fd);
         cf->cf_ddat = cdp;          cf->cf_ddat = cdp;
Line 533 
Line 538 
 /*  /*
  * cvs_file_sort()   * cvs_file_sort()
  *   *
  * Sort a list of cvs file structures according to their filename.   * Sort a list of cvs file structures according to their filename.  The list
    * <flp> is modified according to the sorting algorithm.  The number of files
    * in the list must be given by <nfiles>.
    * Returns 0 on success, or -1 on failure.
  */   */
   
 static int  static int
 cvs_file_sort(struct cvs_flist *flp)  cvs_file_sort(struct cvs_flist *flp, u_int nfiles)
 {  {
         int i;          int i;
         size_t nb;          size_t nb;
         CVSFILE *cf, *cfvec[256];          CVSFILE *cf, **cfvec;
   
           cfvec = (CVSFILE **)calloc(nfiles, sizeof(CVSFILE *));
           if (cfvec == NULL) {
                   cvs_log(LP_ERRNO, "failed to allocate sorting vector");
                   return (-1);
           }
   
         i = 0;          i = 0;
         TAILQ_FOREACH(cf, flp, cf_list) {          TAILQ_FOREACH(cf, flp, cf_list) {
                 cfvec[i++] = cf;                  if (i == (int)nfiles) {
                 if (i == sizeof(cfvec)/sizeof(CVSFILE *)) {  
                         cvs_log(LP_WARN, "too many files to sort");                          cvs_log(LP_WARN, "too many files to sort");
                           /* rebuild the list and abort sorting */
                           while (--i >= 0)
                                   TAILQ_INSERT_HEAD(flp, cfvec[i], cf_list);
                           free(cfvec);
                         return (-1);                          return (-1);
                 }                  }
                   cfvec[i++] = cf;
   
                 /* now unlink it from the list,                  /* now unlink it from the list,
                  * we'll put it back in order later                   * we'll put it back in order later
Line 567 
Line 585 
         for (i = (int)nb - 1; i >= 0; i--)          for (i = (int)nb - 1; i >= 0; i--)
                 TAILQ_INSERT_HEAD(flp, cfvec[i], cf_list);                  TAILQ_INSERT_HEAD(flp, cfvec[i], cf_list);
   
           free(cfvec);
         return (0);          return (0);
 }  }
   

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16