Commits

Nathan Durnan committed 1124306

Refactor options code for single loop.
Not sure if I like this for the number of tests within the loop. May be better with separate loops for Save/Restore.
See item 9 @bitbucket

Comments (0)

Files changed (1)

 	#Check for command optional argument
 	#--------------------
 	if opts['save']:
-		#====================
-		#Save timestamps for all files under version control (typically pre-commit)
-		#--------------------
 		ui.note('______\nSaving timestamps...\n------\n')
-		flag_Update = False
-		#update timestamps for changed items.
-		for s_fileName in List_ChangedFiles:
-			TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
-			flag_Update = True
-		#end of updating changed items.
-		#Save new file data.
 		file_TimeStampRecords = file(repo.root+'/.hgtimestamp', 'w')
-		for s_fileName, f_fileModTime in TimeStamp_dict.items():
-			if (f_fileModTime<=0):
-				#fill in missing any timestamps.
-				TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
-			#end of check for valid timestamp
+	elif opts['restore']:
+		ui.note('______\nRestoring timestamps...\n------\n')
+	else:
+		ui.note('______\nDisplaying timestamps...\n------\n')
+	#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))
-		#end of save new file data
-	elif opts['restore']:
-		#====================
-		#Restore timestamps of all files under version control (typically post-update/post-restore)
-		#--------------------
-		ui.note('______\nRestoring timestamps...\n------\n')
-		for s_fileName, f_fileModTime in TimeStamp_dict.items():
-			if (f_fileModTime>0):
-				_set_fileModTime(repo, s_fileName, f_fileModTime)
-			else:
-				ui.status(s_fileName, ' - skipped - no timestamp recorded\n')
-			#end of check for valid timestamp.
-		#end of loop through dictionary items.
-	else:
-		#====================
-		#no options, just display data in output status
-		#--------------------
-		ui.note('______\nDisplaying timestamps...\n------\n')
-		for s_fileName, f_fileModTime in TimeStamp_dict.items():
+		else:
 			#check for valid timestamp
 			if (f_fileModTime>0):
 				#valid timestamp detected!
-				#display timestamp using local time adjustment.
-				ui.status(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(f_fileModTime)), " \t", s_fileName, "\n")
+				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 loop through dictionary items.
+		#end of check for Save option	
+	#end of loop through dictionary items.
 	
-	#end of check command optional argument
-	
+	#====================
+	#Final Cleanup Actions
+	#--------------------
+	if opts['save']:
+		file_TimeStampRecords.close()
+	#end of close file after saving.
 	
 #_ end of timestamp_mod _______________________________________________________