Message-Id: <200110092317.QAA07511@zen.crufty.net> Subject: Re: Fwd: Re: CVS command line issues From: "Simon J. Gerraty" Date: Tue, 9 Oct 2001 16:17:30 -0700 (PDT) Delivery-Date: Tue, 09 Oct 2001 16:17:45 -0700 Status: RO Anyway, below is an updated version of my precommit patch, that uses '|' as the clue that popen should be used. Thus tools that expect args on stdin can be used directly, and |xargs can be used for others. Description: we use CVS to maintain our DNS data. We also use a DNS regression suite (see http://www.crufty.net/help/dns.html) to do pre-commit checks - very handy. The above toolset includes facilities for generating PTR records. If/when we re-configure said tool, it can cause a few hundred in-addr zone files to change. This typically causes the pre-commit checks to fail as the OS command line length is exceeded when cvs attempts to run the regression suite in that directory. The patch below (to cvs-1.11) modifies precommit_proc() such that if the pre-commit filter command begins with '|', then it is run using run_popen() (after skipping over the '|') rather than run_exec(). Thus filters that expect args on stdin can be used directly, and "| xargs " can be used for others. --sjg --- commit.c.orig Sun Oct 1 23:43:56 2000 +++ commit.c Tue Oct 9 15:40:30 2001 @@ -1102,13 +1102,17 @@ precommit_list_proc (p, closure) void *closure; { struct logfile_info *li; + FILE *fp = closure; li = (struct logfile_info *) p->data; if (li->type == T_ADDED || li->type == T_MODIFIED || li->type == T_REMOVED) { - run_arg (p->key); + if (fp) + fprintf(fp, "'%s'\n", p->key); + else + run_arg (p->key); } return (0); } @@ -1121,6 +1125,8 @@ precommit_proc (repository, filter) char *repository; char *filter; { + int rc = -1; + /* see if the filter is there, only if it's a full path */ if (isabsolute (filter)) { @@ -1141,11 +1147,61 @@ precommit_proc (repository, filter) } free (s); } + + if (*filter == '|') { + /* + * Filter wants args on stdin - like xargs. + * Don't use run_exec(). + */ + char *cmd = xmalloc(strlen(filter) + strlen(repository) + 4); + if (cmd) { + FILE *fp; + int status = -1; + + /* + * Skip over the '|'. + */ + while (*filter == '|' || + *filter == ' ' || + *filter == '\t') + ++filter; + + sprintf(cmd, "%s %s", filter, repository); + + if (fp = run_popen(cmd, "w")) { + (void) walklist (saved_ulist, precommit_list_proc, fp); + status = pclose(fp); + if (status != -1) { + /* + * from run_exec() + */ +#ifndef VMS /* status is return status */ + if (WIFEXITED (status)) + rc = WEXITSTATUS (status); + else if (WIFSIGNALED (status)) + { + if (WTERMSIG (status) == SIGPIPE) + error (1, 0, "broken pipe"); + rc = 2; + } + else + rc = 1; +#else /* VMS */ + rc = WEXITSTATUS (status); +#endif /* VMS */ + } + } + free(cmd); + } + + } else { run_setup (filter); run_arg (repository); (void) walklist (saved_ulist, precommit_list_proc, NULL); - return (run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL|RUN_REALLY)); + rc = run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL|RUN_REALLY); + } + return rc; } /*