2011-09-07 12 views
6

Come è possibile esportare i file modificati in SVN modificati tra due revisioni. Ho bisogno di una soluzione tramite la riga di comando o utilizzando qualsiasi script (con una struttura di cartelle adeguata). Inoltre, ho bisogno di una soluzione basata su Windows.Come esportare i file modificati tra due revisioni SVN

ad es. sth come:

export {svn diff --summarize -r 50:HEAD} 

voglio un albero di directory con una copia dei file che in cui ha cambiato in qualsiasi revisione da 50 a

+0

Che cosa stai chiedendo esattamente? Potresti fornire un esempio di ciò che stai cercando di fare? – Pedro

+0

appena aggiunto un esempio di cosa sto cercando –

+0

Che cosa intendi con esportazione? Vuoi un albero di directory con una copia dei file che sono stati modificati in qualsiasi revisione da 50 in poi? – Matteo

risposta

10

Per quanto ne so, svn non fornisce tale funzionalità. Ma puoi scrivere un semplice programma C# usando SharpSVN per farlo. Ecco un esempio che puoi usare. In questo esempio, sto ottenendo tutto cambiato file da revisione 100 a 200.

using SharpSvn; 
using System.IO; 
using System.Collections.ObjectModel; 
using Microsoft.VisualBasic; 

namespace SvnDiffExporter 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      SvnClient client = new SvnClient(); 
      SvnRevisionRange range = new SvnRevisionRange(100, 200); 
      MemoryStream result = new MemoryStream(); 

      Collection<SvnLogEventArgs> items; 
      SvnLogArgs logargs = new SvnLogArgs(range); 
      client.GetLog(@"e:\Artifacts", logargs, out items); 

      int i = 0; 
      string [] path = new string[255]; 
      foreach (SvnLogEventArgs ar in items) 
      { 
       foreach (SvnChangeItem changeitem in ar.ChangedPaths) 
       { 
        if (changeitem.Action != SvnChangeAction.Delete) 
        { 
         path[i] = changeitem.Path; 
         i++; 
        } 
       } 
      } 

      string localpath = @"c:\data"; 
      foreach (string str in path) 
       client.Export(str, localpath); 
     } 
    } 
} 
+0

la tua soluzione risolverà i miei problemi, controllerò e posterò –

0

Se ho capito la tua domanda correttamente, è un Non sono interessato a una patch globale tra le revisioni. In questo caso, è necessario esportare ogni revisione in una directory separata, quindi utilizzare uno strumento come Beyond Compare (o qualcosa di equivalente come WinMerge) per identificare i file modificati.

Tuttavia, se la directory di compilazione è sotto controllo di versione, sarebbe meglio creare una patch e applicarla su di essa.

+0

, per favore, mi dia un esempio –

1

Ecco un altra opzione scritto in script bash:

#!/bin/bash 

############################## 
# settings and inicilization # 
############################## 

SVN_SOURCE="https://svn.example.com/trunk/" 
REV_PATH="/var/www/revisions/example.com/" 

TIME_SPENT=$(date +%s) 
REV=$(svn info $SVN_SOURCE | grep Revision | cut -d ' ' -f 2) 
PREV=0 
VERBOSIVE=0 

USAGE_INFO="$(basename "$0") [-r REVISION_NUM] [-i PREVIOUS_REVISION_NUM] -- make an incremental svn export 

where: 
    -i previous revision (default: 0) 
    -h show this help text 
    -r revision to export (default: $REV) 
    -v verbosive mode. show fetched files 

current settins: 
    SVN_SOURCE: $SVN_SOURCE 
    REV_PATH: $REV_PATH 
" 

while getopts r:i:hv option; do 
    case "$option" in 
    i) PREV=$OPTARG 
     ;; 
    h) echo "$USAGE_INFO" 
     exit 
     ;; 
    r) REV=$OPTARG 
     ;; 
    v) VERBOSIVE=1 
     ;; 
    esac 
done 

EV_PATH=$REV_PATH$REV"/" 

############################## 
#   functions   # 
############################## 

promtYesOrDie(){ 
    while true; do 
    read -e -p "$1 (y/n): " -i "y" yn 
    case $yn in 
     [Yy]) break;; 
     [Nn]) echo "spent: "$((`date +%s` - $TIME_SPENT))"s" 
      echo "bye bye" 
      exit 
      ;; 
     *) echo "Please answer (y)es or (n)o.";; 
    esac 
    done 
} 

doIncrementalExport(){ 
    PREV_PATH=$REV_PATH$PREV"/" 
    if [ -d $PREV_PATH ]; then 
    echo "copying files from: $PREV_PATH" 
    cp -f -r "$PREV_PATH." $EV_PATH 
    echo "fetching added and modified files since revision $PREV..." 
    for FILE_SRC in $(svn diff --summarize -r $PREV:$REV $SVN_SOURCE | awk '/[AM]/ {print $2}'); do 
     FILE_PATH=$(echo $FILE_SRC | sed -e "s{$SVN_SOURCE{{"); 
     if [ ! -d "$EV_PATH$FILE_PATH" ]; then 
     TRG_DIR="$EV_PATH$(dirname $FILE_PATH)" 
     mkdir -p $TRG_DIR 
     svn export -r$REV -q --force $FILE_SRC "$EV_PATH$FILE_PATH" 
     if [ $VERBOSIVE -eq 1 ]; then 
      echo "$EV_PATH$FILE_PATH" 
     fi 
     fi 
    done 
    echo "removing deleted files and folders since revision $PREV ..." 
    for FILE_SRC in $(svn diff --summarize -r $PREV:$REV $SVN_SOURCE | awk '/D/ {print $2}'); do 
     FILE_PATH=$(echo $FILE_SRC | sed -e "s{$SVN_SOURCE{{"); 
     rm -r "$EV_PATH$FILE_PATH" 
     if [ $VERBOSIVE -eq 1 ]; then 
     echo "$EV_PATH$FILE_PATH" 
     fi 
    done 
    else 
    echo "previous revision does not exist at: $PREV_PATH" 
    exit; 
    fi 
} 

############################## 
#  main function  # 
############################## 

if [ $PREV -eq 0 ]; then 
    promtYesOrDie "Do you want to do full export instead of incremental, for revision $REV of repo: [$SVN_SOURCE]" 
    echo "fatching source ..." 
    if [ $VERBOSIVE -eq 1 ]; then 
    svn export -r$REV --force $SVN_SOURCE $EV_PATH 
    else 
    svn export -r$REV -q --force $SVN_SOURCE $EV_PATH 
    fi 
else 
    promtYesOrDie "Do you want to do incremental export, for revision renge $PREV:$REV of repo: [$SVN_SOURCE]" 
    doIncrementalExport 
fi 

echo "spent: "$((`date +%s` - $TIME_SPENT))"s" 
echo [done] 

Io uso the complete scrip fare un export svn incrementale su un ambiente di produzione LAMP.

4

Ho creato un file batch che funzionerà per esportare i file modificati tra le revisioni.

@echo off 

FOR /F "tokens=1,2" %%I IN ('svn diff --summarize -r %1') DO (
    IF NOT %%I == D (
     IF NOT EXIST %2\%%J\.. mkdir %2\%%J\.. 

     svn export --depth empty -q --force %%J %2\%%J 
     echo %2\%%J 
    ) 
) 

Per utilizzarlo è sufficiente specificare la revisione o l'intervallo di revisione sulla riga di comando e una destinazione per i file esportati.

C:\YourRepository>svnexport.bat 1:10 C:\Export 
Problemi correlati