import os
import os.path
import re
-import StringIO
import sys
import time
return stdout.rstrip('\n')
def original_year(filename, year_hacks=YEAR_HACKS):
- # shortdate filter: YEAR-MONTH-DAY
output = git_cmd('log', '--follow',
'--format=format:%ad', # Author date
'--date=short', # YYYY-MM-DD
elif PROJECT_INFO['vcs'] == 'Mercurial':
+ import StringIO
+ import mercurial
+ import mercurial.dispatch
+
def mercurial_cmd(*args):
cwd = os.getcwd()
stdout = sys.stdout
return years[0]
def authors(filename, author_hacks=AUTHOR_HACKS):
- output,error = mercurial_cmd('log', '-template', '{author}\n',
+ output,error = mercurial_cmd('log', '--follow',
+ '--template', '{author}\n',
filename)
ret = list(set(output.splitlines()))
if splitpath(filename) in author_hacks:
return ret
def authors_list(author_hacks=AUTHOR_HACKS):
- output,error = mercurial_cmd('log', '--follow',
- '--template', '{author}\n')
+ output,error = mercurial_cmd('log', '--template', '{author}\n')
ret = list(set(output.splitlines()))
for path,authors in author_hacks.items():
ret.extend(authors)
return True
elif PROJECT_INFO['vcs'] == 'Bazaar':
- pass
+
+ import StringIO
+ import bzrlib
+ import bzrlib.builtins
+ import bzrlib.errors
+ import bzrlib.log
+
+ class LogFormatter (bzrlib.log.LogFormatter):
+ supports_merge_revisions = True
+ preferred_levels = 0
+ supports_deta = False
+ supports_tags = False
+ supports_diff = False
+
+ def log_revision(self, revision):
+ raise NotImplementedError
+
+ class YearLogFormatter (LogFormatter):
+ def log_revision(self, revision):
+ self.to_file.write(
+ time.strftime('%Y', time.gmtime(revision.rev.timestamp))
+ +'\n')
+
+ class AuthorLogFormatter (LogFormatter):
+ def log_revision(self, revision):
+ authors = revision.rev.get_apparent_authors()
+ self.to_file.write('\n'.join(authors)+'\n')
+
+ def original_year(filename, year_hacks=YEAR_HACKS):
+ cmd = bzrlib.builtins.cmd_log()
+ cmd.outf = StringIO.StringIO()
+ cmd.run(file_list=[filename], log_format=YearLogFormatter, levels=0)
+ years = [int(year) for year in set(cmd.outf.getvalue().splitlines())]
+ if splitpath(filename) in year_hacks:
+ years.append(year_hacks[splitpath(filename)])
+ years.sort()
+ return years[0]
+
+ def authors(filename, author_hacks=AUTHOR_HACKS):
+ cmd = bzrlib.builtins.cmd_log()
+ cmd.outf = StringIO.StringIO()
+ cmd.run(file_list=[filename], log_format=AuthorLogFormatter, levels=0)
+ ret = list(set(cmd.outf.getvalue().splitlines()))
+ if splitpath(filename) in author_hacks:
+ ret.extend(author_hacks[splitpath(filename)])
+ return ret
+
+ def authors_list(author_hacks=AUTHOR_HACKS):
+ cmd = bzrlib.builtins.cmd_log()
+ cmd.outf = StringIO.StringIO()
+ cmd.run(log_format=AuthorLogFormatter, levels=0)
+ output = cmd.outf.getvalue()
+ ret = list(set(cmd.outf.getvalue().splitlines()))
+ for path,authors in author_hacks.items():
+ ret.extend(authors)
+ return ret
+
+ def is_versioned(filename):
+ cmd = bzrlib.builtins.cmd_log()
+ cmd.outf = StringIO.StringIO()
+ try:
+ cmd.run(file_list=[filename])
+ except bzrlib.errors.BzrCommandError:
+ return False
+ return True
else:
raise NotImplementedError('Unrecognized VCS: %(vcs)s' % PROJECT_INFO)
update_authors(dry_run=options.dry_run, verbose=options.verbose)
update_files(files=args, dry_run=options.dry_run, verbose=options.verbose)
-
-# LocalWords: difflib