diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-11-25 13:50:02 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-11-25 13:50:02 +0000 |
commit | 9ad5e4f642bdeda83edc17d43f882d50e96936c3 (patch) | |
tree | 9e0d8f413cd7bddabfa2d0958bd32ba60da7bf3a /usr.bin | |
parent | b5132fce78aaef078187dca50dbe9547b87b3c7b (diff) |
add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rcs/co.c | 20 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 48 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.h | 4 |
3 files changed, 63 insertions, 9 deletions
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index 1e3f7e42201..f5d1286243f 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.36 2005/11/24 15:35:11 xsa Exp $ */ +/* $OpenBSD: co.c,v 1.37 2005/11/25 13:50:01 xsa Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -48,6 +48,7 @@ checkout_main(int argc, char **argv) char fpath[MAXPATHLEN], buf[16]; char *username; const char *state = NULL; + time_t rcs_mtime = -1; flags = 0; kflag = RCS_KWEXP_ERR; @@ -59,7 +60,7 @@ checkout_main(int argc, char **argv) exit (1); } - while ((ch = rcs_getopt(argc, argv, "f::k:l::M::p::q::r::s:u::Vx:")) != -1) { + while ((ch = rcs_getopt(argc, argv, "f::k:l::M::p::q::r::s:Tu::Vx:")) != -1) { switch (ch) { case 'f': rcs_set_rev(rcs_optarg, &rev); @@ -144,6 +145,12 @@ checkout_main(int argc, char **argv) if ((file = rcs_open(fpath, RCS_RDWR)) == NULL) continue; + if (flags & PRESERVETIME) + rcs_mtime = rcs_get_mtime(file->rf_path); + + if (kflag != RCS_KWEXP_ERR) + rcs_kwexp_set(file, kflag); + if (rev == RCS_HEAD_REV) frev = file->rf_head; else @@ -151,17 +158,13 @@ checkout_main(int argc, char **argv) rcsnum_tostr(frev, buf, sizeof(buf)); - if (kflag != RCS_KWEXP_ERR) - rcs_kwexp_set(file, kflag); - if (flags & CO_STATE) { if (checkout_state(file, frev, argv[i], flags, username, state) < 0) { rcs_close(file); continue; } - } - else { + } else { if (checkout_rev(file, frev, argv[i], flags, username) < 0) { rcs_close(file); @@ -170,6 +173,9 @@ checkout_main(int argc, char **argv) } rcs_close(file); + + if (flags & PRESERVETIME) + rcs_set_mtime(fpath, rcs_mtime); } if (rev != RCS_HEAD_REV) diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index d3c261a5fdc..df48069172b 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.46 2005/11/23 09:39:20 xsa Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.47 2005/11/25 13:50:01 xsa Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -83,6 +83,52 @@ rcs_set_rev(const char *str, RCSNUM **rev) } } +/* + * rcs_get_mtime() + * + * Get <filename> last modified time. + * Returns last modified time on success, or -1 on failure. + */ +time_t +rcs_get_mtime(const char *filename) +{ + struct stat st; + time_t mtime; + + if (stat(filename, &st) == -1) { + cvs_log(LP_ERRNO, "failed to stat `%s'", filename); + return (-1); + } + mtime = (time_t)st.st_mtimespec.tv_sec; + + return (mtime); +} + +/* + * rcs_set_mtime() + * + * Set <filename> last modified time to <mtime> if it's not set to -1. + * Returns 0 on success, or -1 on failure. + */ +int +rcs_set_mtime(const char *filename, time_t mtime) +{ + static struct timeval tv[2]; + + if (mtime == -1) + return (0); + + tv[0].tv_sec = mtime; + tv[1].tv_sec = tv[0].tv_sec; + + if (utimes(filename, tv) == -1) { + cvs_log(LP_ERRNO, "error setting utimes"); + return (-1); + } + + return (0); +} + int rcs_init(char *envstr, char **argv, int argvlen) { diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h index e98b4940aa5..b107667a444 100644 --- a/usr.bin/rcs/rcsprog.h +++ b/usr.bin/rcs/rcsprog.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.h,v 1.25 2005/11/25 13:48:02 xsa Exp $ */ +/* $OpenBSD: rcsprog.h,v 1.26 2005/11/25 13:50:01 xsa Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -89,7 +89,9 @@ void rcsmerge_usage(void); int rcs_init(char *, char **, int); int rcs_getopt(int, char **, const char *); int rcs_main(int, char **); +int rcs_set_mtime(const char *, time_t); int rcs_statfile(char *, char *, size_t); +time_t rcs_get_mtime(const char *); void rcs_set_rev(const char *, RCSNUM **); void rcs_usage(void); void (*usage)(void); |