53394fbc3bc0 — Oben Sonne 15 years ago
Conider bookmarks track.current option

If the track.current option if the bookmarks extensions is enabled the
acitve bookmark is annotated with a '*'. Furhter, when being at a
bookmarked revisions with no active bookmark, a warning is printed that
none of the bookmarks will move on commit.

Fixes issue #1.
1 files changed, 20 insertions(+), 0 deletions(-)

M compass.py
M compass.py +20 -0
@@ 38,6 38,7 @@ Website: http://bitbucket.org/obensonne/
 
 """
 
+import os.path
 import re
 import time
 

          
@@ 78,6 79,16 @@ class RepoInfo(object):
         # all head revisions
         self.head_revs = _csi2rev(repo, repo.heads())
         
+        # name of currently active bookmark (if enabled)
+        self.bm_track_current = repo.ui.config("bookmarks", "track.current")
+        bm_current_file = os.path.join(repo.root, ".hg", "bookmarks.current")
+        if self.bm_track_current and os.path.exists(bm_current_file):
+            fp = open(bm_current_file)
+            self.bm_current = fp.read()
+            fp.close()
+        else:                
+            self.bm_current = None  
+        
         # all bookmarked revisions
         bm_names = self.tags_and_bookmarks()[1]
         self.bm_revs = [repo[x].rev() for x in bm_names]

          
@@ 175,6 186,7 @@ class NodeInfo(object):
             whether to provide detailed or short output in __str__()
             
         """
+        self.ri = ri
         self.ctx = ctx
         self.verbose = verbose
 

          
@@ 201,6 213,8 @@ class NodeInfo(object):
         td["age"] = self.__format_age()
         td["branch"] = self.branch
         td["bookmarks"] = _slist(self.bookmarks, pre="(", suf=")")
+        td["bookmarks"] = re.sub(r'([( ])(%s)([ )])' % self.ri.bm_current,
+                                 r'\1\2*\3', td["bookmarks"])
         td["tags"] = _slist(self.tags, suf=" ")
         self.labels = [("@%s" % x) for x in self.labels]
         td["labels"] = _slist(self.labels, suf=" ")

          
@@ 428,6 442,12 @@ def compass(ui, repo, **opts):
     if not ni.rev in ri.head_revs:
         s += _header("Next commit will create a new head!", fc="-")
     
+    ### sleeping bookmarks warning  ###
+    
+    if ni.bookmarks and ri.bm_track_current and not ri.bm_current:
+        s += _header("None of your bookmarks (%s) will move on commit!" %
+                     ' '.join(ni.bookmarks), fc="-")
+    
     ui.write(s)
     
 # =============================================================================