Finish issue #224 by allowing svndbadmin to optionally accept a range

of revisions for the 'update' operation.

* bin/svndbadmin
  (): Update the script's header comment.
  (main): Now accept a 'revs' list instead of a single integer revision.
  (_rev2int): New helper function.
  (usage): Update usage message.
  (__main__): Now allow a revision range to be specified, with support
    for the 'HEAD' keyword, too.


git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@1546 8cb11bc2-c004-0410-86c3-e597b4017df7
remotes/options-overhaul
cmpilato 2007-03-27 20:22:22 +00:00
parent 2860672524
commit 5ce1ab531d
1 changed files with 39 additions and 15 deletions

View File

@ -27,8 +27,8 @@
# #
# If you allow changes to revision properties in your repository, you # If you allow changes to revision properties in your repository, you
# might also want to set up something similar in the # might also want to set up something similar in the
# post-revprop-change hook using "rebuild" instead of "update" to keep # post-revprop-change hook using "update" with the --force option to
# the checkin database consistent with the repository. # keep the checkin database consistent with the repository.
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# #
@ -236,7 +236,7 @@ def handle_revision(db, command, repo, rev, verbose, force=0):
else: else:
print "skipped (already recorded)." print "skipped (already recorded)."
def main(command, repository, rev=None, verbose=0, force=0): def main(command, repository, revs=[], verbose=0, force=0):
cfg = viewvc.load_config(CONF_PATHNAME) cfg = viewvc.load_config(CONF_PATHNAME)
db = cvsdb.ConnectDatabase(cfg) db = cvsdb.ConnectDatabase(cfg)
@ -246,27 +246,46 @@ def main(command, repository, rev=None, verbose=0, force=0):
db.PurgeRepository(repository) db.PurgeRepository(repository)
repo = SvnRepo(repository) repo = SvnRepo(repository)
if command == 'rebuild' or (command == 'update' and not rev): if command == 'rebuild' or (command == 'update' and not revs):
for rev in range(repo.rev_max+1): for rev in range(repo.rev_max+1):
handle_revision(db, command, repo, rev, verbose) handle_revision(db, command, repo, rev, verbose)
elif command == 'update': elif command == 'update':
handle_revision(db, command, repo, rev, verbose, force) if revs[0] is None:
revs[0] = repo.rev_max
if revs[1] is None:
revs[1] = repo.rev_max
revs.sort()
for rev in range(revs[0], revs[1]+1):
handle_revision(db, command, repo, rev, verbose, force)
def _rev2int(r):
if r == 'HEAD':
r = None
else:
r = int(r)
if r < 0:
raise ValueError, "invalid revision '%d'" % (r)
return r
def usage(): def usage():
cmd = os.path.basename(sys.argv[0]) cmd = os.path.basename(sys.argv[0])
sys.stderr.write(""" sys.stderr.write("""
Usage: 1. %s [-v] rebuild REPOSITORY Usage: 1. %s [-v] rebuild REPOSITORY
2. %s [-v] update REPOSITORY [REVISION] [--force] 2. %s [-v] update REPOSITORY [REV:[REV2]] [--force]
3. %s [-v] purge REPOSITORY 3. %s [-v] purge REPOSITORY
1. Rebuild the commit database information for REPOSITORY across all 1. Rebuild the commit database information for REPOSITORY across all
revisions. revisions.
2. Update the commit database information for REPOSITORY across all revisions 2. Update the commit database information for REPOSITORY across all
or, optionally, only for the specified REVISION. This is just like revisions or, optionally, only for the specified revision REV (or
rebuilding, except that, unless --force is specified, no commit information revision range REV:REV2). This is just like rebuilding, except
will be stored for commits already present in the database. that, unless --force is specified, no commit information will be
stored for commits already present in the database. If a range is
specified, the revisions will be processed in ascending order, and
you may specify "HEAD" to indicate "the youngest revision currently
in the repository".
3. Purge information specific to REPOSITORY from the database. 3. Purge information specific to REPOSITORY from the database.
Use the -v flag to cause this script to give progress information as it works. Use the -v flag to cause this script to give progress information as it works.
@ -303,6 +322,7 @@ if __name__ == '__main__':
sys.stderr.write('ERROR: could not find repository %s\n' % repository) sys.stderr.write('ERROR: could not find repository %s\n' % repository)
usage() usage()
revs = []
if len(sys.argv) > 3: if len(sys.argv) > 3:
if command == 'rebuild': if command == 'rebuild':
sys.stderr.write('ERROR: rebuild no longer accepts a revision ' sys.stderr.write('ERROR: rebuild no longer accepts a revision '
@ -310,18 +330,22 @@ if __name__ == '__main__':
usage() usage()
elif command != 'update': elif command != 'update':
usage() usage()
rev = sys.argv[3]
try: try:
rev = int(rev) revs = map(lambda x: _rev2int(x), sys.argv[3].split(':'))
if len(revs) > 2:
raise ValueError, "too many revisions in range"
if len(revs) == 1:
revs.append(revs[0])
except ValueError: except ValueError:
sys.stderr.write('ERROR: revision "%s" is not numeric\n' % rev) sys.stderr.write('ERROR: invalid revision specification "%s"\n' \
% sys.argv[3])
usage() usage()
else: else:
rev = None rev = None
try: try:
repository = cvsdb.CleanRepository(os.path.abspath(repository)) repository = cvsdb.CleanRepository(os.path.abspath(repository))
main(command, repository, rev, verbose, force) main(command, repository, revs, verbose, force)
except KeyboardInterrupt: except KeyboardInterrupt:
print print
print '** break **' print '** break **'