Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

grep: thread searches, implement history search

Changeset 6aa056e52715

Parent 5ac961a16bbb

by Steve Borho

Changes to one file · Browse files at 6aa056e52715 Showing diff from parent 5ac961a16bbb Diff from another changeset...

 
8
9
10
11
 
12
13
14
 
21
22
23
24
25
26
27
28
29
30
31
 
32
33
34
 
99
100
101
102
103
104
105
106
107
 
 
108
 
109
 
 
110
 
111
112
113
114
115
116
 
117
118
119
120
121
122
123
124
125
 
127
128
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131
132
 
137
138
139
 
140
141
142
 
8
9
10
 
11
12
13
14
 
21
22
23
 
 
24
25
26
27
28
29
30
31
32
33
 
98
99
100
 
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
 
 
118
119
 
 
120
 
 
121
122
123
 
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
184
185
186
187
188
189
190
@@ -8,7 +8,7 @@
 import os  import re   -from mercurial import ui, hg, error +from mercurial import ui, hg, error, commands    from tortoisehg.hgqt import htmlui, visdiff, qtlib  from tortoisehg.util import paths, hglib @@ -21,14 +21,13 @@
 # prove search features    # Technical Debt -# hg grep functionality -# thread the searches  # draggable matches from history  # tortoisehg.editor with line number  # smart visual diffs  # context menu for matches  # emit errors to parent's status bar  # emit to parent's progress bar +# ESC should cancel current search  # turn HTMLDelegate into a column delegate, merge back with htmllistview    class SearchWidget(QWidget): @@ -99,27 +98,26 @@
  except Exception, inst:   msg = _('grep: invalid match pattern: %s\n') % inst   self.emit(SIGNAL('errorMessage'), msg) - print inst   return     self.le.selectAll()   mode = self.cb.currentIndex()   if mode == 0: + self.tv.setColumnHidden(COL_REVISION, True) + self.tv.setColumnHidden(COL_USER, True)   ctx = self.repo[None] + self.thread = CtxSearchThread(self.repo, regexp, ctx)   elif mode == 1: + self.tv.setColumnHidden(COL_REVISION, True) + self.tv.setColumnHidden(COL_USER, True)   ctx = self.repo['.'] + self.thread = CtxSearchThread(self.repo, regexp, ctx)   else:   self.tv.setColumnHidden(COL_REVISION, False)   self.tv.setColumnHidden(COL_USER, False) - # Full blown 'hg grep' call - # hg grep [-i] -afn regexp - return + self.thread = HistorySearchThread(self.repo, pattern, icase)   - self.tv.setColumnHidden(COL_REVISION, True) - self.tv.setColumnHidden(COL_USER, True)   self.le.setEnabled(False) - - self.thread = CtxSearchThread(self.repo, regexp, ctx)   self.connect(self.thread, SIGNAL('finished'),   lambda: self.le.setEnabled(True))   self.connect(self.thread, SIGNAL('matchedRow'), @@ -127,6 +125,55 @@
  self.thread.start()     +class HistorySearchThread(QThread): + '''Background thread for searching repository history''' + def __init__(self, repo, pattern, icase, parent=None): + super(HistorySearchThread, self).__init__() + self.repo = repo + self.pattern = pattern + self.icase = icase + + def run(self): + # special purpose - not for general use + class incrui(ui.ui): + def __init__(self, src=None): + super(incrui, self).__init__(src) + self.setconfig('ui', 'interactive', 'off') + self.setconfig('progress', 'disable', 'True') + os.environ['TERM'] = 'dumb' + qtlib.configstyles(self) + self.fullmsg = '' + + def write(self, msg, *args, **opts): + if msg.endswith('\n'): + self.fullmsg += msg + fname, line, rev, addremove, user, text = \ + self.fullmsg.split(':', 5) + row = [fname, line, rev, user, addremove + ' ' + text] + self.obj.emit(SIGNAL('matchedRow'), row) + self.fullmsg = '' + else: + if opts.get('label'): + self.fullmsg += self.label(msg, opts['label']) + else: + self.fullmsg += msg + + def label(self, msg, label): + msg = hglib.tounicode(msg) + msg = Qt.escape(msg) + msg = msg.replace('\n', '<br />') + style = qtlib.geteffect(label) + return '<span style="%s">%s</span>' % (style, msg) + + # hg grep [-i] -afn regexp + opts = {'all':True, 'user':True, 'follow':True, 'rev':[], + 'line_number':True, 'print0':False, + 'ignore_case':self.icase, + } + u = incrui() + u.obj = self + commands.grep(u, self.repo, self.pattern, **opts) + self.emit(SIGNAL('finished'))    class CtxSearchThread(QThread):   '''Background thread for searching a changectx''' @@ -137,6 +184,7 @@
  self.ctx = ctx     def run(self): + # this will eventually be: hg grep -c   hu = htmlui.htmlui()   # searching len(ctx.manifest()) files   for wfile in self.ctx: # walk manifest