Print this page
3272 findunref should support git

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/findunref/findunref.c
          +++ new/usr/src/tools/findunref/findunref.c
↓ open down ↓ 68 lines elided ↑ open up ↑
  69   69   */
  70   70  typedef int checkscm_func_t(const char *, const struct FTW *);
  71   71  typedef void chdirscm_func_t(const char *);
  72   72  
  73   73  typedef struct {
  74   74          const char      *name;
  75   75          checkscm_func_t *checkfunc;
  76   76          chdirscm_func_t *chdirfunc;
  77   77  } scm_t;
  78   78  
  79      -static checkscm_func_t check_tw, check_hg;
  80      -static chdirscm_func_t chdir_hg;
       79 +static checkscm_func_t check_tw, check_hg, check_git;
       80 +static chdirscm_func_t chdir_hg, chdir_git;
  81   81  static int      pnset_add(pnset_t *, const char *);
  82   82  static int      pnset_check(const pnset_t *, const char *);
  83   83  static void     pnset_empty(pnset_t *);
  84   84  static void     pnset_free(pnset_t *);
  85   85  static int      checkpath(const char *, const struct stat *, int, struct FTW *);
  86   86  static pnset_t  *make_exset(const char *);
  87   87  static void     warn(const char *, ...);
  88   88  static void     die(const char *, ...);
  89   89  
  90   90  static const scm_t scms[] = {
  91   91          { "tw",         check_tw,       NULL            },
  92   92          { "teamware",   check_tw,       NULL            },
  93   93          { "hg",         check_hg,       chdir_hg        },
  94   94          { "mercurial",  check_hg,       chdir_hg        },
       95 +        { "git",        check_git,      chdir_git       },
  95   96          { NULL,         NULL,           NULL            }
  96   97  };
  97   98  
  98   99  static const scm_t      *scm;
  99  100  static hgdata_t         hgdata;
      101 +static pnset_t          *gitmanifest = NULL;
 100  102  static time_t           tstamp;         /* timestamp to compare files to */
 101  103  static pnset_t          *exsetp;        /* pathname globs to ignore */
 102  104  static const char       *progname;
 103  105  
 104  106  int
 105  107  main(int argc, char *argv[])
 106  108  {
 107  109          int c;
 108  110          char path[MAXPATHLEN];
 109  111          char subtree[MAXPATHLEN] = "./";
↓ open down ↓ 33 lines elided ↑ open up ↑
 143  145                  case '?':
 144  146                          goto usage;
 145  147                  }
 146  148          }
 147  149  
 148  150          argc -= optind;
 149  151          argv += optind;
 150  152  
 151  153          if (argc != 2) {
 152  154  usage:          (void) fprintf(stderr, "usage: %s [-s <subtree>] "
 153      -                    "[-t <tstampfile>] [-S hg|tw] <srcroot> <exceptfile>\n",
      155 +                    "[-t <tstampfile>] [-S hg|tw|git] <srcroot> <exceptfile>\n",
 154  156                      progname);
 155  157                  return (EXIT_FAILURE);
 156  158          }
 157  159  
 158  160          /*
 159  161           * Interpret a relative timestamp path as relative to srcroot.
 160  162           */
 161  163          if (tstampfile[0] == '/')
 162  164                  (void) strlcpy(path, tstampfile, MAXPATHLEN);
 163  165          else
↓ open down ↓ 30 lines elided ↑ open up ↑
 194  196  load_manifest(const char *hgroot)
 195  197  {
 196  198          FILE    *fp = NULL;
 197  199          char    *hgcmd = NULL;
 198  200          char    *newline;
 199  201          pnset_t *pnsetp;
 200  202          char    path[MAXPATHLEN];
 201  203  
 202  204          pnsetp = calloc(sizeof (pnset_t), 1);
 203  205          if (pnsetp == NULL ||
 204      -            asprintf(&hgcmd, "/usr/bin/hg manifest -R %s", hgroot) == -1)
      206 +            asprintf(&hgcmd, "hg manifest -R %s", hgroot) == -1)
 205  207                  goto fail;
 206  208  
 207  209          fp = popen(hgcmd, "r");
 208  210          if (fp == NULL)
 209  211                  goto fail;
 210  212  
 211  213          while (fgets(path, sizeof (path), fp) != NULL) {
 212  214                  newline = strrchr(path, '\n');
 213  215                  if (newline != NULL)
 214  216                          *newline = '\0';
↓ open down ↓ 7 lines elided ↑ open up ↑
 222  224          return (pnsetp);
 223  225  fail:
 224  226          warn("cannot load hg manifest at %s", hgroot);
 225  227          if (fp != NULL)
 226  228                  (void) pclose(fp);
 227  229          free(hgcmd);
 228  230          pnset_free(pnsetp);
 229  231          return (NULL);
 230  232  }
 231  233  
      234 +static void
      235 +chdir_git(const char *path)
      236 +{
      237 +        FILE *fp = NULL;
      238 +        char *gitcmd = NULL;
      239 +        char *newline;
      240 +        char fn[MAXPATHLEN];
      241 +        pnset_t *pnsetp;
      242 +
      243 +        pnsetp = calloc(sizeof (pnset_t), 1);
      244 +        if ((pnsetp == NULL) ||
      245 +            (asprintf(&gitcmd, "git ls-files %s", path) == -1))
      246 +                goto fail;
      247 +
      248 +        if ((fp = popen(gitcmd, "r")) == NULL)
      249 +                goto fail;
      250 +
      251 +        while (fgets(fn, sizeof (fn), fp) != NULL) {
      252 +                if ((newline = strrchr(fn, '\n')) != NULL)
      253 +                        *newline = '\0';
      254 +
      255 +                if (pnset_add(pnsetp, fn) == 0)
      256 +                        goto fail;
      257 +        }
      258 +
      259 +        (void) pclose(fp);
      260 +        free(gitcmd);
      261 +        gitmanifest = pnsetp;
      262 +        return;
      263 +fail:
      264 +        warn("cannot load git manifest");
      265 +        if (fp != NULL)
      266 +                (void) pclose(fp);
      267 +        if (pnsetp != NULL)
      268 +                free(pnsetp);
      269 +        if (gitcmd != NULL)
      270 +                free(gitcmd);
      271 +}
      272 +
 232  273  /*
 233  274   * If necessary, change our active manifest to be appropriate for `path'.
 234  275   */
 235  276  static void
 236  277  chdir_hg(const char *path)
 237  278  {
 238  279          char hgpath[MAXPATHLEN];
 239  280          char basepath[MAXPATHLEN];
 240  281          char *slash;
 241  282  
↓ open down ↓ 59 lines elided ↑ open up ↑
 301  342  static int
 302  343  check_hg(const char *path, const struct FTW *ftwp)
 303  344  {
 304  345          /*
 305  346           * The manifest paths are relative to the manifest root; skip past it.
 306  347           */
 307  348          path += hgdata.rootlen;
 308  349  
 309  350          return (hgdata.manifest != NULL && pnset_check(hgdata.manifest, path));
 310  351  }
      352 +/* ARGSUSED */
      353 +static int
      354 +check_git(const char *path, const struct FTW *ftwp)
      355 +{
      356 +        path += 2;              /* Skip "./" */
      357 +        return (gitmanifest != NULL && pnset_check(gitmanifest, path));
      358 +}
 311  359  
 312  360  /*
 313  361   * Check if a file is under TeamWare control by checking for its corresponding
 314  362   * SCCS "s-dot" file.
 315  363   */
 316  364  static int
 317  365  check_tw(const char *path, const struct FTW *ftwp)
 318  366  {
 319  367          char sccspath[MAXPATHLEN];
 320  368  
↓ open down ↓ 219 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX