Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Applied a patch from Johan Vromans to add the --link option to ttree

  • Loading branch information...
commit 8ab80b344638240a5e022c2d97844d4513aefb44 1 parent 6d79843
@abw authored
Showing with 67 additions and 24 deletions.
  1. +7 −0 Changes
  2. +60 −24 bin/ttree
View
7 Changes
@@ -11,6 +11,13 @@
#========================================================================
#-----------------------------------------------------------------------
+# Version 2.25 - Not yet released
+#------------------------------------------------------------------------
+
+* Applied a patch from Johan Vromans to add the --link option to trree.
+
+
+#-----------------------------------------------------------------------
# Version 2.24 - 8th February 2012
#------------------------------------------------------------------------
View
84 bin/ttree
@@ -15,16 +15,12 @@
# Andy Wardley <abw@wardley.org>
#
# COPYRIGHT
-# Copyright (C) 1996-2003 Andy Wardley. All Rights Reserved.
+# Copyright (C) 1996-2012 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2003 Canon Research Centre Europe Ltd.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
-#------------------------------------------------------------------------
-#
-# $Id$
-#
#========================================================================
use strict;
@@ -71,6 +67,7 @@ my $all = $config->all;
my $libdir = $config->lib;
my $ignore = $config->ignore;
my $copy = $config->copy;
+my $link = $config->link;
my $accept = $config->accept;
my $absolute = $config->absolute;
my $relative = $config->relative;
@@ -78,7 +75,7 @@ my $suffix = $config->suffix;
my $binmode = $config->binmode;
my $depends = $config->depend;
my $depsfile = $config->depend_file;
-my ($n_proc, $n_unmod, $n_skip, $n_copy, $n_mkdir) = (0) x 5;
+my ($n_proc, $n_unmod, $n_skip, $n_copy, $n_link, $n_mkdir) = (0) x 6;
my $srcdir = $config->src
|| die "Source directory not set (-s)\n";
@@ -193,6 +190,7 @@ if ($verbose) {
"Include Path: [ @$libdir ]\n",
" Ignore: [ @$ignore ]\n",
" Copy: [ @$copy ]\n",
+ " Link: [ @$link ]\n",
" Accept: [ @$accept ]\n",
" Suffix: [ $sfx ]\n");
print(" Module: $ttmodule ", $ttmodule->module_version(), "\n")
@@ -244,6 +242,7 @@ if ($summary || $verbose) {
$dryrun ? red("This was a dry run. Nothing was actually done\n") : "\n",
green(sprintf($format, $n_proc, $n_proc == 1 ? 'file' : 'files', 'processed')),
green(sprintf($format, $n_copy, $n_copy == 1 ? 'file' : 'files', 'copied')),
+ green(sprintf($format, $n_link, $n_link == 1 ? 'file' : 'files', 'linked')),
green(sprintf($format, $n_mkdir, $n_mkdir == 1 ? 'directory' : 'directories', 'created')),
yellow(sprintf($format, $n_unmod, $n_unmod == 1 ? 'file' : 'files', 'skipped (not modified)')),
yellow(sprintf($format, $n_skip, $n_skip == 1 ? 'file' : 'files', 'skipped (ignored)'))
@@ -353,6 +352,7 @@ sub process_file {
my ($old_suffix, $new_suffix);
my $is_dep = 0;
my $copy_file = 0;
+ my $link_file = 0;
$absfile ||= $file;
$filename = basename($file);
@@ -371,15 +371,26 @@ sub process_file {
# print "proc $file => $dest\n";
- # check against copy list
- foreach my $copy_pattern (@$copy) {
- if ($filename =~ /$copy_pattern/) {
- $copy_file = 1;
- $check = $copy_pattern;
+ # check against link list
+ foreach my $link_pattern (@$link) {
+ if ($filename =~ /$link_pattern/) {
+ $link_file = $copy_file = 1;
+ $check = $link_pattern;
last;
}
}
+ unless ($copy_file) {
+ # check against copy list
+ foreach my $copy_pattern (@$copy) {
+ if ($filename =~ /$copy_pattern/) {
+ $copy_file = 1;
+ $check = $copy_pattern;
+ last;
+ }
+ }
+ }
+
# stat the source file unconditionally, so we can preserve
# mode and ownership
( undef, undef, $mode, undef, $uid, $gid, undef,
@@ -405,6 +416,25 @@ sub process_file {
}
}
+ # check against link list
+ if ($link_file) {
+ unless ($dryrun) {
+ if (link($absfile, $dest) == 1) {
+ $copy_file = 0;
+ }
+ else {
+ warn red("Could not link ($absfile to $dest) : $!\n");
+ }
+ }
+
+ unless ($copy_file) {
+ $n_link++;
+ printf green(" > %-32s (linked, matches /$check/)\n"), $file
+ if $verbose;
+ return;
+ }
+ }
+
# check against copy list
if ($copy_file) {
$n_copy++;
@@ -579,6 +609,7 @@ sub read_config {
'binmode=s',
'ignore=s@',
'copy=s@',
+ 'link=s@',
'accept=s@',
'depend=s%',
'depend_debug|depdbg',
@@ -696,6 +727,9 @@ ignore = ^#
copy = \\.png\$
copy = \\.gif\$
+# ditto for things that should be linked rather than copied / processed.
+# link = \\.flv\$
+
# by default, everything not ignored or copied is accepted; add 'accept'
# lines if you want to filter further. e.g.
#
@@ -774,6 +808,7 @@ Display options:
File search specifications (all may appear multiple times):
--ignore=REGEX Ignore files matching REGEX
--copy=REGEX Copy files matching REGEX
+ --link=REGEX Link files matching REGEX
--accept=REGEX Process only files matching REGEX
File Dependencies Options:
@@ -873,11 +908,12 @@ home directory.
/home/abw/.ttreerc created. Please edit accordingly and re-run ttree
The purpose of this file is to set any I<global> configuration options
-that you want applied I<every> time F<ttree> is run. For example, you
-can use the C<ignore> and C<copy> option to provide regular expressions
-that specify which files should be ignored and which should be copied
-rather than being processed as templates. You may also want to set
-flags like C<verbose> and C<recurse> according to your preference.
+that you want applied I<every> time F<ttree> is run. For example, you
+can use the C<ignore> and C<copy> / C<link> options to provide regular
+expressions that specify which files should be ignored and which
+should be copied or linked rather than being processed as templates.
+You may also want to set flags like C<verbose> and C<recurse>
+according to your preference.
A minimal F<.ttreerc>:
@@ -1010,14 +1046,14 @@ processed and the modification time checking is bypassed.
=head2 File Options
-The C<ignore>, C<copy> and C<accept> options are used to specify Perl
-regexen to filter file names. Files that match any of the C<ignore>
-options will not be processed. Remaining files that match any of the
-C<copy> regexen will be copied to the destination directory. Remaining
-files that then match any of the C<accept> criteria are then processed
-via the Template Toolkit. If no C<accept> parameter is specified then
-all files will be accepted for processing if not already copied or
-ignored.
+The C<ignore>, C<copy>, C<link> and C<accept> options are used to
+specify Perl regexen to filter file names. Files that match any of the
+C<ignore> options will not be processed. Remaining files that match
+any of the C<copy> or C<link> regexen will be copied or linked to the
+destination directory. Remaining files that then match any of the
+C<accept> criteria are then processed via the Template Toolkit. If no
+C<accept> parameter is specified then all files will be accepted for
+processing if not already copied or ignored.
# ignore these files
ignore = \b(CVS|RCS)\b
Please sign in to comment.
Something went wrong with that request. Please try again.