1. Nathan Durnan
  2. TimeStampMod

Commits

Nathan Durnan  committed aea2509

MAJOR Refactor: Simplify tests inside of loops for optimal speed.
see issue 9 @bitbucket
This means more duplicated loop code (restore & display are almost identical), but the loops should run faster.

  • Participants
  • Parent commits 1124306
  • Branches development

Comments (0)

Files changed (1)

File TimestampMod.py

View file
 # Global Objects
 #------------------------------------------------------------------------------
 TimeStamp_dict = dict()
+List_ChangedFiles = []
+List_DroppedFiles = []
 #_ end of global objects ______________________________________________________
 
 #==============================================================================
 # end help text
 	ui.note("Executing timestamp_mod function\n")
 	
-	#====================
 	#Retrieve Repository file list contents.
-	#--------------------
 	List_ChangedFiles, List_DroppedFiles = _get_RepoFileList(repo)
 	
-	#====================
 	#Retrieve existing timestamps from the record file.
-	#--------------------
 	_read_TimestampRecords(repo)
 	
-	#====================
 	#Check for command optional argument
-	#--------------------
 	if opts['save']:
-		ui.note('______\nSaving timestamps...\n------\n')
-		file_TimeStampRecords = file(repo.root+'/.hgtimestamp', 'w')
+		_save_Timestamps(repo)
 	elif opts['restore']:
-		ui.note('______\nRestoring timestamps...\n------\n')
+		_restore_Timestamps(repo)
 	else:
-		ui.note('______\nDisplaying timestamps...\n------\n')
+		_display_Timestamps(repo)
 	#end of check options
-	
-	#====================
-	#Execute Actions on File List
-	#--------------------
-	for s_fileName, f_fileModTime in TimeStamp_dict.items():
-		if opts['save']:
-			if (s_fileName in List_ChangedFiles) or (f_fileModTime<=0):
-				f_fileModTime = TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
-			#end of update timestamps for changed items or missing timestamps.
-			file_TimeStampRecords.write("%s,%s\n" % (s_fileName, f_fileModTime))
-		else:
-			#check for valid timestamp
-			if (f_fileModTime>0):
-				#valid timestamp detected!
-				if opts['restore']:
-					#restore file timestamp
-					_set_fileModTime(repo, s_fileName, f_fileModTime)
-				else:
-					#display timestamp using local time adjustment.
-					ui.status(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(f_fileModTime)), " \t", s_fileName, "\n")
-				#end of check for Restore option.
-			else:
-				#no valid timestamp recorded, skip this file.
-				ui.status(s_fileName, ' - skipped - no timestamp recorded\n')
-			#end of check for valid timestamp.
-		#end of check for Save option	
-	#end of loop through dictionary items.
-	
-	#====================
-	#Final Cleanup Actions
-	#--------------------
-	if opts['save']:
-		file_TimeStampRecords.close()
-	#end of close file after saving.
-	
 #_ end of timestamp_mod _______________________________________________________
 
 
 	#end of accessing record file.
 #_ end of _read_TimestampRecords ______________________________________________
 
+
+
+#==============================================================================
+# _save_Timestamps Function Definitions
+#------------------------------------------------------------------------------
+# Summary: Save File Modified Timestamp data for files in the global dictionary
+#	collection to a record file in the repository root directory.  New values
+#	for timestamps will be retrieved for files that have changed or are missing
+#	timestamp records in the first place.
+#==============================================================================
+def _save_Timestamps(repo):
+	'''Save File Modification Timestamps to record file.'''
+	repo.ui.note('______\nSaving timestamps...\n------\n')
+	file_TimeStampRecords = file(repo.root+'/.hgtimestamp', 'w')
+	for s_fileName, f_fileModTime in TimeStamp_dict.items():
+		if (s_fileName in List_ChangedFiles) or (f_fileModTime<=0):
+			f_fileModTime = TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
+		#end of update timestamps for changed items or missing timestamps.
+		file_TimeStampRecords.write("%s,%s\n" % (s_fileName, f_fileModTime))
+	#end of loop through dictionary items.
+	file_TimeStampRecords.close()
+#_ end of _save_Timestamps ____________________________________________________
+
+
+
+#==============================================================================
+# _restore_Timestamps Function Definitions
+#------------------------------------------------------------------------------
+# Summary: Restore the File Modification Timestamp property for files in the
+#	global dictionary collection.  
+# NOTE: This presumes that the dictionary has been initialized and the original
+#	timestamp data has already been read into the dictionary.
+#==============================================================================
+def _restore_Timestamps(repo):
+	'''Restore File Modification Timestamps from record file'''
+	repo.ui.note('______\nRestoring timestamps...\n------\n')
+	for s_fileName, f_fileModTime in TimeStamp_dict.items():
+		#check for valid timestamp
+		if (f_fileModTime>0):
+			#valid timestamp detected!
+				#restore file timestamp
+				_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')
+		#end of check for valid timestamp.
+	#end of loop through dictionary items.
+#_ end of _restore_Timestamps _________________________________________________
+
+
+
+#==============================================================================
+# _display_Timestamps Function Definition
+#------------------------------------------------------------------------------
+# Summary: Default action.  Display the File Modification Timestamp property for
+#	files in the global dictionary collection.  
+# NOTE: This presumes that the dictionary has been initialized and the original
+#	timestamp data has already been read into the dictionary.
+#==============================================================================
+def _display_Timestamps(repo):
+	'''Display File Timestamps currently recorded.'''
+	repo.ui.note('______\nDisplaying timestamps...\n------\n')
+	for s_fileName, f_fileModTime in TimeStamp_dict.items():
+		#check for valid timestamp
+		if (f_fileModTime>0):
+			#valid timestamp detected!
+			#display timestamp using local time adjustment.
+			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')
+		#end of check for valid timestamp.
+	#end of loop through dictionary items.
+#_ end of _display_Timestamps _________________________________________________
+
+
+