[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.30

1.30    ! joris       1: /*     $OpenBSD: history.c,v 1.29 2007/06/20 16:25:46 xsa 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.30    ! joris      80:        if (cvs_server_active == 1) {
        !            81:                cwd = "<remote>";
        !            82:        } else {
        !            83:                if ((cwd = getcwd(NULL, MAXPATHLEN)) == NULL)
        !            84:                        fatal("cvs_history_add: getcwd: %s", strerror(errno));
        !            85:        }
1.1       jfb        86:
1.28      joris      87:        /* construct repository field */
                     88:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                     89:                cvs_get_repository_name(".", repo, sizeof(repo));
                     90:
                     91:                if (strlen(repo) > strlen(cwd))
                     92:                        fatal("bad repository `%s'", repo);
                     93:        } else {
                     94:                strlcpy(repo, argument, sizeof(repo));
                     95:        }
1.24      joris      96:
1.28      joris      97:        /* construct revision field */
                     98:        revbuf[0] = '\0';
                     99:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                    100:                switch (type) {
                    101:                case CVS_HISTORY_TAG:
                    102:                        strlcpy(revbuf, argument, sizeof(revbuf));
                    103:                        break;
                    104:                case CVS_HISTORY_CHECKOUT:
                    105:                case CVS_HISTORY_EXPORT:
                    106:                        /* copy TAG or DATE to revbuf */
                    107:                        break;
                    108:                case CVS_HISTORY_UPDATE_MERGED:
                    109:                case CVS_HISTORY_UPDATE_MERGED_ERR:
                    110:                case CVS_HISTORY_COMMIT_MODIFIED:
                    111:                case CVS_HISTORY_COMMIT_ADDED:
                    112:                case CVS_HISTORY_COMMIT_REMOVED:
                    113:                case CVS_HISTORY_UPDATE_CO:
                    114:                        rcsnum_tostr(cf->file_rcs->rf_head,
                    115:                            revbuf, sizeof(revbuf));
                    116:                        break;
1.15      xsa       117:                }
1.28      joris     118:        }
1.20      joris     119:
1.28      joris     120:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
                    121:            current_cvsroot->cr_dir, CVS_PATH_HISTORY);
1.20      joris     122:
1.28      joris     123:        if ((fp = fopen(fpath, "a")) != NULL) {
                    124:                fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n",
                    125:                    historytab[type], time(NULL), getlogin(), cwd, repo,
                    126:                    revbuf, (cf != NULL) ? cf->file_name : argument);
                    127:
                    128:                (void)fclose(fp);
                    129:        } else {
                    130:                cvs_log(LP_ERR, "failed to add entry to history file");
1.15      xsa       131:        }
1.1       jfb       132:
1.30    ! joris     133:        if (cvs_server_active != 1)
        !           134:                xfree(cwd);
1.1       jfb       135: }
                    136:
1.28      joris     137: int
                    138: cvs_history(int argc, char **argv)
                    139: {
                    140:        int ch, flags;
1.1       jfb       141:
1.28      joris     142:        flags = 0;
1.1       jfb       143:
1.28      joris     144:        while ((ch = getopt(argc, argv, cvs_cmd_history.cmd_opts)) != -1) {
                    145:                switch (ch) {
                    146:                case 'a':
                    147:                        flags |= HISTORY_ALL_USERS;
                    148:                        break;
                    149:                case 'c':
                    150:                        flags |= HISTORY_DISPLAY_ARCHIVED;
                    151:                        break;
                    152:                default:
                    153:                        fatal("%s", cvs_cmd_history.cmd_synopsis);
                    154:                }
1.1       jfb       155:        }
                    156:
1.28      joris     157:        argc -= optind;
                    158:        argv += optind;
                    159:
                    160:        return (0);
1.1       jfb       161: }