Commits

Nathan Durnan committed 44c8207 Merge

Merge with BBI#27 - Update timestamps after merge
See Issue #27 at BitBucket

  • Participants
  • Parent commits bb96a2f, f5c7bb4

Comments (0)

Files changed (3)

 .hgignore,1305849292.78
 .hgtags,1327960909.75
-README.rst,1312921197.45
+README.rst,1328133746.06
 TimeStampMod.png,1305052883.0
-TimestampMod.py,1327960495.36
+TimestampMod.py,1328134752.84
 TimeStampMod.xmind,1306451621.66
     [extensions]
     TimestampMod = /path/to/TimestampMod.py
 
+If using TortoiseHg, some of the hooks will need to be manually configured.  
+Add entries into the hooks section of the configuration file (**mercurial.ini**) 
+similar to the following::
+    
+    [hooks]
+    post-merge.TimestampMod = python:/path/to/TimestampMod.py:Hook_Post_Merge
+    post-resolve.TimestampMod = python:/path/to/TimestampMod.py:Hook_Post_Resolve
+
 Nothing further is required to make the extension work.  It will set up it's 
 own hooks that will trigger during committing and updating actions automatically.
 
 	# 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)'''
+	#NOTE: the post-merge and post-resolve hooks are not picked up by TortoiseHg.
+	#  When using this extension with TortoiseHg, these hooks must be manually
+	#  added to the "mercurial.ini" configuration file.  
+	#  Use the following format:
+	#    [hooks]
+	#    post-merge.TimestampMod = python:{path-to-TimestampMod.py}:Hook_Post_Merge
+	#    post-resolve.TimestampMod = python:{path-to-TimestampMod.py}:Hook_Post_Resolve
+	ui.setconfig("hooks", "post-merge.TimestampMod", Hook_Post_Merge)
+	ui.setconfig("hooks", "post-resolve.TimestampMod", Hook_Post_Resolve)
 #_ end of uisetup _____________________________________________________________
 
 
 	#Check for a merge-commit. 
 	#  Don't run timestamp code on merge.
 	if (len(repo.parents()) > 1):
-		repo.ui.status('Wrap_Commit aborted - Merge in progress\n')
+		repo.ui.status('TimestampMod|Wrap_Commit aborted - Merge in progress\n')
 	else:
 		# Make sure the match object is created.
 		if not match:
 	kwargs['pats'].append(File_TimestampRecords)
 ''' # Hook_Pre_Commit is depreciated
 def Hook_Post_Status(repo, **kwargs):
-	repo.ui.note("Post-Status Hook accessed!\n")
+	repo.ui.note("TimestampMod|Post-Status Hook accessed!\n")
 	timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': None}))
 
 def Hook_Update(repo, **kwargs):
-	repo.ui.note("Update Hook accessed!\n")
-	timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': True}))
+	repo.ui.note("TimestampMod|Hook_Update accessed!\n")
+	if (len(repo.parents()) > 1):
+		repo.ui.status('TimestampMod|Hook_Update aborted - Merge in progress\n')
+	else:
+		timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': True}))
+	#end of check for merging.
+
+def Hook_Post_Merge(repo, **kwargs):
+	repo.ui.note("TimestampMod|Post-Merge Hook accessed!\n")
+	#repo.ui.debug("Post-Merge:kwargs = \n", str(kwargs), '\n')
+	myPreview = False #starting value
+	if ('opts' in kwargs):
+		if ('preview' in kwargs['opts']):
+			myPreview = kwargs['opts']['preview']
+		#end of check for 'preview' option.
+	#end of check for 'opts' keyword.
+	if not myPreview:
+		#only update timestamps if not just a preview.
+		timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': True}))
+	#check for preview option.
+
+def Hook_Post_Resolve(repo, **kwargs):
+	repo.ui.note("TimestampMod|Post-Resolve Hook accessed!\n")
+	#repo.ui.debug("Post-Resolve:kwargs = \n", str(kwargs), '\n')
+	myResolveAll = False #starting value
+	if ('opts' in kwargs):
+		if ('all' in kwargs['opts']):
+			myResolveAll = kwargs['opts']['all']
+		#end of check for 'preview' option.
+	#end of check for 'opts' keyword.
+	if (myResolveAll or (File_TimestampRecords in str(kwargs['pats']))):
+		#Only re-apply timestamps if the timestamp file is the one being resolved.
+		repo.ui.status("Resolved timestamp file - Reapplying timestamps!\n")
+		timestamp_mod(repo.ui, repo, **dict({'save': None, 'restore': True}))
+	#end of check for timestamp file resolve.
 #_ end of Hook Functions ______________________________________________________