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

Annotation of src/usr.bin/cvs/history.c, Revision 1.29

1.29    ! xsa         1: /*     $OpenBSD: history.c,v 1.28 2007/06/18 17:54:13 joris Exp $      */
1.1       jfb         2: /*
1.28      joris       3:  * Copyright (c) 2007 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.28      joris       5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         8:  *
1.28      joris       9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.28      joris      18: #include <sys/stat.h>
                     19:
                     20: #include <ctype.h>
                     21: #include <errno.h>
                     22: #include <pwd.h>
                     23: #include <stdlib.h>
                     24: #include <string.h>
                     25: #include <unistd.h>
1.1       jfb        26:
                     27: #include "cvs.h"
1.28      joris      28: #include "remote.h"
1.1       jfb        29:
1.28      joris      30: void   cvs_history_local(struct cvs_file *);
1.1       jfb        31:
1.28      joris      32: struct cvs_cmd         cvs_cmd_history = {
                     33:        CVS_OP_HISTORY, 0, "history",
1.29    ! xsa        34:        { "hi", "his" },                        /* omghi2you */
1.28      joris      35:        "Display the history of actions done in the base repository",
                     36:        "[-ac]",
                     37:        "ac",
1.14      jfb        38:        NULL,
1.28      joris      39:        cvs_history
                     40: };
                     41:
                     42: /* keep in sync with the defines for history stuff in cvs.h */
                     43: const char historytab[] = {
                     44:        'T',
                     45:        'O',
                     46:        'E',
                     47:        'F',
                     48:        'W',
                     49:        'U',
                     50:        'G',
                     51:        'C',
                     52:        'M',
                     53:        'A',
                     54:        'R',
                     55:        NULL
1.9       joris      56: };
                     57:
1.28      joris      58: #define HISTORY_ALL_USERS              0x01
                     59: #define HISTORY_DISPLAY_ARCHIVED       0x02
1.1       jfb        60:
1.28      joris      61: void
                     62: cvs_history_add(int type, struct cvs_file *cf, const char *argument)
1.1       jfb        63: {
1.28      joris      64:        FILE *fp;
                     65:        char *cwd;
                     66:        char revbuf[64], repo[MAXPATHLEN], fpath[MAXPATHLEN];
1.1       jfb        67:
1.28      joris      68:        if (cvs_nolog == 1)
                     69:                return;
1.19      xsa        70:
1.28      joris      71:        if (cvs_cmdop == CVS_OP_CHECKOUT || cvs_cmdop == CVS_OP_EXPORT) {
                     72:                if (type != CVS_HISTORY_CHECKOUT &&
                     73:                    type != CVS_HISTORY_EXPORT)
                     74:                        return;
1.1       jfb        75:        }
                     76:
1.28      joris      77:        cvs_log(LP_TRACE, "cvs_history_add(`%c', `%s', `%s')",
                     78:            historytab[type], (cf != NULL) ? cf->file_name : "", argument);
1.1       jfb        79:
1.28      joris      80:        if ((cwd = getcwd(NULL, MAXPATHLEN)) == NULL)
                     81:                fatal("cvs_history_add: getcwd: %s", strerror(errno));
1.1       jfb        82:
1.28      joris      83:        /* construct repository field */
                     84:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                     85:                cvs_get_repository_name(".", repo, sizeof(repo));
                     86:
                     87:                if (strlen(repo) > strlen(cwd))
                     88:                        fatal("bad repository `%s'", repo);
                     89:        } else {
                     90:                strlcpy(repo, argument, sizeof(repo));
                     91:        }
1.24      joris      92:
1.28      joris      93:        /* construct revision field */
                     94:        revbuf[0] = '\0';
                     95:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                     96:                switch (type) {
                     97:                case CVS_HISTORY_TAG:
                     98:                        strlcpy(revbuf, argument, sizeof(revbuf));
                     99:                        break;
                    100:                case CVS_HISTORY_CHECKOUT:
                    101:                case CVS_HISTORY_EXPORT:
                    102:                        /* copy TAG or DATE to revbuf */
                    103:                        break;
                    104:                case CVS_HISTORY_UPDATE_MERGED:
                    105:                case CVS_HISTORY_UPDATE_MERGED_ERR:
                    106:                case CVS_HISTORY_COMMIT_MODIFIED:
                    107:                case CVS_HISTORY_COMMIT_ADDED:
                    108:                case CVS_HISTORY_COMMIT_REMOVED:
                    109:                case CVS_HISTORY_UPDATE_CO:
                    110:                        rcsnum_tostr(cf->file_rcs->rf_head,
                    111:                            revbuf, sizeof(revbuf));
                    112:                        break;
1.15      xsa       113:                }
1.28      joris     114:        }
1.20      joris     115:
1.28      joris     116:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
                    117:            current_cvsroot->cr_dir, CVS_PATH_HISTORY);
1.20      joris     118:
1.28      joris     119:        if ((fp = fopen(fpath, "a")) != NULL) {
                    120:                fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n",
                    121:                    historytab[type], time(NULL), getlogin(), cwd, repo,
                    122:                    revbuf, (cf != NULL) ? cf->file_name : argument);
                    123:
                    124:                (void)fclose(fp);
                    125:        } else {
                    126:                cvs_log(LP_ERR, "failed to add entry to history file");
1.15      xsa       127:        }
1.1       jfb       128:
1.28      joris     129:        xfree(cwd);
1.1       jfb       130: }
                    131:
1.28      joris     132: int
                    133: cvs_history(int argc, char **argv)
                    134: {
                    135:        int ch, flags;
1.1       jfb       136:
1.28      joris     137:        flags = 0;
1.1       jfb       138:
1.28      joris     139:        while ((ch = getopt(argc, argv, cvs_cmd_history.cmd_opts)) != -1) {
                    140:                switch (ch) {
                    141:                case 'a':
                    142:                        flags |= HISTORY_ALL_USERS;
                    143:                        break;
                    144:                case 'c':
                    145:                        flags |= HISTORY_DISPLAY_ARCHIVED;
                    146:                        break;
                    147:                default:
                    148:                        fatal("%s", cvs_cmd_history.cmd_synopsis);
                    149:                }
1.1       jfb       150:        }
                    151:
1.28      joris     152:        argc -= optind;
                    153:        argv += optind;
                    154:
                    155:        return (0);
1.1       jfb       156: }