views:

46

answers:

3

I'm writing my blog system(django), and my blog files are VCSed by mercurial,

I want get files create/update time, how could I do this by using commandline or python?

edit: this is a example:

$ SOME_COMMAND
xxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
xyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
xxy.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
yxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
yyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
+1  A: 

You could use hg log

temp $ mkdir test
temp $ cd test
test $ hg init .
test $ cp ../a.py .
test $ hg add a.py 
test $ mate a.py 
test $ hg commit -m "added file"
test $ hg commit a.py -m "changed file"
test $ hg log
1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
  changed file

0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
  added file

test $ hg log a.py 
1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
  changed file

0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
  added file
pyfunc
I got the impression he was going after the value programatically, so using log without a template would mean having to grep/parse both first and last out.
Ry4an
+2  A: 
$ hg log -l1 --template "{date|isodate}\n" specific-file
2010-08-18 21:00 -0400
$ hg log -l1 --template "{date|isodate}\n"   # latest changeset
2010-10-20 09:48 -0400

~/.hgrc, .hg/hgrc

[alias]
# last commit (ci being an alias for commit/check-in)
lastci = log -l1 --template "{date|localdate|rfc822date}\n"
# unless I'm misunderstanding, this will convert the date in the changeset to
# your local timezone, then display as per rfc822

$ hg lastci specific-file
Wed, 18 Aug 2010 21:00:46 -0400
$ hg lastci   # latest changeset
Wed, 20 Oct 2010 09:48:29 -0400
Roger Pate
+4  A: 

To get the most recent modification time of a file:

hg log --template '{date}' -l 1 path/to/file

and to get the creation time:

hg log --template '{date}' -r 0:tip -l 1 README

Example output:

$ hg log --template '{date}' -r 0:tip -l 1 README
1115154970.028800

$ hg log --template '{date}' -l 1 README
1255462070.025200

Those date values are unix epoc seconds followed by a dot and a timezone offset. You can pretty format them using various filters described in hg help templates like this:

$ hg log --template '{date|rfc822date}' -l 1 README
Tue, 13 Oct 2009 12:27:50 -0700
Ry4an