def main()

in tools/hook-scripts/log-police.py [0:0]


def main(ignored_pool, argv):
  repos_path = None
  txn_name = None
  rev_name = None
  all_revs = False

  try:
    opts, args = my_getopt(argv[1:], 't:r:h?', ["help", "all-revs"])
  except:
    usage_and_exit("problem processing arguments / options.")
  for opt, value in opts:
    if opt == '--help' or opt == '-h' or opt == '-?':
      usage_and_exit()
    elif opt == '-t':
      txn_name = value
    elif opt == '-r':
      rev_name = value
    elif opt == '--all-revs':
      all_revs = True
    else:
      usage_and_exit("unknown option '%s'." % opt)

  if txn_name is not None and rev_name is not None:
    usage_and_exit("cannot pass both -t and -r.")
  if txn_name is not None and all_revs:
    usage_and_exit("cannot pass --all-revs with -t.")
  if rev_name is not None and all_revs:
    usage_and_exit("cannot pass --all-revs with -r.")
  if rev_name is None and txn_name is None and not all_revs:
    usage_and_exit("must provide exactly one of -r, -t, or --all-revs.")
  if len(args) != 1:
    usage_and_exit("only one argument allowed (the repository).")

  repos_path = svn.core.svn_path_canonicalize(args[0])

  # A non-bindings version of this could be implemented by calling out
  # to 'svnlook getlog' and 'svnadmin setlog'.  However, using the
  # bindings results in much simpler code.

  fs = svn.repos.svn_repos_fs(svn.repos.svn_repos_open(repos_path))
  if txn_name is not None:
    fix_txn(fs, txn_name)
  elif rev_name is not None:
    fix_rev(fs, int(rev_name))
  elif all_revs:
    # Do it such that if we're running on a live repository, we'll
    # catch up even with commits that came in after we started.
    last_youngest = 0
    while True:
      youngest = svn.fs.svn_fs_youngest_rev(fs)
      if youngest >= last_youngest:
        for this_rev in range(last_youngest, youngest + 1):
          fix_rev(fs, this_rev)
        last_youngest = youngest + 1
      else:
        break