[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: File date/time

From: Oliver Betz <list_ob_at_gmx.net>
Date: 2006-10-27 08:55:15 CEST

Ryan Schmidt wrote:

[...]

> If you must preserve each file's modification time in the repository,
> then you can consider compiling Subversion yourself from the
> unofficial "text-time" branch:
>
> http://svn.collab.net/repos/svn/branches/meta-data-versioning/

is this branch maintained? IOW which subversion version does one get
using this branch?

> Then you would need to start over, create a new repository, and
> import again.
>
> FWIW I would also find it useful if this were an option available in
> the standard Subversion, particularly for importing historical
> projects where the loss of such information can be significant. See

ack. But most times it is sufficient to have the commit time set to
the file mtime when importing the project the first time.

I already posted a (crude) perl script to this list doing this, here
is it:

#!/usr/bin/perl
# import files to subversion one by one and adjust commit date to file's mtime
# this method is rather slow!
# directory timestamps are set to the mtime of the oldest file

# 2005-07-15 Oliver Betz

# instructions:
# create an empty repository, make sure to have a "pre-revprop-change" hook
# check out a working copy from the empty repository
# copy the whole tree of files to the working copy
# run this script from the WC root

# caution:
# - stat() fails on filenames with foreign characters.
# maybe conflicting translations from svn and perl?
# - (stat())->mtime reports wrong data using ActivePerl with NTFS. Cygwin works.

use strict;

use File::stat; # by-name access to mtime
use File::Find;

my $rev; # revision of committed file
my $svnstat; # response of "svn stat"
my %files;
my $filename; # path to current file
my $mtime; # mtime of current file

$ENV{Lang}="C"; # else we might get localized responses

find({wanted => \&getfile, no_chdir => 1}, '.'); # all files and directories in the tree

$mtime = svntime((sort(values(%files)))[0]), "\n"; # oldest file
print "svn propset svn:date $mtime --revprop -r HEAD\n";
print `svn propset svn:date $mtime --revprop -r HEAD\n`;

# first add all directories, they receive the time of the oldest file
foreach $filename (sort keys(%files)){
  next unless (-d $filename);
  print "svn add -N \"$filename\"\n";
  print `svn add -N "$filename"`; # put the file under svn control, print response
}

foreach $filename (sort { $files{$a} <=> $files{$b} } keys(%files)) {
  next if (-d $filename); # directories have already been added
  $svnstat = `svn stat "$filename"`;
  next unless $svnstat =~ m/^\?.....\s+(\S.*)$/;
  # skip if ignored or already under version control

  print `svn add -N "$filename"`; # put the file under svn control
  $rev=`svn ci -m "mtime keeping add of $filename"`; # commit the file immediately
  print "$rev"; # show complete response (several lines)
  die "wrong response $rev" unless $rev =~ /Committed revision (\d+)\./;
  # this is rather restrictive - 'next' might be a good alternative
  $rev = $1; # numerical value -> $rev

  $mtime = svntime($files{$filename}); # special format of svn time: 2005-07-11T09:17:35.000000Z

  print `svn propset svn:date $mtime --revprop -r $rev`;
}
print "ready\n";

# add file dates and file/dir types to hash
sub getfile {
  return if $File::Find::name eq "."; # don't add "."
  return if $File::Find::name =~ m{/.svn}; # don't add svn directories
  $files{$File::Find::name} = (stat($File::Find::name))->mtime; # add file to hash
}

sub svntime {
  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(@_[0]);
  return sprintf "%4d-%02d-%02dT%02d:%02d:%02d.000000Z",1900+$year,$mon+1,$mday,$hour,$min,$sec;
}
__END__

Oliver

-- 
Oliver Betz, Muenchen
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Oct 27 08:55:45 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.