You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by kf...@collab.net on 2006/03/03 20:17:44 UTC

Installing log-police.py in Subversion's repository.

So, I'd like to install log-police.py (see r18705) as a pre-commit
hook in Subversion's own repository, and also use it to clean up all
the old log messages.  As it doesn't trigger the post-revprop-change
hook, no one would receive mails about those cleanups.  But since this
wouldn't affect the real content of log messages, it would just ensure
that each log message ends with exactly one newline, not seeing those
silly little diffs is just fine by me.  Thoughts, objections?  (Yes,
I'd make a backup before doing anything.)

The result of this would be that, now and for all time, our 'svn log'
output would be consistent in its vertical spacing.

To those interested in log message templates: please note that this
has nothing to do with them.  The problem being solved here is
different, and probably impossible to solve via any template system.

-Karl

-- 
www.collab.net  <>  CollabNet  |  Distributed Development On Demand

kfogel@tigris.org writes:
> Author: kfogel
> Date: Fri Mar  3 15:33:50 2006
> New Revision: 18705
> 
> Added:
>    trunk/tools/hook-scripts/log-police.py   (contents, props changed)
> Modified:
>    trunk/tools/hook-scripts/README
> 
> Log:
> Add a pre-commit hook script to alleviate issue #1870 (svn adds an
> extra blank line to log messages).  While this does not fix the issue,
> it can at least make 'svn log' output look consistent.
> 
> Review by: jerenkrantz
>            danderson
>            djames
> 
> * tools/hook-scripts/log-police.py: New file.
> 
> * tools/hook-scripts/README: Describe it.
> 
> 
> Modified: trunk/tools/hook-scripts/README
> Url: http://svn.collab.net/viewcvs/svn/trunk/tools/hook-scripts/README?rev=18705&p1=trunk/tools/hook-scripts/README&p2=trunk/tools/hook-scripts/README&r1=18704&r2=18705
> ==============================================================================
> --- trunk/tools/hook-scripts/README	(original)
> +++ trunk/tools/hook-scripts/README	Fri Mar  3 15:33:50 2006
> @@ -40,4 +40,8 @@
>        Checks whether the contents of PO files committed to the repository
>        are encoded in UTF-8.
>  
> +   8. log-police.py
> +      Ensures that log messages end with exactly one newline.  Can
> +      also be run as a standalone script to fix up old revisions.
> +
>  $Id$
> 
> Added: trunk/tools/hook-scripts/log-police.py
> Url: http://svn.collab.net/viewcvs/svn/trunk/tools/hook-scripts/log-police.py?rev=18705
> ==============================================================================
> --- (empty file)
> +++ trunk/tools/hook-scripts/log-police.py	Fri Mar  3 15:33:50 2006
> @@ -0,0 +1,139 @@
> +#!/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)
> +      usage(sys.stderr)
> +      sys.exit(1)
> +
> +  if txn_name is not None and rev_name is not None:
> +    sys.stderr.write("ERROR: Cannot pass both -t and -r.\n\n")
> +    usage(sys.stderr)
> +    sys.exit(1)
> +
> +  if txn_name is not None and all_revs:
> +    sys.stderr.write("ERROR: Cannot pass --all-revs with -t.\n\n")
> +    usage(sys.stderr)
> +    sys.exit(1)
> +
> +  if rev_name is not None and all_revs:
> +    sys.stderr.write("ERROR: Cannot pass --all-revs with -r.\n\n")
> +    usage(sys.stderr)
> +    sys.exit(1)
> +
> +  if rev_name is None and txn_name is None and not all_revs:
> +    usage(sys.stderr)
> +    sys.exit(1)
> +
> +  if len(args) > 1:
> +    sys.stderr.write("ERROR: only one argument allowed (the repository).\n\n")
> +    usage(sys.stderr)
> +    sys.exit(1)
> +    
> +  repos_path = 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
> +
> +
> +def usage(outfile=sys.stdout):
> +  outfile.write("USAGE: %s [-t TXN_NAME | -r REV_NUM | --all-revs] REPOS\n"
> +                % (sys.argv[0]))
> +  outfile.write(
> +    "\n"
> +    "Ensure that log messages end with exactly one newline and no\n"
> +    "other whitespace characters.  Use as a pre-commit hook by passing\n"
> +    "'-t TXN_NAME'; fix up a single revision by passing '-r REV_NUM';\n"
> +    "fix up all revisions by passing '--all-revs'.  (When used as a\n"
> +    "pre-commit hook, may modify the svn:log property on the txn.)\n")
> +
> +
> +if __name__ == '__main__':
> +  sys.exit(svn.core.run_app(main, sys.argv))
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: svn-help@subversion.tigris.org
> 
> 

-- 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Julian Foad wrote:
> Max Bowsher wrote:
>> kfogel@collab.net wrote:
>>> Max Bowsher <ma...@ukf.net> writes:
>>>
>>>> Additionally, I feel that deciding that it is useful enough to warrant
>>>> installation on our own repository is logically irreconcilable with a
>>>> decision to keep the functionality out of the Subversion core code.
>>>
>>> That I don't get.  *Every* hook running in our repository implements
>>> something we decided not to put in core Subversion.  I don't see how
>>> this one is any different.  Deciding to enforce certain log message
>>> conventions for our project doesn't mean we think all other projects
>>> in the world should use them.
>>>
>>> In short: huh? :-)
>>
>> What I mean is:
>> As I understand it (possibly incorrectly), we haven't put this
>> functionality into core because we deem it to be of niche interest, and
>> not important for the majority of repositories.
>>
>> Now, if we consider ourselves to be an example of a typical project
>> using Subversion source control (do we? I'd tend to assume we do), then
>> if we are interested in log canonicalization, that conflicts with the
>> supposition that log canonicalization is of niche interest.
> 
> How do you respond to Karl's point that it's the same situation for
> every hook we run, yet presumably we're happy to run the others?  (I
> don't even know what hooks we are running, but I expect you do.)

I don't, not in full, anyway. But for the two I do know of, I respond as
follows:

mailer.py: is different from this case, in that it fulfils a need that,
whilst common, has a myriad variations, instead of simply do/don't
canonicalize.

verify-po.py: Fulfils a project-policy-specific need.

Max.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFED4J+fFNSmcDyxYARAipfAKCd7W/ujEUbs/G7PjvPUnBEt1DbjgCgt+Zz
jIGnp8RL3wEsKta3s24QOuk=
=FddZ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Julian Foad <ju...@btopenworld.com>.
Max Bowsher wrote:
> kfogel@collab.net wrote:
>>Max Bowsher <ma...@ukf.net> writes:
>>
>>>Additionally, I feel that deciding that it is useful enough to warrant
>>>installation on our own repository is logically irreconcilable with a
>>>decision to keep the functionality out of the Subversion core code.
>>
>>That I don't get.  *Every* hook running in our repository implements
>>something we decided not to put in core Subversion.  I don't see how
>>this one is any different.  Deciding to enforce certain log message
>>conventions for our project doesn't mean we think all other projects
>>in the world should use them.
>>
>>In short: huh? :-)
> 
> What I mean is:
> As I understand it (possibly incorrectly), we haven't put this
> functionality into core because we deem it to be of niche interest, and
> not important for the majority of repositories.
> 
> Now, if we consider ourselves to be an example of a typical project
> using Subversion source control (do we? I'd tend to assume we do), then
> if we are interested in log canonicalization, that conflicts with the
> supposition that log canonicalization is of niche interest.

How do you respond to Karl's point that it's the same situation for every hook 
we run, yet presumably we're happy to run the others?  (I don't even know what 
hooks we are running, but I expect you do.)

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by kf...@collab.net.
Max Bowsher <ma...@ukf.net> writes:
> What I mean is:
> As I understand it (possibly incorrectly), we haven't put this
> functionality into core because we deem it to be of niche interest, and
> not important for the majority of repositories.

I'm not sure I agree with the lemma, yeah.

I think we didn't put this functionality into core because we didn't
have the guts to make the call when we should have.  Now it's a
compatibility issue, so we're left with a hook as next best choice.

-Karl

-- 
www.collab.net  <>  CollabNet  |  Distributed Development On Demand

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kfogel@collab.net wrote:
> Max Bowsher <ma...@ukf.net> writes:
>> I vote -0.5 on this.
>>
>> I feel that this issue is so irrelevant, the benefits provided so
>> negligible, that the additional possibilities for problems, and
>> additional administrator time, however small they may be, are not justified.
> 
> Okay.  I disagree, but it's largely a matter of taste and I can't
> really say anything that would make your -0.5 come down (uh, go up).
> 
>> Additionally, I feel that deciding that it is useful enough to warrant
>> installation on our own repository is logically irreconcilable with a
>> decision to keep the functionality out of the Subversion core code.
> 
> That I don't get.  *Every* hook running in our repository implements
> something we decided not to put in core Subversion.  I don't see how
> this one is any different.  Deciding to enforce certain log message
> conventions for our project doesn't mean we think all other projects
> in the world should use them.
> 
> In short: huh? :-)

Well, can't get much shorter than that! :-)

What I mean is:
As I understand it (possibly incorrectly), we haven't put this
functionality into core because we deem it to be of niche interest, and
not important for the majority of repositories.

Now, if we consider ourselves to be an example of a typical project
using Subversion source control (do we? I'd tend to assume we do), then
if we are interested in log canonicalization, that conflicts with the
supposition that log canonicalization is of niche interest.

Max.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFED3rUfFNSmcDyxYARAgm6AJ9EIbr9C9ibyxinMWCIPMlg6r3vIACfS6yL
TsybTGC7vSBsHlla5Jf9klo=
=mYk0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by kf...@collab.net.
Max Bowsher <ma...@ukf.net> writes:
> I vote -0.5 on this.
> 
> I feel that this issue is so irrelevant, the benefits provided so
> negligible, that the additional possibilities for problems, and
> additional administrator time, however small they may be, are not justified.

Okay.  I disagree, but it's largely a matter of taste and I can't
really say anything that would make your -0.5 come down (uh, go up).

> Additionally, I feel that deciding that it is useful enough to warrant
> installation on our own repository is logically irreconcilable with a
> decision to keep the functionality out of the Subversion core code.

That I don't get.  *Every* hook running in our repository implements
something we decided not to put in core Subversion.  I don't see how
this one is any different.  Deciding to enforce certain log message
conventions for our project doesn't mean we think all other projects
in the world should use them.

In short: huh? :-)

-K

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Philip Martin <ph...@codematters.co.uk>.
Max Bowsher <ma...@ukf.net> writes:

> kfogel@collab.net wrote:
>> So, I'd like to install log-police.py (see r18705) as a pre-commit
>> hook in Subversion's own repository, and also use it to clean up all
>> the old log messages.

I don't mind whether or not the script gets installed, nor whether or
not it gets run on existing revisions.

> Additionally, I feel that deciding that it is useful enough to warrant
> installation on our own repository is logically irreconcilable with a
> decision to keep the functionality out of the Subversion core code.

I disagree -- if we determine that a script it the correct way to
address this "problem" then installing such a script in the Subversion
repository is perfectly acceptable.

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kfogel@collab.net wrote:
> So, I'd like to install log-police.py (see r18705) as a pre-commit
> hook in Subversion's own repository, and also use it to clean up all
> the old log messages.  As it doesn't trigger the post-revprop-change
> hook, no one would receive mails about those cleanups.  But since this
> wouldn't affect the real content of log messages, it would just ensure
> that each log message ends with exactly one newline, not seeing those
> silly little diffs is just fine by me.  Thoughts, objections?  (Yes,
> I'd make a backup before doing anything.)
> 
> The result of this would be that, now and for all time, our 'svn log'
> output would be consistent in its vertical spacing.


I vote -0.5 on this.

I feel that this issue is so irrelevant, the benefits provided so
negligible, that the additional possibilities for problems, and
additional administrator time, however small they may be, are not justified.

Additionally, I feel that deciding that it is useful enough to warrant
installation on our own repository is logically irreconcilable with a
decision to keep the functionality out of the Subversion core code.

Max.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFECMjHfFNSmcDyxYARAiDyAKCFwBdou3Bw4XV6MMBY6qWiYPJaFQCg27Bq
m7B1/jW+t3yICE+gQaFBeeY=
=ZMHy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by kf...@collab.net.
Max Bowsher <ma...@ukf.net> writes:
> > Is
> > there a command line equivalent (svnadmin or svnlook) for python's
> > svn.fs.svn_fs_change_txn_prop?
> 
> No.

There's 'svnlook log' and 'svnadmin setlog'.  The latter doesn't
appear to take a '-t TXN' option, if its help is to be believed, but
it would be pretty easy to add it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alan Barrett wrote:
> On Fri, 03 Mar 2006, kfogel@collab.net wrote:
>> So, I'd like to install log-police.py (see r18705) as a pre-commit
>> hook in Subversion's own repository, and also use it to clean up all
>> the old log messages.
> 
> Hmm.  I have been doing that sort of thing in a post-commit hook because
> I thought it was impossible to change things in a pre-commit hook.

You can change txn/rev-props. Nothing else, though.

> Is
> there a command line equivalent (svnadmin or svnlook) for python's
> svn.fs.svn_fs_change_txn_prop?

No.

Max.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFECXpAfFNSmcDyxYARAoLmAKCs1Je6m7LsIQqz78eOSBwdL0KyFACfYtNL
4UpsswpmJ3wZYBB2LavWwHE=
=owY1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by Alan Barrett <ap...@cequrux.com>.
On Fri, 03 Mar 2006, kfogel@collab.net wrote:
> So, I'd like to install log-police.py (see r18705) as a pre-commit
> hook in Subversion's own repository, and also use it to clean up all
> the old log messages.

Hmm.  I have been doing that sort of thing in a post-commit hook because
I thought it was impossible to change things in a pre-commit hook.  Is
there a command line equivalent (svnadmin or svnlook) for python's
svn.fs.svn_fs_change_txn_prop?

--apb (Alan Barrett)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by "C. Michael Pilato" <cm...@collab.net>.
C. Michael Pilato wrote:
> And I didn't feel good about sending this reply without at least
> checking out the log-police.py script for myself, and now I've gone and
> blown *another* 10 minutes making fixes and cleanups to that thing
> (r187398).

That's r18738.  Sorry.

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand

Re: Installing log-police.py in Subversion's repository.

Posted by kf...@collab.net.
"C. Michael Pilato" <cm...@collab.net> writes:
> kfogel@collab.net wrote:
> > So, I'd like to install log-police.py (see r18705) as a pre-commit
> > hook in Subversion's own repository, and also use it to clean up all
> > the old log messages.
> 
> What about pre-revprop-change?

Good point; it'd need some (small) modification to work there too.

> Crap.  And I didn't feel good about sending this reply without at least
> checking out the log-police.py script for myself, and now I've gone and
> blown *another* 10 minutes making fixes and cleanups to that thing
> (r187398).
> 
> -0 on installation at svn.collab.net.
> -1 on this topic eating up any more of any committer's valuable time.

Hah :-).

I like your changes, but let's face it, they are to log-police.py what
log-police.py is to Subversion as a whole.  Which just goes to prove
that I've found the ultimate time suck for Subversion committers,
something I've been searching for for six years...

<ducks>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Installing log-police.py in Subversion's repository.

Posted by "C. Michael Pilato" <cm...@collab.net>.
kfogel@collab.net wrote:
> So, I'd like to install log-police.py (see r18705) as a pre-commit
> hook in Subversion's own repository, and also use it to clean up all
> the old log messages.

What about pre-revprop-change?

> The result of this would be that, now and for all time, our 'svn log'
> output would be consistent in its vertical spacing.

This is suuuuuuuuuuuuch a non-issue.  I've lost more time reading and
deleting that thread, the commit mails, and now this follow-up thread
than I've ever spent in annoyance that, *gasp*, there's extra whitespace
in my 'svn log' output!  (The horror!)

[minutes later]

Crap.  And I didn't feel good about sending this reply without at least
checking out the log-police.py script for myself, and now I've gone and
blown *another* 10 minutes making fixes and cleanups to that thing
(r187398).

-0 on installation at svn.collab.net.
-1 on this topic eating up any more of any committer's valuable time.

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand