Upgrade yt-dlp to version 2022.11.11
[sunny256-utils.git] / svnfiledate
blob901afbf443c6e962a7ca8610d4cd26566cf113a1
1 #!/usr/bin/env perl
3 #=======================================================================
4 # svnfiledate
5 # File ID: 2530c5b0-f744-11dd-a6f8-000475e441b9
6 # Stores the file date in a special svn property.
8 # Character set: UTF-8
9 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'directories' => 0,
26 'help' => 0,
27 'verbose' => 0,
28 'version' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = "0.00";
36 Getopt::Long::Configure("bundling");
37 GetOptions(
39 "debug" => \$Opt{'debug'},
40 "directories|d" => \$Opt{'directories'},
41 "help|h" => \$Opt{'help'},
42 "verbose|v+" => \$Opt{'verbose'},
43 "version" => \$Opt{'version'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 my $PROP_NAME = "filedate";
48 my $CMD_SVN = "svn";
50 $Opt{'debug'} && ($Debug = 1);
51 $Opt{'help'} && usage(0);
52 if ($Opt{'version'}) {
53 print_version();
54 exit(0);
57 for my $File (@ARGV) {
58 # {{{
59 my @stat_array = lstat($File);
60 if (scalar(@stat_array)) {
61 if (-d $File && !$Opt{'directories'}) {
62 warn("$progname: $File: Ignoring directory\n");
63 } else {
64 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
65 $atime, $mtime, $ctime, $blksize, $blocks) = @stat_array;
66 my @TA = gmtime($mtime);
67 my $date_str = sprintf("%04u-%02u-%02uT%02u:%02u:%02uZ",
68 $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0]);
69 mysyst($CMD_SVN, "propset", $PROP_NAME, $date_str, $File);
71 } else {
72 warn("$progname: $File: Unable to lstat() file\n");
74 # }}}
77 sub mysyst {
78 # {{{
79 my @Args = @_;
80 my $system_txt = sprintf("system(\"%s\");", join("\", \"", @Args));
81 D("$system_txt");
82 deb_wait();
83 print("@_\n");
84 system(@_);
85 # }}}
86 } # mysyst()
88 sub deb_wait {
89 # {{{
90 $Debug || return;
91 print("debug: Press ENTER...");
92 <STDIN>;
93 # }}}
94 } # deb_wait()
96 sub print_version {
97 # Print program version {{{
98 print("$progname v$VERSION\n");
99 # }}}
100 } # print_version()
102 sub usage {
103 # Send the help message to stdout {{{
104 my $Retval = shift;
106 if ($Opt{'verbose'}) {
107 print("\n");
108 print_version();
110 print(<<END);
112 Define a "$PROP_NAME" property containing the timestamp of a
113 file/symlink/directory on Subversion-controlled files.
115 Usage: $progname [options] [file [files [...]]]
117 Options:
119 -d, --directories
120 Also set the property on directories, default action is to ignore
121 those.
122 -h, --help
123 Show this help.
124 -v, --verbose
125 Increase level of verbosity. Can be repeated.
126 --version
127 Print version information.
128 --debug
129 Print debugging messages.
132 exit($Retval);
133 # }}}
134 } # usage()
136 sub msg {
137 # Print a status message to stderr based on verbosity level {{{
138 my ($verbose_level, $Txt) = @_;
140 if ($Opt{'verbose'} >= $verbose_level) {
141 print(STDERR "$progname: $Txt\n");
143 # }}}
144 } # msg()
146 sub D {
147 # Print a debugging message {{{
148 $Debug || return;
149 my @call_info = caller;
150 chomp(my $Txt = shift);
151 my $File = $call_info[1];
152 $File =~ s#\\#/#g;
153 $File =~ s#^.*/(.*?)$#$1#;
154 print(STDERR "$File:$call_info[2] $$ $Txt\n");
155 return("");
156 # }}}
157 } # D()
159 __END__
161 # Plain Old Documentation (POD) {{{
163 =pod
165 =head1 NAME
167 svnfiledate
169 =head1 SYNOPSIS
171 svnfiledate [options] [file [files [...]]]
173 =head1 DESCRIPTION
175 Define a "$PROP_NAME" property containing the timestamp of a
176 file/symlink/directory on Subversion-controlled files.
178 =head1 OPTIONS
180 =over 4
182 =item B<-d>, B<--directories>
184 Also set the property on directories, default action is to ignore those.
186 =item B<-h>, B<--help>
188 Print a brief help summary.
190 =item B<-v>, B<--verbose>
192 Increase level of verbosity. Can be repeated.
194 =item B<--version>
196 Print version information.
198 =item B<--debug>
200 Print debugging messages.
202 =back
204 =head1 BUGS
206 It’s non-standard. The Subversion client doesn’t have anything like this
207 yet, so it will probably change in the future.
209 =head1 AUTHOR
211 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
213 =head1 COPYRIGHT
215 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
216 This is free software; see the file F<COPYING> for legalese stuff.
218 =head1 LICENCE
220 This program is free software: you can redistribute it and/or modify it
221 under the terms of the GNU General Public License as published by the
222 Free Software Foundation, either version 2 of the License, or (at your
223 option) any later version.
225 This program is distributed in the hope that it will be useful, but
226 WITHOUT ANY WARRANTY; without even the implied warranty of
227 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
228 See the GNU General Public License for more details.
230 You should have received a copy of the GNU General Public License along
231 with this program.
232 If not, see L<http://www.gnu.org/licenses/>.
234 =head1 SEE ALSO
236 =cut
238 # }}}
240 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :