216 (p1node, p1fnode, p2node, p2fnode, commit.id.hex, path, filenode), |
216 (p1node, p1fnode, p2node, p2fnode, commit.id.hex, path, filenode), |
217 ) |
217 ) |
218 db.commit() |
218 db.commit() |
219 |
219 |
220 |
220 |
|
221 def _index_repo_commit(gitrepo, db, commit): |
|
222 files = {} |
|
223 # I *think* we only need to check p1 for changed files |
|
224 # (and therefore linkrevs), because any node that would |
|
225 # actually have this commit as a linkrev would be |
|
226 # completely new in this rev. |
|
227 p1 = commit.parents[0].id.hex if commit.parents else None |
|
228 if p1 is not None: |
|
229 patchgen = gitrepo.diff(p1, commit.id.hex, flags=_DIFF_FLAGS) |
|
230 else: |
|
231 patchgen = commit.tree.diff_to_tree(swap=True, flags=_DIFF_FLAGS) |
|
232 new_files = (p.delta.new_file for p in patchgen) |
|
233 files = { |
|
234 nf.path: nf.id.hex |
|
235 for nf in new_files |
|
236 if nf.id.raw != sha1nodeconstants.nullid |
|
237 } |
|
238 for p, n in files.items(): |
|
239 # We intentionally set NULLs for any file parentage |
|
240 # information so it'll get demand-computed later. We |
|
241 # used to do it right here, and it was _very_ slow. |
|
242 db.execute( |
|
243 'INSERT INTO changedfiles (' |
|
244 'node, filename, filenode, p1node, p1filenode, p2node, ' |
|
245 'p2filenode) VALUES(?, ?, ?, ?, ?, ?, ?)', |
|
246 (commit.id.hex, p, n, None, None, None, None), |
|
247 ) |
|
248 |
|
249 |
221 def _index_repo( |
250 def _index_repo( |
222 gitrepo, |
251 gitrepo, |
223 db, |
252 db, |
224 logfn=lambda x: None, |
253 logfn=lambda x: None, |
225 progress_factory=lambda *args, **kwargs: None, |
254 progress_factory=lambda *args, **kwargs: None, |
301 num_changedfiles = db.execute( |
330 num_changedfiles = db.execute( |
302 "SELECT COUNT(*) from changedfiles WHERE node = ?", |
331 "SELECT COUNT(*) from changedfiles WHERE node = ?", |
303 (commit.id.hex,), |
332 (commit.id.hex,), |
304 ).fetchone()[0] |
333 ).fetchone()[0] |
305 if not num_changedfiles: |
334 if not num_changedfiles: |
306 files = {} |
335 _index_repo_commit(gitrepo, db, commit) |
307 # I *think* we only need to check p1 for changed files |
|
308 # (and therefore linkrevs), because any node that would |
|
309 # actually have this commit as a linkrev would be |
|
310 # completely new in this rev. |
|
311 p1 = commit.parents[0].id.hex if commit.parents else None |
|
312 if p1 is not None: |
|
313 patchgen = gitrepo.diff(p1, commit.id.hex, flags=_DIFF_FLAGS) |
|
314 else: |
|
315 patchgen = commit.tree.diff_to_tree( |
|
316 swap=True, flags=_DIFF_FLAGS |
|
317 ) |
|
318 new_files = (p.delta.new_file for p in patchgen) |
|
319 files = { |
|
320 nf.path: nf.id.hex |
|
321 for nf in new_files |
|
322 if nf.id.raw != sha1nodeconstants.nullid |
|
323 } |
|
324 for p, n in files.items(): |
|
325 # We intentionally set NULLs for any file parentage |
|
326 # information so it'll get demand-computed later. We |
|
327 # used to do it right here, and it was _very_ slow. |
|
328 db.execute( |
|
329 'INSERT INTO changedfiles (' |
|
330 'node, filename, filenode, p1node, p1filenode, p2node, ' |
|
331 'p2filenode) VALUES(?, ?, ?, ?, ?, ?, ?)', |
|
332 (commit.id.hex, p, n, None, None, None, None), |
|
333 ) |
|
334 db.execute('DELETE FROM heads') |
336 db.execute('DELETE FROM heads') |
335 db.execute('DELETE FROM possible_heads') |
337 db.execute('DELETE FROM possible_heads') |
336 db.executemany( |
338 db.executemany( |
337 'INSERT INTO possible_heads (node) VALUES(?)', |
339 'INSERT INTO possible_heads (node) VALUES(?)', |
338 [(hid.hex,) for hid in possible_heads], |
340 [(hid.hex,) for hid in possible_heads], |