title: How to know if a git repository is clean with Python3 (pygit2)?
body: <p>I'm trying to determine if a  or <code>git commit</code> is needed in a git repository. I come up with this code that works fine for me :</p>
  
  <pre><code>def is_dirty(repo):
    import pygit2
    status = repo.status()
    for filepath, flags in status.items():
      if flags != pygit2.GIT_STATUS_CURRENT:
          if flags != 16384:
              return True
    return False;
  </code></pre>
  
  <p>But this is extremely inefficient : the <code>repo.status()</code> takes forever -- at least compared to the <code>git status</code> command line.</p>
  
  <p>So my question is : is there a more efficient way to know if the repository is clean ?</p>
  
  <p>PS : I'm using python3. With python2 I used the module <code>git</code> that has a <code>is_dirty</code> function.</p>