Introduction

At check-out time, Subversion expands text like:

$HeadURL$ 

to something like:

$HeadURL: svn+ssh://dione.no-ip.org/diska/svn-repos/ahdg/trunk/doc/ahdg.lyx $ 

(assuming the svn:keywords property has been set appropriately).

At check-in time the expansion is reversed so as to leave the version in the repository in a consistent state.

LyX splits text in .lyx files to ensure line length is not excessively long. This means that the above line, although it is displayed and printed correctly by LyX, may actually be stored as this:

$HeadURL: svn+ssh://dione.no-ip.org/diska/svn-repos/ahdg/trunk/doc/ahdg.lyx
 $ 

This line-splitting will prevent Subversion from reversing the expansion at check-in time and thereafter the expansion will fail at check-out time.

According to http://svnbook.red-bean.com/en/1.4/svn.reposadmin.create.html#svn.reposadmin.create.hooks, it is a bad idea to use Subversion hooks to correct problems in a transaction because the client-side caches become misaligned with what is in the server-side repository.

It is possible to use a pre-commit hook to refuse to accept .lyx files with split svn keywords, but it is still up to the user, not the server, to correct the problem.

Procedure

  1. Create .../<svn-repo-dir>/hooks/pre-commit containing:

    #!/usr/bin/env perl
    $repos = $ARGV[0];
    $txn = $ARGV[1];
    $rc = 0; #  assume success till proven otherwise
    foreach $ch (`svnlook changed -t "$txn" "$repos"`) {
        chomp($ch);
        next if ($ch !~ /^[AU]\S*\s+(\S.*)$/);
        $fn = $1;
        next if ($fn !~ /\.lyx$/);
        $cntnt = scalar(`svnlook cat -t "$txn" "$repos" "$fn"`);
        foreach $kw (qw/LastChangedDate LastChangedRevision LastChangedBy HeadURL Id/) {
            next if ($cntnt !~ /\$$kw:\s*\S+\s*\n\s*\$/);
            print STDERR "$0: ERROR: split '$kw' keyword\n";
            $rc = 1;
        }
    }
    exit($rc); 
    (This will prevent split lines being committed.)
  2. Make the hook script executable with:

    chmod 755 .../<svn-repo-dir>/hooks/pre-commit 
  3. Take a backup copy of your .lyx document.
  4. Run the command:

    perl -0777 -pi -e 's/\$(LastChangedDate|LastChangedRevision|LastChangedBy|HeadURL|Id):\s*(\S+)\s*\n\s*\$/\$$1: $2 \$/msg' *.lyx 
  5. Alternatively put this in a Makefile:

    commitable:
            perl -0777 -pi -e 's/\$$(LastChangedDate|LastChangedRevision|LastChangedBy|HeadURL|Id):\s*(\S+)\s*\n\s*\$$/\$$$$1: $$2 \$$/msg' *.lyx 

    (That's a TAB at the beginning of the second line!) and run:

    make 

See also


CategoryProcedure

CorrectingSvnKeywordsInLyxDocuments (last edited 2011-09-26 19:12:58 by AlexisHuxley)