Commits

Michael Diamond committed ae14cb3

Improved add command to output minimum necessary prefix of new issue

Comments (0)

Files changed (4)

-Should output prefix of newly added bug if possible          | owner:Michael, open:True, id:1364b6de76f3b532867da63223a45d429ba08a46, time:1277687762.41
+Should output prefix of newly added bug if possible          | owner:Michael, open:False, id:1364b6de76f3b532867da63223a45d429ba08a46, time:1277687762.41
 list command reports no such file when bugs dir doesn't exist | owner:Michael, open:False, id:21d24c2b58102a88fa7d6ee78cd190c5b10dafa1, time:1278106675.1
 Need to add bug files automatically                          | owner:Michael, open:False, id:27e00056bfc988ab41c023b5c0a9db9f5e9fa527, time:1277581398.52
 missing unicode support                                      | owner:ArneBab, open:True, id:286b661789a9b4ae60ffd0754888cf43563ce668, time:1306670417.88

.bugs/details/1364b6de76f3b532867da63223a45d429ba08a46.txt

 # Comments and updates - leave your name
 
 On: Thursday, July 22 2010 03:50PM
-Improved b to output a generic (10 char) prefix of the bug, but it would be very nice if it output the current, proper prefix.  This would likely involve a new function to calculate an individual ID's prefix.
+Improved b to output a generic (10 char) prefix of the bug, but it would be very nice if it output the current, proper prefix.  This would likely involve a new function to calculate an individual ID's prefix.
+
+By: Michael
+On: Sunday, December 25 2011 02:14AM
+Implemented a resolution to this issue, however it adds an O(n) complexity to the add command.  Given normal usage, this is likely acceptable, however it can be disabled by mercurial configuration if necessary, for instance when bulk adding issues.
+
+Using `--config 'bugs.fast_add=True'` at the command line will disable this temporarily.
         """
         timelimit = 4   # seconds to allow to run
         numbugs = 10000 # number of bugs to create before testing - increase this when possible
+        self.bd.fast_add = True
         for i in range(0,numbugs):
             self.bd.add('This is bug %s - be nice to it' % str(i))
             
     and therefore anything calling this class ought to handle that change
     (normally to the repo root)
     """
-    def __init__(self,bugsdir='.bugs',user=''):
+    def __init__(self,bugsdir='.bugs',user='',fast_add=False):
         """Initialize by reading the task files, if they exist."""
         self.bugsdir = bugsdir
         self.user = user
+        self.fast_add = fast_add
         self.file = 'bugs'
         self.detailsdir = 'details'
         self.last_added_id = None
         task_id = _hash(text) if _simple_hash else _hash(text+self.user+str(time.time()))
         self.bugs[task_id] = {'id': task_id, 'open': 'True', 'owner': self.user, 'text': text, 'time': time.time()}
         self.last_added_id = task_id
-        return _("Added bug %s...") % task_id[:10]
+        if not self.fast_add:
+            prefix = _prefixes(self.bugs.keys())[task_id]
+            prefix = "%s:%s" % (prefix, task_id[len(prefix):10])
+        else:
+            prefix = "%s..." % task_id[:10]
+        return _("Added bug %s") % prefix
     
     def rename(self, prefix, text):
         """Renames the bug
     try:
         bugsdir = ui.config("bugs","dir",".bugs")
         user = ui.config("bugs","user",'')
+        fast_add = ui.configbool("bugs","fast_add",False)
         if user == 'hg.user':
             user = ui.username()
         path = repo.root
                 _cat(ui,repo,os.path.join(bugsdir,'bugs'),revpath,rev)
             os.chdir(revpath)
 
-        bd = BugsDict(bugsdir,user)
+        bd = BugsDict(bugsdir,user,fast_add)
         
         if opts['rev'] and 'details'.startswith(cmd):
             # if it's a details command, try to get the details file