<commit_before>#!/usr/bin/python

# log-police.py: Ensure that log messages end with a single newline.
# See usage() function for details, or just run with no arguments.

import os
import sys
import getopt

import svn
import svn.fs
import svn.repos
import svn.core


# Pretend we have true booleans on older python versions
try:
  True
except:
  True = 1
  False = 0


def fix_log_message(log_message):
  """Return a fixed version of LOG_MESSAGE.  By default, this just
  means ensuring that the result ends with exactly one newline and no
  other whitespace.  But if you want to do other kinds of fixups, this
  function is the place to implement them -- all log message fixing in
  this script happens here."""
  return log_message.rstrip() + "\n"


def fix_txn(fs, txn_name):
  "Fix up the log message for txn TXN_NAME in FS.  See fix_log_message()."
  txn = svn.fs.svn_fs_open_txn(fs, txn_name)
  log_message = svn.fs.svn_fs_txn_prop(txn, "svn:log")
  if log_message is not None:
    log_message = fix_log_message(log_message)
    svn.fs.svn_fs_change_txn_prop(txn, "svn:log", log_message)


def fix_rev(fs, revnum):
  "Fix up the log message for revision REVNUM in FS.  See fix_log_message()."
  log_message = svn.fs.svn_fs_revision_prop(fs, revnum, 'svn:log')
  if log_message is not None:
    log_message = fix_log_message(log_message)
    svn.fs.svn_fs_change_rev_prop(fs, revnum, "svn:log", log_message)


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

  try:
    opts, args = getopt.getopt(argv[1:], 't:r:h?', ["help", "all-revs"])
  except:
    sys.stderr.write("ERROR: problem processing arguments / options.\n\n")
    usage(sys.stderr)
    sys.exit(1)
  for opt, value in opts:
    if opt == '--help' or opt == '-h' or opt == '-?':
      usage()
      sys.exit(0)
    elif opt == '-t':
      txn_name = value
    elif opt == '-r':
      rev_name = value
    elif opt == '--all-revs':
      all_revs = True
    else:
      sys.stderr.write("ERROR: unknown option '%s'.\n\n" % opt)<commit_msg>* tools/hook-scripts/log-police.py   (fix_txn, fix_rev): Don't set a new log message if there's no change.<commit_after>#!/usr/bin/python

# log-police.py: Ensure that log messages end with a single newline.
# See usage() function for details, or just run with no arguments.

import os
import sys
import getopt

import svn
import svn.fs
import svn.repos
import svn.core


# Pretend we have true booleans on older python versions
try:
  True
except:
  True = 1
  False = 0


def fix_log_message(log_message):
  """Return a fixed version of LOG_MESSAGE.  By default, this just
  means ensuring that the result ends with exactly one newline and no
  other whitespace.  But if you want to do other kinds of fixups, this
  function is the place to implement them -- all log message fixing in
  this script happens here."""
  return log_message.rstrip() + "\n"


def fix_txn(fs, txn_name):
  "Fix up the log message for txn TXN_NAME in FS.  See fix_log_message()."
  txn = svn.fs.svn_fs_open_txn(fs, txn_name)
  log_message = svn.fs.svn_fs_txn_prop(txn, "svn:log")
  if log_message is not None:
    new_message = fix_log_message(log_message)
    if new_message != log_message:
      svn.fs.svn_fs_change_txn_prop(txn, "svn:log", new_message)


def fix_rev(fs, revnum):
  "Fix up the log message for revision REVNUM in FS.  See fix_log_message()."
  log_message = svn.fs.svn_fs_revision_prop(fs, revnum, 'svn:log')
  if log_message is not None:
    new_message = fix_log_message(log_message)
    if new_message != log_message:
      svn.fs.svn_fs_change_rev_prop(fs, revnum, "svn:log", new_message)


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

  try:
    opts, args = getopt.getopt(argv[1:], 't:r:h?', ["help", "all-revs"])
  except:
    sys.stderr.write("ERROR: problem processing arguments / options.\n\n")
    usage(sys.stderr)
    sys.exit(1)
  for opt, value in opts:
    if opt == '--help' or opt == '-h' or opt == '-?':
      usage()
      sys.exit(0)
    elif opt == '-t':
      txn_name = value
    elif opt == '-r':
      rev_name = value
    elif opt == '--all-revs':
      all_revs = True
    else:
      sys.stderr.write("ERROR: unknown option '%s'.\n\n" % opt)
{'fraction_non_alphanumeric': 0.1134404845096669, 'fraction_numerical': 0.0023293733985557887, 'mean_word_length': 3.3995901639344264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2865565', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1549, 'n_words': 480}