Changeset da0a7914


Ignore:
Timestamp:
04/14/2021 07:04:34 PM (4 months ago)
Author:
Xi Ruoyao <xry111@…>
Branches:
xry111/git-date
Children:
6254a33
Parents:
6cbfa66
Message:

use FETCH_HEAD in expand_date

File:
1 edited

Legend:

Unmodified
Added
Removed
  • expand_date

    r6cbfa66 rda0a7914  
    22
    33from os import getcwd
    4 from subprocess import check_output
     4from subprocess import check_output, DEVNULL
    55from sys import stdin, stdout, argv
    66
    77content = stdin.read()
    8 cmd = [ 'git', 'log', '-1', '--pretty=%ai', '--', argv[1] ]
    9 date = check_output(cmd, cwd = getcwd()).decode().rstrip()
    10 stdout.write(content.replace('$Date$', '$Date: %s$' % date))
     8
     9# To editors:
     10# The usage of FETCH_HEAD here is very tricky.  This is only intended for
     11# the cron job running "git pull" periodically.  Humans should NOT rely on
     12# this script at all.  Do NOT add "dater" filter into your .git/config.
     13# For editors, just use `git log ${path}` to show the history of a file.
     14cmd = [ 'git', 'log', '-1', '--pretty=%ad', 'FETCH_HEAD', argv[1] ]
     15try:
     16    date = check_output(cmd, cwd = getcwd(), stderr=DEVNULL).decode().rstrip()
     17    content = content.replace('$Date$', '$Date: %s$' % date)
     18except Exception:
     19    pass
     20stdout.write(content)
Note: See TracChangeset for help on using the changeset viewer.