Search code examples
cvs

How to programatically get the latest commit date on a CVS checkout


For a script I'm working on to implement bisection using CVS, I want to figure out what the 'timestamp' is of the current checkout. In other words, if I'm on a branch/tag, I want to know the last timestamp something got commited to that branch/tag. If I'm on head, I want to know the last timestamp on head.

I know this is not 100% guaranteed, since cvs checkouts can have different files at different timestamps/revisions/..., but a correct-in-most-cases solution is fine by me.

Naively, I thought that

cvs log -N | grep ^date: | sort | tail -n 1 | cut -d\; -f1

was going to do it, but it turns out it goes through the whole commit history, for all branches/tags.


Solution

  • CVS files on a branch being at different timestamps, the accuracy of picking any one file to get the last time-info for the branch is hardly worth.

    But, it can get better if there is some file which will be changed often. For, example, in one of my bases, there is a version.h file which is updated on every version shift (minor or major). That can be used for time-info on the current version (again not accurate to all the files in the branch, but it does give a bottom line).

    So, if you know a file that can give you a bottom line value,

    cvs log path/to/version.h -r branch/tag | grep ^date | sort | tail -1
    

    will give you the last timestamp for that file.


    If you can enumerate the entire file set of the base like this,

    find /base/dir -type f | grep -v CVS > files.txt
    

    then, you can loop the cvs command above for each file,

    rm -f allFiles.txt
    for f in $(<files.txt); do cvs log $f ...etc... tail -1 >> allFiles.txt
    sort allFiles.txt | tail -1
    

    Last line of the sort will give you exact date for the most recent commit.
    Alas, you will not get the file name (which can also be done with some more fu)