How to recursively add files and directories in GNU Arch

Last week we moved from Subverion to GNU Arch. Why? I’ll try to explain in next posts. So, we needed to import our project (it contains many files and directories) in the new Arch repository. Leonid created a shell script to do that. But I’ve found easier (IMHO) way to do that.


tla inventory --source --names | xargs tla add

P.S. If you have some files in the Arch repository and some of them no you can do as indicated above. But in that case you’ll see warnings about already added files and directories. To avoid it run following command:

tla tree-lint --untagged-files | xargs tla add

How remove leading zeros

The most efficient way to remove leading zeros from some number is add to that number 0:

      1 #! /usr/bin/perl -w
2
3 use strict;
4 use Benchmark;
5
6 my $test = '000000000000001';
8 timethese shift,
9 {
10 Add => sub { my $num = $test; $num += 0 },
11 Regex => sub { my $num = $test; $num =~ s/^0+// },
12 Sprintf => sub { my $num = $test; $num = sprintf '%d', $num },
13 };

Benchmark: timing 10000000 iterations of Add, Regex, Sprintf…
Add: 26 wallclock secs (17.68 usr + 0.06 sys = 17.74 CPU) @ 563697.86/s (n=10000000)
Regex: 48 wallclock secs (38.32 usr + 0.09 sys = 38.41 CPU) @ 260348.87/s (n=10000000)
Sprintf: 43 wallclock secs (34.78 usr + 0.10 sys = 34.88 CPU) @ 286697.25/s (n=10000000)

My Wishlist

Last update at 08/01/2010

Gadgets

A/V equipment

Computer Parts

Сlothes

tar: Howto Exclude or Include Files

Recently I’ve had a little problem. I’ve needed to create an archive from some source directories but I’ve not needed to add in the archive some subdirectorives. I’ve made a quick search in Google and found an article “Telling tar Which Files to Exclude or Include”. Here is a short example:


$ find videoguide/ ! -type d -print | egrep '/,|%$|~$|.jpg$|.gif$|.png$' > /tmp/exclude_files

That command forms a list of excluded files and store it into temporary file.

$ tar vcfX ~/projects/arc/vg-19012004.tar /tmp/exclude_files

will remove files which listed into excluded_files from archive.

Updated: There is a more simple way to exclude file/dir from the archive. You can define a pattern in the command line instead of creation a file. Let’s image that we need to exclude Subversion directories from the archive:
tar vzcf my-project.tar.gz --exclude='.svn' ProjectDir
Note: you should always wrap the pattern by quotes!