📜 ⬆️ ⬇️

Smart export from SVN using console

I started using svn, working in windows and, accordingly, used TortoiseSVN as a client.
At that time, I was very pleased with the new feature described in the article Smart export from SVN using TortoiseSVN .
I recently did something that had not been done for a long time - I put linux on my work computer.
And so bad luck, in one of the graphical clients I tested, I did not find similar functionality.
Little of. After reading svn --help did not find the option that gives such a result.
It's a shame. Given that the department has already trained to make such exports for the smooth updating of projects.
In general, I will not pull: I wrote a script on bash that implements the comparison and export of differences between two revisions.


Code


  #! / bin / bash

 if [$ # -lt 2];  then
  echo "usage: start_revision end_revision [project_name]"
  exit 0
 fi

 dir_prefix = '! UPDATES /'
 svn_repo = 'svn: // <svn_host>: <svn_port>'


 if [[$ 3! = '']]
     then
         project = $ svn_repo '/' $ 3 '/'
     fi
 revision_start = $ 1
 revision_end = $ 2

 files = `svn diff --summarize -r $ revision_start: $ revision_end $ project |  awk '{print \ $ 2}' `
 echo "svn diff --summarize -r $ revision_start: $ revision_end $ project | awk '{print \ $ 2}'"
 declare -a filelist
 i = 0
 for file in $ files;
 do
     dir = ""
     filelist [$ i] = `echo $ file |  sed -e 's / \ // \ n / g'`
     j = 0
     declare -a items
     for item in $ {filelist [$ i]};
     do
         items [$ j] = $ item
         j = `echo $ j + 1 |  bc`
     done

     #create dirs
     j = 0
     cur_dir = "'
     els_count = `echo $ {# items [@]} - 1 |  bc`
     for ditem in $ {items [@]};
     do
         if [[$ j = $ els_count]] #if lat element - it's filename
         then
             #store filename
             file_name = $ ditem
             break
         fi
         cur_dir = $ cur_dir $ ditem '/'
         j = `echo $ j + 1 |  bc`
     done
     dir = $ {dir_prefix} `date +% Y-% m-% d` '/' $ {revision_end} '/' $ cur_dir
     mkdir -p $ dir

     #export files in created dirs
     svn export -r $ revision_end $ project $ file ./$dir$file_name

     i = `echo $ i + 1 |  bc`
 done 


Customization


Register the host on which the svn-server is located.
')

Using


  1. Type in the directory with the working copy <script name> <initial revision> <final revision>
  2. Or type in arbitrary directory <script name> <initial revision> <final revision> <path inside repository>


As a result, the directory! UPDATES / current date / number of the final revision / appears in the current directory, in which there will be changes between these revision numbers taking into account the nesting of the directories.

Use. =)

Source: https://habr.com/ru/post/46266/


All Articles