Skip to content

Instantly share code, notes, and snippets.

@zzzeid
Last active July 30, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzzeid/46f7d8cc794f9fccf999bb8356f981be to your computer and use it in GitHub Desktop.
Save zzzeid/46f7d8cc794f9fccf999bb8356f981be to your computer and use it in GitHub Desktop.
A small python script that updates the timestamp on a file to match that in the directory state file.
#! /usr/bin/env python
"""
usage: fix.py [-h] path
mitigate mercurial bug 6528 for a particular repo
positional arguments:
path the path of the affected repo
optional arguments:
-h, --help show this help message and exit
"""
import argparse
import os
import pathlib
from mercurial.pure.parsers import parse_dirstate
parser = argparse.ArgumentParser(
description="mitigate mercurial bug 6528 for a particular repo"
)
parser.add_argument("path", help="the path of the affected repo")
# Path of misbehaving file.
path = b"toolkit/themes/shared/icons/reload.svg"
if __name__ == "__main__":
_map = dict()
args = parser.parse_args()
base_path = pathlib.Path(args.path)
with open(base_path / ".hg" / "dirstate", "rb") as f:
# Read directory state file.
dirstate = f.read()
# Parse directory state into `_map`.
parse_dirstate(_map, {}, dirstate)
# Fetch the timestamp in directory state, then modify the file on disk to match.
timestamp = _map[path][-1]
misbehaving_path = base_path / path.decode("utf-8")
os.utime(misbehaving_path, (timestamp, timestamp))
print("Updated timestamp to {} for {}.".format(timestamp, misbehaving_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment