File: svn-inject

package info (click to toggle)
svn-buildpackage 0.6.7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 232 kB
  • ctags: 34
  • sloc: perl: 1,202; makefile: 75
file content (267 lines) | stat: -rwxr-xr-x 8,212 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/perl
# (c) Eduard Bloch <blade@debian.org>, 2003
# License: GPL

use Getopt::Long qw(:config no_ignore_case bundling);
use File::Basename;
use Cwd;

$basedir=getcwd;
$scriptname="[svn-inject]";

sub help {
        print <<END
Usage: svn-inject [options] <package>.dsc [ <repository URL> ]
Options: 
  -h           print this message
  -v           Make the commands verbose
  -q           Don't show command calls
  -l <digit>   Layout type (1=pkg/function, 2=function/pkg/)
                           (2 not implemented yet)
  -t <string>  Directory where you like to store the .orig files
  -o           Only keep modified files under SVN control (experimental)
  -c <digit>   Checkout the tree after injecting 
               (0=don't do, 1=trunk only (default), 2=complete tree)
  -d <string>  Do-Like-OtherPackage feature. Looks at a local working
               directory, removes lastword/trunk from its URL and uses 
               the result as base URL

If the base repository URL is omited, svn-inject tries to get it from
the current directory. In this case, -c becomes ineffective.

END
;
exit 1;
}

chomp($tempdir=`mktemp -d`);

my $initial_run;
my $opt_debug;
my $opt_svnurl;
my $opt_layout;
my $opt_quiet;
my $opt_tardir;
my $opt_checkout=1;
my $opt_dolike;

# parse Command line
%options = (
   "h|help"                => \$opt_help,
   "v|verbose"             => \$opt_verbose,
   "q|quiet"             => \$opt_quiet,
   "t=s"                     => \$opt_tardir,
   "d=s"                     => \$opt_dolike,
   "l=i"                     => \$opt_layout,
   "o"                     => \$opt_onlychanged,
   "c=i"                   => \$opt_checkout
);

&help unless ( GetOptions(%options));
&help if ($opt_help);
&help if $#ARGV < 0;

use lib "/usr/share/svn-buildpackage";
use SDCommon;
$ENV{"SVN_BUILDPACKAGE"} = $SDCommon::version;
$SDCommon::opt_verbose=$opt_verbose;

$opt_dsc=$ARGV[0];
my $use_this_repo;
my $opt_svnurl;

if($opt_dolike) {
   $opt_svnurl=url($opt_dolike);
   ($opt_svnurl=~s/\/[^\/]+\/trunk$//) or die "Failed to extract the base URL, maybe not in layout type 2?\n";
   $basedir=long_path(dirname($opt_dolike));
   open(dl,"$opt_dolike/.svn/deb-layout");
   while(<dl>) {if(/^origDir\s*=\s*(.*)/) {$opt_tardir=$1; last;} }
   print "Got base URL: $opt_svnurl\n";
   print "Working directory goes to $basedir/\n";
   print "Tarball to $opt_tardir/ or so...\n";
   $opt_onlychanged = length(`svn proplist $opt_dolike/debian | grep mergeWithUpstream`);
}
else {
   $opt_svnurl=$ARGV[1];
   $opt_svnurl=~s,/$,,;
   if(! defined($opt_svnurl)) {
      # we use the current directory and its reflection in the repository as
      # base for the package tree
      $use_this_repo=1;
      $opt_svnurl=url(".");
   }

   if(! ($opt_dsc && $opt_svnurl)) {
      die "Need two arguments: <dsc file> <SVN url>\n";
   }
}

die "Dsc file not readable!\n" if (! -r $opt_dsc);

$opt_dsc = long_path($opt_dsc);

$SVN_QUIET="-q";
#$TAR_QUIET="";
$PATCH_QUIET="--silent";

if($opt_verbose) {
   undef $SVN_QUIET;
   $TAR_QUIET="-v";
   $PATCH_QUIET="";
}

$SDCommon::opt_quiet=$opt_quiet;


open($dsc, "<$opt_dsc");
while(<$dsc>) {
   # NEVER USE abs_path HERE, it resolves the links
   $package=$1 if(/^Source: (.+)\n/);
#   $dscVersion = $1 if(/^Version: (\S+)\n/);
   $dscOrig = dirname($opt_dsc)."/$1" if(/^\s\w+\s\d+\s(.+orig.tar.gz)\n/);
   $dscDiff = dirname($opt_dsc)."/$1" if(/^\s\w+\s\d+\s(.+\.diff.gz)\n/);
#   $dscNat  = abs_path($1) if( (!$dscOrig) && /^\s\w+\s\d+\s(.+tar.gz)\n/);
}

if($opt_checkout && -d "$basedir/$package") {
   die "$basedir/$package already exists, aborting...\n";
}

# expanding the paths now, extracting upstream version
if($dscOrig) {
   $dscOrig=long_path($dscOrig);
   $dscBase = basename($dscOrig);
   $dscBase =~ /_(.*)\.orig.t/;
   $upsVersion=$1;
}
$dscDiff=long_path($dscDiff);

if($dscOrig) {
   $opt_tardir=long_path($opt_tardir ? $opt_tardir : "$basedir/tarballs");
   mkdir $opt_tardir if(!-d $opt_tardir);
   withecho "cp", $dscOrig, $opt_tardir;
}

$SDCommon::c{"origDir"}=long_path($opt_tardir);

# creating the list of relevant files for mergeWithUpstream mode
if($opt_onlychanged && $dscDiff) {
   open($dl, "zcat $dscDiff|");
   while(<$dl>) {
      push(@difflist, $1) if(/^\+\+\+\ [^\/]+\/(.+)\n/);
   }
   close($dl);
}

chdir $tempdir;

# preparing a package tree that will be inserted into repository later
if($dscOrig) {
   # prepare the upstream source
   withecho "mkdir", "-p", "$package/branches/upstream";
   chdir "$package/branches/upstream";
   withecho "tar", $TAR_QUIET, "-z", "-x", "-f", $dscOrig;
   oldSvnDirsCheck ".";
   @filesInside=(<*>);
   if(@difflist) {
      if($#filesInside > 0) {
         mkdir $upsVersion;
      }
      withecho("mv",@filesInside, $upsVersion);
      #  withecho "mv * $upsVersion";
      mkdir "current";
      chdir $upsVersion;
      withecho("tar $TAR_QUIET -c ".join(' ',@difflist)." 2>/dev/null | tar x $TAR_QUIET -C ../current");
      chdir "..";
      withecho "rm -rf $upsVersion";
   }
   else {
      if($#filesInside > 0) {
         mkdir "current";
      }
      withecho("mv",@filesInside, "current");
      # withecho "mv * current";
   }
}
else {
   # native packages are easier
   mkdir $package;
   chdir $package;
   withecho "dpkg-source -x $opt_dsc";
   system "rm -f *.gz";
   withecho "mv * trunk";
}

chdir $tempdir;

# Final tree prepation before commit, preconfiguring already
mkdir "$package/tags";
$SDCommon::c{"tagsUrl"}="$opt_svnurl/$package/tags";
$SDCommon::c{"upsCurrentUrl"}="$opt_svnurl/$package/branches/upstream/current";
$SDCommon::c{"upsTagUrl"}="$opt_svnurl/$package/branches/upstream";

# go, go, go
withecho "svn $SVN_QUIET import -m\"$scriptname Installing original source of $package\" $package $opt_svnurl/$package";

# for non-native: create the trunk copy from the source and divert it
if($dscOrig) {
   withecho("svn", "-m", "$scriptname Tagging upstream source version of $package", "copy",
   "$opt_svnurl/$package/branches/upstream/current",
   "$opt_svnurl/$package/branches/upstream/$upsVersion", $SVN_QUIET);
   withecho("svn", "-m", "$scriptname Forking $package source to Trunk", "copy",
   "$opt_svnurl/$package/branches/upstream/current",
   "$opt_svnurl/$package/trunk", $SVN_QUIET);
   mkdir "tmp";
   chdir "tmp";
   withecho "dpkg-source -x $opt_dsc";
   system "rm -f *.gz";
   # now use svn_load_dirs to upgrade the trunk fork to Debian versions.
   # For mergeWithUpstream mode, extract the interessting files to a new
   # directory and load this one instead
   if(@difflist) {
      withecho "mv * $upsVersion";
      mkdir "newtrunk";
      chdir $upsVersion; withecho "tar $TAR_QUIET -c ".join(' ',@difflist)." 2>/dev/null | tar $TAR_QUIET -x -C ../newtrunk"; 
      chdir "..";
      withecho "svn_load_dirs $opt_svnurl/$package/trunk . newtrunk";
   }
   else {
      withecho "svn_load_dirs $opt_svnurl/$package/trunk . *";
   }
}

chdir $basedir;
if($use_this_repo) {
   withecho "svn up";
   $trunkdir = "$package/trunk";
}
else {
   if($opt_checkout==2) {
      print "Storing copy of your repository tree in $basedir/$package.\n";
      withecho "svn", "checkout", "$opt_svnurl/$package", "$basedir/$package", $SVN_QUIET;
      $trunkdir = "$basedir/$package/trunk";
   }
   elsif ($opt_checkout==1) {
      print "Storing trunk copy in $basedir/$package.\n";
      withecho "svn", "checkout", "$opt_svnurl/$package/trunk", "$basedir/$package", $SVN_QUIET;
      $trunkdir = "$basedir/$package";
   }
   elsif($opt_onlychanged) {
      # we may still need the trunk directory for workarounds
      # for svn's lack of propset function on remote targets
      withecho "svn", "checkout", "$opt_svnurl/$package/trunk", "$tempdir/trunk", $SVN_QUIET;
      chdir "$tempdir/trunk";
   }
}

chdir $trunkdir if($trunkdir);

if ($opt_onlychanged) {
   withecho "svn propset mergeWithUpstream 1 debian";
   withecho "svn -m\"$scriptname Setting properties of $package/debian/\" commit debian $SVN_QUIET";
}

SDCommon::writeCfg ".svn/deb-layout" if($opt_checkout>0);
print "Done! Removing tempdir.\n";
system "rm -rf $tempdir";
print ("Your working directory is $trunkdir - have fun!\n") if($trunkdir);