hgext/git/index.py
changeset 52627 4dadaf300fe0
parent 52626 42f00965e50b
child 52628 3865451a5fab
equal deleted inserted replaced
52626:42f00965e50b 52627:4dadaf300fe0
   220     db.commit()
   220     db.commit()
   221 
   221 
   222 
   222 
   223 def _index_repo_commit(gitrepo, db, node, commit=False):
   223 def _index_repo_commit(gitrepo, db, node, commit=False):
   224     already_done = db.execute(
   224     already_done = db.execute(
   225         "SELECT changedfiles FROM changelog WHERE node=?", (node.id.hex,)
   225         "SELECT changedfiles FROM changelog WHERE node=?", (node,)
   226     ).fetchone()[0]
   226     ).fetchone()[0]
   227     if already_done:
   227     if already_done:
   228         return  # This commit has already been indexed
   228         return  # This commit has already been indexed
   229 
   229 
   230     commit = gitrepo[node]
   230     commit = gitrepo[node]
   331                 p1 = commit.parents[0].id.hex
   331                 p1 = commit.parents[0].id.hex
   332             if len(commit.parents) == 2:
   332             if len(commit.parents) == 2:
   333                 p2 = commit.parents[1].id.hex
   333                 p2 = commit.parents[1].id.hex
   334             pos += 1
   334             pos += 1
   335             db.execute(
   335             db.execute(
   336                 'INSERT INTO changelog (rev, node, p1, p2, synthetic, changedfiles) VALUES(?, ?, ?, ?, NULL, TRUE)',
   336                 'INSERT INTO changelog (rev, node, p1, p2, synthetic, changedfiles) VALUES(?, ?, ?, ?, NULL, FALSE)',
   337                 (pos, commit.id.hex, p1, p2),
   337                 (pos, commit.id.hex, p1, p2),
   338             )
   338             )
   339         else:
   339         else:
   340             parents = list(commit.parents)
   340             parents = list(commit.parents)
   341 
   341 
   351                     synth = commit.id.hex
   351                     synth = commit.id.hex
   352 
   352 
   353                 p2 = parents.pop(0).id.hex
   353                 p2 = parents.pop(0).id.hex
   354 
   354 
   355                 db.execute(
   355                 db.execute(
   356                     'INSERT INTO changelog (rev, node, p1, p2, synthetic, changedfiles) VALUES(?, ?, ?, ?, ?, TRUE)',
   356                     'INSERT INTO changelog (rev, node, p1, p2, synthetic, changedfiles) VALUES(?, ?, ?, ?, ?, FALSE)',
   357                     (pos, this, p1, p2, synth),
   357                     (pos, this, p1, p2, synth),
   358                 )
   358                 )
   359 
   359 
   360                 p1 = this
   360                 p1 = this
   361 
   361     # Determine heads from the list of possible heads.
   362         num_changedfiles = db.execute(
       
   363             "SELECT COUNT(*) from changedfiles WHERE node = ?",
       
   364             (commit.id.hex,),
       
   365         ).fetchone()[0]
       
   366         if not num_changedfiles:
       
   367             _index_repo_commit(gitrepo, db, commit)
       
   368     db.execute('DELETE FROM heads')
   362     db.execute('DELETE FROM heads')
   369     db.execute('DELETE FROM possible_heads')
   363     db.execute('DELETE FROM possible_heads')
   370     db.executemany(
   364     db.executemany(
   371         'INSERT INTO possible_heads (node) VALUES(?)',
   365         'INSERT INTO possible_heads (node) VALUES(?)',
   372         [(hid.hex,) for hid in possible_heads],
   366         [(hid.hex,) for hid in possible_heads],
   380                     changelog.p1 = possible_heads.node OR
   374                     changelog.p1 = possible_heads.node OR
   381                     changelog.p2 = possible_heads.node
   375                     changelog.p2 = possible_heads.node
   382             )
   376             )
   383     '''
   377     '''
   384     )
   378     )
       
   379     # Mark all commits with already-loaded changefiles info
       
   380     db.execute(
       
   381         '''
       
   382     UPDATE changelog SET changedfiles=TRUE WHERE node IN (
       
   383         SELECT DISTINCT node FROM changedfiles
       
   384     )
       
   385     '''
       
   386     )
       
   387 
       
   388     if prog is not None:
       
   389         prog.complete()
       
   390 
       
   391     # Index the changed files for head commits
       
   392     prog = progress_factory(b'indexing head files')
       
   393     heads = [
       
   394         row[0].decode('ascii') for row in db.execute("SELECT * FROM heads")
       
   395     ]
       
   396     for pos, h in enumerate(heads):
       
   397         if prog is not None:
       
   398             prog.update(pos)
       
   399         _index_repo_commit(gitrepo, db, h)
   385 
   400 
   386     db.commit()
   401     db.commit()
   387     if prog is not None:
   402     if prog is not None:
   388         prog.complete()
   403         prog.complete()
   389 
   404