简体   繁体   中英

CVSNT: from a tag to a list of file names and revisions

I have a project with sources under the control of CVSNT.

I need a list of source file names and revisions belonging to a certain tag. For example:

the tag MYTAG is:
myproject/main.cpp 1.5.2.3
myproject/myclass.h 1.5.2.1

I know that with cvs log -rMYTAG > log.txt I get in log.txt all the information I need and then I can filter it to build my list, but, is there any utility which already do what I need?

Here's a Python script that does this:

import sys, os, os.path
import re, string

def runCvs(args):
  f_in, f_out, f_err = os.popen3('cvs '+string.join(args))
  out = f_out.read()
  err = f_err.read()
  f_out.close()
  f_err.close()
  code = f_in.close()
  if not code: code = 0
  return code, out, err

class RevDumper:
  def parseFile(self, rex, filelog):
    m = rex.search(filelog)
    if m:
      print '%s\t%s' % (m.group(1), m.group(2))

  def filterOutput(self, logoutput, repoprefix):
    rex = re.compile('^={77}$', re.MULTILINE)
    files = rex.split(logoutput)
    rex = re.compile('RCS file: %s(.*),v[^=]+selected revisions: [^0][^=]+revision ([0-9\.]+)' % repoprefix, re.MULTILINE)
    for file in files:
      self.parseFile(rex, file)

  def getInfo(self, tag, module, repoprefix):
    args = ['-Q', '-z9', 'rlog', '-S', '-N', '-r'+tag, module] # remove the -S if you're using an older version of CVS
    code, out, err = runCvs(args)
    if code == 0:
      self.filterOutput(out, repoprefix)
    else:
      sys.stderr.write('CVS returned %d\n%s\n' % (code, err))

if len(sys.argv) > 2:
  tag = sys.argv[1]
  module = sys.argv[2]
  if len(sys.argv) > 3:
    repoprefix = sys.argv[3]
  else:
    repoprefix = ''
  RevDumper().getInfo(tag, module, repoprefix)
else:
  sys.stderr.write('Syntax: %s TAG MODULE [REPOPREFIX]' % os.path.basename(sys.argv[0]))

Note that you either have to have a CVSROOT environment variable set or run this from inside a working copy checked out from the repository you want to query.

Also, the file names displayed are based on the "RCS File" property of the rlog output, ie they still contain the repository prefix. If you want to filter that out you can specify a third argument, eg when your CVSROOT is something like sspi:server:/cvsrepo then you would call this like:

ListCvsTagRevisions.py MyTag MyModule /cvsrepo/

Hope this helps.


Note: If you need a script that lists the revisions currently in your working copy, see the edit history of this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM