This page shows how to extract one version back from
svn
on given file.
-
The scripts gets a file name. It uses the command
svn log to extract one version back, and
overwrites the file with this version.
On a tcsh, I use the following command to run the
script on a list of files:
-
cat ~/my_txt/my_svn_log.txt | xargs -n1 | xargs -t -i= ~/bin/svn_one_ver_back.unx =
-
The script is shown below:
- #!/bin/bash
- #\.\/\([a-zA-Z].*\) r[0-9]* .*
- svn_ver=`svn log $1 | grep "^r[0-9]* " | head -2 | tail -1 | perl -e 'while (<STDIN>) {$t=index($_, " ");$s=substr($_, 0, $t);print("$s\n");};'`
- svn cat -r $svn_ver $1 > $1
-
Note, that bash script calls perl in one
line command invocation.
-
Now suppose you want to change reveisions listed in
a given file.
This file contains the target files and their
new revisions. In my case
the file was created by the following
script.
The output of this script looks like:
- Tue Nov 6 09:39:52 IST 2012
- ./main_data/Clib/init.c r2 | dkuku | 2012-06-25 16:21:34 +0300 (Mon, 25 Jun 2012) | 1 line
- ./main_data/Clib/dbg_cmd.c r2 | dkuku | 2012-06-25 16:21:34 +0300 (Mon, 25 Jun 2012) | 1 line
- ...
My idea is to take each line from the file,
extract its name and version and update.
This can be achieved by the following script:
- #!/bin/bash
- #restores to tag
- #~/bin/svn_tag.unx ~/restricted/my_svn_log_24779.txt
- OIFS="$IFS" #see below on IFS
- IFS=$'\n'
- for li in `cat $1 | grep " r[0-9]* "`; do
- svn_ver=`echo $li | perl -e 'while (<STDIN>) {$t=index($_, " r");$s=substr($_, $t);$t=index($s, " |");$s=substr($s, 0, $t);print("$s\n");};'`
- f=`echo $li | perl -e 'while (<STDIN>) {$t=index($_, " r");$s=substr($_, 0, $t);print("$s\n");};'`
-
- echo "file: "$svn_ver" version: "$f
- svn cat -r $svn_ver $f > $f
- done
- IFS="$OIFS"
Note that the bash scripts calls perl to extract
some fields.
|