3177N/A#!/usr/bin/python2.7
2508N/A
2508N/A# This program is free software; you can redistribute it and/or modify
2508N/A# it under the terms of the GNU General Public License version 2
2508N/A# as published by the Free Software Foundation.
2508N/A#
2508N/A# This program is distributed in the hope that it will be useful,
2508N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2508N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2508N/A# GNU General Public License for more details.
2508N/A#
2508N/A# You should have received a copy of the GNU General Public License
2508N/A# along with this program; if not, write to the Free Software
2508N/A# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2508N/A#
3177N/A# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2508N/A
2508N/A
2508N/A# Create a dictionary (timestamps) mapping paths of python files in the modules
2508N/A# directory to their timestamps. If a file is modified, its timestamp is the
2508N/A# filesystem timestamp. If it's unchanged, its timestamp is the timestamp of
2508N/A# the last changeset which modified it.
2508N/A
3143N/Afrom __future__ import print_function
2508N/Aimport os
2508N/Aimport time
2508N/Aimport mercurial.cmdutil as cmdutil
2588N/Aimport mercurial.match as matchmod
2508N/Afrom mercurial.localrepo import localrepository
2508N/Afrom mercurial.ui import ui
2508N/A
2508N/Amyui = ui()
2508N/Arepo = localrepository(myui, cmdutil.findrepo(os.getcwd()))
2508N/A
2508N/A# Match only python files in src/modules.
2588N/Amatchfn = matchmod.match(repo.root, os.getcwd(), patterns=["re:src/modules/.*\.py$"])
2508N/A
2508N/A# Dummy prep function.
2508N/Adef prep(ctx, fns):
2508N/A pass
2508N/A
2508N/A# Get the set of matching files in the working directory parent.
2508N/Amanifest = set(
2508N/A f
2588N/A for f in repo["."]
2508N/A if f.startswith("src/modules/") and f.endswith(".py")
2508N/A)
2508N/A
2508N/A# Find out which files have changed.
2561N/Astatus = repo.status(match=matchfn)
2508N/A
2508N/Atimestamps = {}
2508N/A
2508N/A# Handle the modified files first: get their timestamps from the filesystem.
2508N/A# Remove the filenames from "manifest" so that we don't look for their changeset
2508N/A# timestamps in the next loop.
2561N/Afor f in status[0] + status[1]:
2508N/A if f in manifest:
2508N/A timestamps[f] = \
2508N/A os.stat(os.path.join(repo.root, f)).st_mtime
2508N/A manifest.remove(f)
2508N/A
2508N/A# Now walk backwards through the changesets from the working directory parent
2508N/A# (making sure we don't look at changesets that aren't ancestors), and for each
2508N/A# file that still needs a timestamp, grab it from the changeset and make sure we
2508N/A# don't look at it again.
2508N/Arevs = ['reverse(ancestors(.))']
2508N/Afor ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev': revs}, prep):
2508N/A for f in ctx.files():
2508N/A if f in manifest:
2508N/A timestamps[f] = ctx.date()[0]
2508N/A manifest.remove(f)
2508N/A
2508N/Afor name, stamp in timestamps.iteritems():
3143N/A print(stamp, name)
2508N/A
2508N/A# Get the timestamp of the workspace. If it's unmodified, then use the
2508N/A# timestamp of the parent of the working directory, and the latest timestamp of
2508N/A# the modified and added files if not. (We would do removed, but we don't know
2508N/A# when they were removed.)
2508N/As = repo.status()
2508N/Amodadd = s[0] + s[1]
2508N/Aif any(modadd):
3143N/A print(max((
2508N/A os.stat(os.path.join(repo.root, f)).st_mtime
2508N/A for f in modadd
3143N/A )), ".")
2508N/Aelse:
3143N/A print(repo["."].date()[0], ".")