1. Nathan Durnan
  2. TimeStampMod

Commits

Nathan Durnan  committed 2fd8123

Add Hook_Post_Resolve to pick up new timestamps after resolving timestamp file.
See Issue #27 at BitBucket.
Also updated instructions to include manual hooks for TortoiseHg.

  • Participants
  • Parent commits 3b9cac9
  • Branches BBI#27

Comments (0)

Files changed (3)

File .hgtimestamp

View file
 .hgignore,1305849292.78
 .hgtags,1323983941.97
-README.rst,1312921197.45
+README.rst,1328133746.06
 TimeStampMod.png,1305052883.0
-TimestampMod.py,1328130234.63
+TimestampMod.py,1328132974.11
 TimeStampMod.xmind,1306451621.66

File README.rst

View file
     [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.
 

File TimestampMod.py

View file
 	# 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 hook does not seem to be recognized by TortoiseHg.
+	#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('TimestampMod|Wrap_Commit intercepted - Merge in progress\n')
-		#Call Post-Merge hook when committing a merge-in-progress.
-		#  This is needed because TortoiseHg does not pick up the Post-Merge
-		#  hook correctly.  Also, the contents of the timestamp file will likely
-		#  be manually edited/merged even after a normal post-merge if there 
-		#  were any unresolved conflicts.  Calling it here ensures that the
-		#  timestamps from the merged timestamp file are applied correctly in
-		#  the working directory.
-		Hook_Post_Merge(repo)
+		repo.ui.status('TimestampMod|Wrap_Commit aborted - Merge in progress\n')
 	else:
 		# Make sure the match object is created.
 		if not match:
 
 def Hook_Post_Merge(repo, **kwargs):
 	repo.ui.note("TimestampMod|Post-Merge Hook accessed!\n")
-	#repo.ui.status("Post-Merge:kwargs = \n", str(kwargs), '\n')
+	#repo.ui.debug("Post-Merge:kwargs = \n", str(kwargs), '\n')
 	myPreview = False #starting value
 	if ('opts' in kwargs):
 		if ('preview' in kwargs['opts']):
 		#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')
+	if (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 ______________________________________________________