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 the context search thread

Changeset 5ac961a16bbb

Parent 8a2e965d918d

by Steve Borho

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

 
35
36
37
 
38
39
40
 
84
85
86
 
 
 
87
88
89
90
91
 
 
92
 
 
 
 
 
 
 
 
 
93
94
95
96
97
98
 
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111
112
113
 
 
114
115
116
117
118
 
119
120
121
122
123
124
 
 
 
 
125
126
127
 
35
36
37
38
39
40
41
 
85
86
87
88
89
90
91
92
 
 
 
93
94
95
96
97
98
99
100
101
102
103
104
105
 
 
106
107
108
 
117
118
119
120
121
122
123
124
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
@@ -35,6 +35,7 @@
  def __init__(self, root=None, parent=None):   QWidget.__init__(self, parent)   + self.thread = None   root = paths.find_root(root)   repo = hg.repository(ui.ui(), path=root)   assert(repo) @@ -84,15 +85,24 @@
    def searchActivated(self):   'User pressed [Return] in QLineEdit' + if self.thread and self.thread.isRunning(): + return +   model = self.tv.model()   model.reset() - regexp = hglib.fromunicode(self.le.text()) - icase = self.chk.isChecked() - if not regexp: + pattern = hglib.fromunicode(self.le.text()) + if not pattern:   return + try: + icase = self.chk.isChecked() + regexp = re.compile(pattern, icase and re.I or 0) + except Exception, inst: + msg = _('grep: invalid match pattern: %s\n') % inst + self.emit(SIGNAL('errorMessage'), msg) + print inst + return +   self.le.selectAll() - searchre = re.compile(regexp, icase and re.I or 0) -   mode = self.cb.currentIndex()   if mode == 0:   ctx = self.repo[None] @@ -107,21 +117,44 @@
    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'), + lambda row: model.appendRow(*row)) + self.thread.start() + + + +class CtxSearchThread(QThread): + '''Background thread for searching a changectx''' + def __init__(self, repo, regexp, ctx, parent=None): + super(CtxSearchThread, self).__init__() + self.repo = repo + self.regexp = regexp + self.ctx = ctx + + def run(self):   hu = htmlui.htmlui()   # searching len(ctx.manifest()) files - for wfile in ctx: # walk manifest - data = ctx[wfile].data() # load file data + for wfile in self.ctx: # walk manifest + data = self.ctx[wfile].data() # load file data   if '\0' in data:   continue   for i, line in enumerate(data.splitlines()):   pos = 0 - for m in searchre.finditer(line): # perform regexp + for m in self.regexp.finditer(line): # perform regexp   hu.write(line[pos:m.start()])   hu.write(line[m.start():m.end()], label='grep.match')   pos = m.end()   if pos:   hu.write(line[pos:]) - model.appendRow(wfile, i, None, None, hu.getdata()[0]) + row = [wfile, i, None, None, hu.getdata()[0]] + self.emit(SIGNAL('matchedRow'), row) + self.emit(SIGNAL('finished')) +    COL_PATH = 0  COL_LINE = 1