Commits

Nathan Durnan committed 8714385 Merge

Merge with Release 0.1.3

Comments (0)

Files changed (2)

 .hgtags,1326395894.98
 README.rst,1312921197.45
 TimeStampMod.png,1305052883.0
-TimestampMod.py,1326395813.03
+TimestampMod.py,1327960495.36
 TimeStampMod.xmind,1306451621.66
 #==============================================================================
 # TimestampMod.py - Automatically save and restore the modification times of files
-# Version 0.1.2  --> !!BETA RELEASE!!!
+# Version 0.1.3  --> !!BETA RELEASE!!!
 # Copyright 2011 Nathan Durnan <nedmech@gmail.com>
 #
 # Based on timestamp extension by Friedrich Kastner-Masilko <face@snoopie.at>
 # Development information:
 #	Mercurial Version:	1.8.3 - 2.0.1 (from TortoiseHg package)
 #	Python Version:		2.6.6 (from TortoiseHg package)
-#	TortoiseHg Version: 2.0.4 - 2.2.1
+#	TortoiseHg Version: 2.0.4 - 2.2.2
 #==============================================================================
 # begin Extension Help Text:
 '''Automatically store and retrieve modification times of files.'''
 import os	#required for filesystem access methods.
 import time	#required for time functions.
 from mercurial import localrepo	#required for creating a pseudo-pre-commit hook.
-from mercurial import commands	#required for accessing Mercurial commands.
 from mercurial import scmutil	#required for "match" object in commit wrapper.
 #_ end of imported modules_____________________________________________________
 
 	'''Initialize UI-Level Callback'''
 	ui.debug('* Loading TimestampMod uisetup\n')
 	ui.setconfig("hooks", "post-status.TimestampMod", Hook_Post_Status)
-	ui.setconfig("hooks", "pre-commit.TimestampMod", Hook_Pre_Commit)
+	# Hook_Pre_Commit is depreciated in favor of Wrap_Commit method
+	#	(Wrap_Commit works with both native Mercurial and TortoiseHg.)
+	'''ui.setconfig("hooks", "pre-commit.TimestampMod", Hook_Pre_Commit)'''
 #_ end of uisetup _____________________________________________________________
 
 
 #	Ideally, this will be revised to a cleaner method in the future.
 #==============================================================================
 def Wrap_Commit(repo, text="", user=None, date=None, match=None, force=False, editor=False, extra={}):
-	repo.ui.note('Wrap_Commit accessed!\n')
+	repo.ui.note('TimestampMod|Wrap_Commit accessed!\n')
 	#Check for a merge-commit. 
 	#  Don't run timestamp code on merge.
 	if (len(repo.parents()) > 1):
 		# Make sure the match object is created.
 		if not match:
 			repo.ui.debug('Empty match: Must create!\n')
-			match = scmutil.matchall(repo) #match all files if nothing specified.
+			match = scmutil.matchfiles(repo, "")  #create an empty match object
 		else:
 			pass
 		# End of check for non-existent match object.
 		myList_Match = list()
-		myList_Match = match.files() + [File_TimestampRecords]
+		myList_Match = match.files() #don't add timestamp file here, it will be added later.
 		timestamp_mod(repo.ui, repo, **dict({'save': True, 'restore': None, 'match': myList_Match}))
 		# Make sure record file is part of repository and commit. 
 		if not (File_TimestampRecords in repo.dirstate):
 			repo.ui.debug('Wrap_Commit: ', File_TimestampRecords, ' not in repo.dirstate  Adding...\n')
-			commands.add(repo.ui, repo, File_TimestampRecords)
+			repo[None].add([File_TimestampRecords]) #same method used for adding '.hgtags' file in localrepo.py
 		#end of check for record file in repository.
 		#Update match fileset for use under TortoiseHg.
 		#  TortoiseHg doesn't seem to catch the updated file
 		# end of check for record file.
 		repo.ui.debug('Match Files: ', str(match.files()), '\n')
 	#end of check for merge-commit.
+	repo.ui.note('TimestampMod|Wrap_Commit finished!\n')
 	return repo.timestamp_origcommit(text, user, date, match, force, editor, extra)
 #_ end of Wrap_Commit _________________________________________________________
 
 # NOTES: The pre-** hooks are the only ones that does not function properly
 #	under the TortoiseHg GUI.  All the hooks work from command-line.
 #==============================================================================
-def Hook_Pre_Commit(repo, **kwargs):
+# Hook_Pre_Commit is depreciated in favor of Wrap_Commit method
+#	(Wrap_Commit works with both native Mercurial and TortoiseHg.)
+'''def Hook_Pre_Commit(repo, **kwargs):
 	repo.ui.note("Pre-Commit Hook accessed!\n")
 	repo.ui.debug('kwargs = ',kwargs, "\n")
 	timestamp_mod(repo.ui, repo, **dict({'save': True, 'restore': None}))
 	kwargs['pats'].append(File_TimestampRecords)
-
+''' # Hook_Pre_Commit is depreciated
 def Hook_Post_Status(repo, **kwargs):
 	repo.ui.note("Post-Status Hook accessed!\n")
 	timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': None}))
 	myDroppedList = list()
 	myMatchList = list()
 	if ('match' in kwargs):
-		ui.note("-----\nmatch: ", str(kwargs['match']), "\n")
+		ui.debug("-----\nmatch: ", str(kwargs['match']), "\n")
 		myMatchList = kwargs['match']
 	else:
-		ui.note("-----\nmatch argument not specified\n")
+		ui.debug("-----\nmatch argument not specified\n")
 	# end of check for match argument'''
 	myChangedList, myDroppedList = _get_RepoFileList(repo, myMatchList, TimeStamp_dict)
 	# Retrieve existing timestamps from the record file.
 			_display_Timestamps(repo, TimeStamp_dict)
 		# end of check options (Restore/Display)
 	else:
-		repo.ui.warn('Timestamp_Mod can not continue without ', File_TimestampRecords, ' file! \n')
+		repo.ui.debug('Timestamp_Mod can not continue without ', File_TimestampRecords, ' file! \n')
 	# end of check options
 #_ end of timestamp_mod _______________________________________________________
 
 	myFilePath = repo.wjoin(IN_FileName)
 	try:
 		myModTime = float(os.stat(myFilePath).st_mtime)
-		repo.ui.note(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(myModTime)), " \t", IN_FileName, "\n")
+		repo.ui.debug(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(myModTime)), " \t", IN_FileName, "\n")
 		return myModTime
 	except:
-		repo.ui.warn('*** Get File Stat failed for ', IN_FileName, '!\n')
-		repo.ui.warn('*** Exception: ', str(sys.exc_info()), '  ***\n')
+		repo.ui.warn('*** TimestampMod: Get File Stat failed for ', IN_FileName, '!\n')
+		repo.ui.debug('*** Exception: ', str(sys.exc_info()), '  ***\n')
 		return -1
 	# end of file stat access.
 #_ end of _get_fileModTime ____________________________________________________
 	try:
 		myFileStat = os.stat(myFilePath)
 		os.utime(myFilePath, (myFileStat.st_atime, type(myFileStat.st_mtime)(IN_ModTime)))
-		repo.ui.note(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(IN_ModTime)), " \t", IN_FileName, "\n")
+		repo.ui.debug(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(IN_ModTime)), " \t", IN_FileName, "\n")
 	except:
-		repo.ui.warn('*** Set File Stat failed for ', IN_FileName, '! ***\n')
-		repo.ui.warn('*** Exception: ', str(sys.exc_info()), '  ***\n')
+		repo.ui.warn('*** TimestampMod: Set File Stat failed for ', IN_FileName, '! ***\n')
+		repo.ui.debug('*** Exception: ', str(sys.exc_info()), '  ***\n')
 	# end of file stat access.
 #_ end of _set_fileModTime ____________________________________________________
 
 		myTimeStampRecordsFile.close()
 		return True 	# Set return flag as successful.
 	except:
-		repo.ui.warn('*** Error accessing ', IN_TimestampFileName, ' file! ***\n')
-		repo.ui.warn('*** Exception: ', str(sys.exc_info()), '  ***\n')
+		repo.ui.debug('*** Error accessing ', IN_TimestampFileName, ' file! ***\n')
+		repo.ui.debug('*** Exception: ', str(sys.exc_info()), '  ***\n')
 		return False	# Make sure return flag is not set.
 	# end of accessing record file.
 #_ end of _read_TimestampRecords ______________________________________________
 			_set_fileModTime(repo, s_fileName, f_fileModTime)
 		else:
 			# No valid timestamp recorded, skip this file.
-			repo.ui.note(s_fileName, ' - skipped - no timestamp recorded\n')
+			repo.ui.debug(s_fileName, ' - skipped - no timestamp recorded\n')
 		# end of check for valid timestamp.
 	# end of loop through dictionary items.
 #_ end of _restore_Timestamps _________________________________________________
 			repo.ui.status(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(f_fileModTime)), " \t", s_fileName, "\n")
 		else:
 			# No valid timestamp recorded, skip this file.
-			repo.ui.note(s_fileName, ' - skipped - no timestamp recorded\n')
+			repo.ui.debug(s_fileName, ' - skipped - no timestamp recorded\n')
 		# end of check for valid timestamp.
 	# end of loop through dictionary items.
 #_ end of _display_Timestamps _________________________________________________