Commits

Nathan Durnan committed 3434e2d

Cleaned up comments/layout.
Added datatype indicator to some variable names.

Comments (0)

Files changed (1)

 # begin command/function help text	
 	'''Save or restore file modification times.'''
 # end help text
-	ui.note("executing timestamp_mod function\n")
+	ui.note("Executing timestamp_mod function\n")
 	
+	#====================
 	#Access timestamp record file.
+	#--------------------
 	file_TimeStampRecords=''
-	ui.note('accessing .hgtimestamp file...\n')
+	flag_FileErr = False
+	ui.debug('accessing .hgtimestamp file...\n')
 	try:
 		file_TimeStampRecords = file(repo.root+'/.hgtimestamp', 'r')
 	except:
-		ui.warn('Error accessing .hgtimestamp file!\n')
+		flag_FileErr = True
+		ui.warn('*** Error accessing .hgtimestamp file! ***\n')
+	#end of accessing record file.
 	
-	#initialize data objects.
+	#====================
+	# Initialize data objects.
+	#--------------------
 	TimeStamp_dict = dict()
 	TimeStamp_list = list()
-
-	#retrieve Repository Manifest contents.
-	ui.debug('generating file list from repo...\n')
+	#NOTE: keep list as duplicate of dict.keys so items can be safely deleted from dictionary later.
+	
+	#====================
+	#Retrieve Repository Manifest contents.
+	#--------------------
+	ui.debug('______\ngenerating file list from repo...\n------\n')
 	RepoContext = cmdutil.revsingle(repo, None)
 	for myFile in RepoContext:
-		fileName = str(myFile).strip()
-		if fileName.endswith(('.hg','.Hg','.hG','.HG'),0,3):	#don't add internal hg files to timestamp list.
-			ui.debug('    (skipped):  ' + fileName + '\n')
+		s_fileName = str(myFile).strip()
+		if s_fileName.endswith(('.hg','.Hg','.hG','.HG'),0,3):
+			#don't add internal hg files to timestamp list.
+			#QUESTION: is there a better way to check for this?
+			ui.debug('    (skipped):  ' + s_fileName + '\n')
 		else:
-			TimeStamp_dict[fileName] = -1	#initialize dictionary entry
-			TimeStamp_list.append(fileName)	#create list entry
-			ui.debug('Tracking:  ' + fileName + '\n')
-	return #!!!temporary testing stop!!!
+			TimeStamp_dict[s_fileName] = -1	#initialize dictionary entry
+			TimeStamp_list.append(s_fileName)	#create list entry
+			ui.debug('Tracking:  ' + s_fileName + '\n')
+		#end of check for internal files.
+	#end of loop through repo files.
 	
-	for line in file_TimeStampRecords.readlines():
-		#read the data from the line. (CSV format: [FileName],[ModificationTime])
-		try:
-			fileName, fileModTime = line.strip().split(',')
-		except:
-			#split failed, so check for an entry w/o a timestamp.
-			if (len(line)>0):
-				#data present, but missing timestamp?
-				fileName = line.strip()
-				fileModTime = str(-1)
-			#end of check line length non-zero.
+	#====================
+	#Retrieve existing timestamps from the record file.
+	#--------------------
+	if not flag_FileErr:
+		ui.debug('______\nRetrieveing timestamps from record file:\n------\n')
+		for s_line in file_TimeStampRecords.readlines():
+			#read the data from the line. (CSV format: [FileName],[ModificationTime])
+			try:
+				s_fileName, s_fileModTime = s_line.strip().split(',')
+			except:
+				#split failed, so check for an entry w/o a timestamp.
+				if (len(s_line)>0):
+					#data present, but missing timestamp?
+					s_fileName = s_line.strip()
+					s_fileModTime = str(-1)
+				#end of check line length non-zero.
+			#end of read data from line.
 			
-		if (len(fileName)>0):		
-			TimeStamp_dict[fileName] = float(fileModTime)
-			TimeStamp_list.append(fileName)
-			ui.debug('fileName: '+fileName+'\t fileModTime: '+fileModTime+'\n')
-		#end of check file name length non-zero.
+			if (len(s_fileName)>0):
+				if s_fileName in TimeStamp_dict:
+					TimeStamp_dict[s_fileName] = float(s_fileModTime)
+					ui.debug('fileName: '+s_fileName+'\t fileModTime: '+s_fileModTime+'\n')
+				#end of check file exists in dictionary.
+			#end of check file name length non-zero.
+		#end of readlines from record file.
+	#end of check file error.
 	
-	#end of readlines from record file.
-	
+	#====================
 	#Check for command optional argument
+	#--------------------
 	if opts['save']:
 		#Save timestamps for all files under version control (typically pre-commit)
-		ui.note('saving timestamps...\n')
+		ui.note('______\nSaving timestamps...\n------\n')
 		
 		
 	elif opts['restore']:
 		#Restore timestamps of all files under version control (typically post-update/post-restore)
-		ui.note('restoring timestamps...\n')
+		ui.note('______\nRestoring timestamps...\n------\n')
 		
 	else:
 		#no options, just display data in output status
-		ui.note('displaying timestamps...\n')
-		for fileName in TimeStamp_list:
-			#retrieve recorded time and make sure it is in the right datatype
-			fileModTime=float(TimeStamp_dict[fileName])
+		ui.note('______\nDisplaying timestamps...\n------\n')
+		for s_fileName in TimeStamp_list:
+			#retrieve recorded time and make sure it is a floating point datatype
+			f_fileModTime = float(TimeStamp_dict[s_fileName])
 			#check for valid timestamp
-			if (fileModTime>=0):
+			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(fileModTime)), " \t", fileName, "\n")
+				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.
-				ui.status(fileName, ' skipped - no timestamp recorded\n')
+				ui.status(s_fileName, ' skipped - no timestamp recorded\n')
 			#end of check for valid timestamp
 		#end of filenames in list
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.