Takahiro KITAHARA  committed 9619484

Try to open json with filesystemencoding, if failed.
For mbcs support.

  • Participants
  • Parent commits cbda367
  • Branches mbcs support

Comments (0)

Files changed (2)

File .hgtimestamp

 ".hgtags": {"timestamp": 1327960909.75},
 "": {"timestamp": 1339691478.75},
 "TimeStampMod.png": {"timestamp": 1305052883.0},
-"": {"timestamp": 1339691056.98},
+"": {"timestamp": 1341814092.17},
 "TimeStampMod.xmind": {"timestamp": 1306451621.66},
 "TimestampMod_LastRecord": {"timestamp": 0}


 import json	#use JSON format for storing timestamp data in file.
 import inspect	#required for getting path/name of current code module.
 import fnmatch	#required for checking file patterns.
+import codecs	#for mbcs support.
 from mercurial import localrepo	#required for creating a pseudo-pre-commit hook.
 from mercurial import match as matchmod	#required for "match" object in commit wrapper.
 from mercurial import merge as mergemod	#required for merge state (check unresolved)
 		myTimeStampJSONFile = open(repo.wjoin(IN_TimestampFileName), 'r')
 		repo.ui.debug('______\nRetrieving timestamps from JSON record file:\n------\n')
-			myData = json.load(myTimeStampJSONFile)
+			openEncode = None
+			try:
+				myData = json.load(myTimeStampJSONFile)
+			except:
+				# if error, open with filesystem encoding.
+				# On Windows, that will return 'mbcs'.
+				myData = json.load(codecs.getreader(sys.getfilesystemencoding())
+							   (open(repo.wjoin(IN_TimestampFileName),'r')))
+				# if success set openEncode filesystemencode
+				openEncode = sys.getfilesystemencoding()
 			# Check for version and object data:
 			if ('FileData' in myData):
 				if (LastPlaceholder in myData['FileData']):
 					del myData['FileData'][LastPlaceholder]
 				myWarnCount = 0 #initialize counter.
 				for s_fileName, obj_fileData in myData['FileData'].items():
+					if openEncode:
+						# convert s_fileName encode (unicode) to openedEncode
+						s_fileName = s_fileName.encode(openEncode)
 					#Only import data for entries already in local dictionary.
 					if s_fileName in INOUT_TimeStamp_dict:
 						myWarn = False #initialize warning flag for each item.