Make repository select the deepest repository in the directory tree

Review Request #9620 — Created Feb. 11, 2018 and submitted

Information

RBTools
release-0.7.x
7a16851...

Reviewers

Without the presence of a .reviewboardrc file which defines
REPOSITORY_TYPE, RBTools will try to auto-detect the repository type by running
various commands like "svn info", "hg root", etc. This will run through each
repository type until one is found that works.

Unfortunately, if people have nested repositories, this means
RBTools can select the wrong one. For example, some people may have
/home/user/ as a git directory, and /home/user/src/project/ is a subversion
checkout, running "rbt" within their "project" directory may detect it as git
instead of svn.

This change auto-detects all repository types, and then selects the
deepest one. In the case of multiple matching repositories, we output a
warning suggesting that people define REPOSITORY_TYPE in .reviewboardrc in
order to speed up detection.

  • Tested combinations of nested svn, git, hg repos.
  • All unit tests pass.
Description From Last Updated

Can you wrap your description to 70 columns?

daviddavid

E265 block comment should start with '# '

reviewbotreviewbot

E501 line too long (98 > 79 characters)

reviewbotreviewbot

E501 line too long (83 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (95 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E265 block comment should start with '# '

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E265 block comment should start with '# '

reviewbotreviewbot

E501 line too long (110 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (82 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (95 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E265 block comment should start with '# '

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E265 block comment should start with '# '

reviewbotreviewbot

E501 line too long (110 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E501 line too long (82 > 79 characters)

reviewbotreviewbot

E266 too many leading '#' for block comment

reviewbotreviewbot

E261 at least two spaces before inline comment

reviewbotreviewbot

E114 indentation is not a multiple of four (comment)

reviewbotreviewbot

E116 unexpected indentation (comment)

reviewbotreviewbot

E114 indentation is not a multiple of four (comment)

reviewbotreviewbot

E116 unexpected indentation (comment)

reviewbotreviewbot

E126 continuation line over-indented for hanging indent

reviewbotreviewbot

E261 at least two spaces before inline comment

reviewbotreviewbot

E114 indentation is not a multiple of four (comment)

reviewbotreviewbot

E116 unexpected indentation (comment)

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

E501 line too long (86 > 79 characters)

reviewbotreviewbot

E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

E261 at least two spaces before inline comment

reviewbotreviewbot

E114 indentation is not a multiple of four (comment)

reviewbotreviewbot

E116 unexpected indentation (comment)

reviewbotreviewbot

E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

E261 at least two spaces before inline comment

reviewbotreviewbot

E114 indentation is not a multiple of four (comment)

reviewbotreviewbot

E116 unexpected indentation (comment)

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

F841 local variable 'local_root' is assigned to but never used

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E303 too many blank lines (2)

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

These should be in alphabetical order.

daviddavid

Should be "self.path". Even though it's starting a sentence, self refers to a symbol.

daviddavid

There's an extra space at the beginning of this comment line.

daviddavid

Add a blank line between these (we like to have a bit of space before and after blocks)

daviddavid

Add a blank line between these.

daviddavid

Hmmm. We should probably just make sure that get_repository_info doesn't change things. Needing a special case here is ugly.

daviddavid

Add a blank line between these.

daviddavid

We generally prefer to have the joining space at the end of the previous line instead of the beginning of …

daviddavid

Blank line between these.

daviddavid

Blank line between these.

daviddavid

Blank line between these.

daviddavid

Also not necessary if we fix up GitClient.

daviddavid

This looks like leftover debug output. Can we get rid of it?

daviddavid

More fallout from GitClient being dumb.

daviddavid

And here.

daviddavid

Blank line between these.

daviddavid

I think this function might be a bit too long. Might be a good idea to break it up, for …

rpolyanorpolyano

Too many blank lines here now.

daviddavid

Not enough blank lines here now.

daviddavid

Blank line here.

daviddavid

Would it make sense to move all of these Regexes out into one place and a) have them organized by …

rpolyanorpolyano

Blank line here.

daviddavid

Blank line here.

daviddavid

Blank line here.

daviddavid

This should fit all on one line.

daviddavid

From my understanding, the idea here is to find the deepest repo in terms of directory depth right? Using the …

jshephardjshephard

This would wrap more nicely as: if (repo.local_root and len(os.path.normpath(repo.local_root)) > deepest_repo):

daviddavid

Does the >>>>>>>> mean anything or is it a part of the reviewboard UI?

JT jtrang

Oh I see! That makes a lot more sense. Thank you!

JT jtrang

Please use single quotes instead of double, and add a blank line above this.

daviddavid

Same comment as above. I'm not sure if the chevrons are appearing as part of the UI or not.

JT jtrang
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

MA
Review request changed
Change Summary:

Check if git changes the CWD, roll back until other clients find their repos, and then find deepest repo. Cannot stop gitClient from changing CWD as that ensures diffs on server are not messed up. Check if git changes the CWD, roll back until other clients find their repos, and then find deepest. Cannot stop gitClient from changing CWD as that ensures diffs on server are not messed up.

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
MA
Review request changed
Description:
   

Without the presence of a .reviewboardrc file which defines REPOSITORY_TYPE, RBTools will try to auto-detect the repository type by running various commands like "svn info", "hg root", etc. This will run through each repository type until one is found that works.

   
~  

Unfortunately, if people have nested repositories, this means RBTools can select the wrong one. For example, some people may have /home/user/ as a git directory, and /home/user/src/project/ is a subversion checkout, running "rbt" within their "project" directory may detect it as git instead of svn. We'd like to auto-detect all repository types, and then select the deepest one.

  ~

Unfortunately, if people have nested repositories, this means RBTools can select the wrong one. For example, some people may have /home/user/ as a git directory, and /home/user/src/project/ is a subversion checkout, running "rbt" within their "project" directory may detect it as git instead of svn. This change auto-detects all repository types, and then selects the deepest one.

   
~  

In the case of multiple matching repositories, we may want to output a warning suggesting that people define REPOSITORY_TYPE in .reviewboardrc in order to speed up detection.

  ~

In the case of multiple matching repositories, we output a warning suggesting that people define REPOSITORY_TYPE in .reviewboardrc in order to speed up detection.

Commit:
1b9c14f1524fb0f4d12834f8fdfef956bddc54e1
33dde16cf2afda0204792f8e01a38f75631e8470

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
Review request changed
Change Summary:

Rebased the branch on release-0.7.x to avoid rbt post error after new changes on master were pulled.

Testing Done:
~  
  • Tested combinations of nested svn and git repos, both were unaffected by this issue.
  ~
  • Tested combinations of nested svn, git, hg repos
-  
  • Tested mercurial repo nested in a git repo.
Branch:
deepestrepo
release-0.7.x
Commit:
33dde16cf2afda0204792f8e01a38f75631e8470
6996a3346f42ac105c9025ef413ea7646f9a7e71

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
Review request changed

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
Review request changed
Testing Done:
~  
  • Tested combinations of nested svn, git, hg repos
  ~
  • Tested combinations of nested svn, git, hg repos.

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
Review request changed
Summary:
[WIP] Make repository select the deepest repository in the directory tree
Make repository select the deepest repository in the directory tree
Testing Done:
   
  • Tested combinations of nested svn, git, hg repos.
  +
  • All unit tests pass.

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

MA
david
  1. 
      
  2. Show all issues

    Can you wrap your description to 70 columns?

  3. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
     
     
     
     
    Show all issues

    These should be in alphabetical order.

  4. rbtools/clients/__init__.py (Diff revision 8)
     
     
    Show all issues

    Should be "self.path". Even though it's starting a sentence, self refers to a symbol.

  5. rbtools/clients/__init__.py (Diff revision 8)
     
     
    Show all issues

    There's an extra space at the beginning of this comment line.

  6. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Add a blank line between these (we like to have a bit of space before and after blocks)

  7. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Add a blank line between these.

  8. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Hmmm. We should probably just make sure that get_repository_info doesn't change things. Needing a special case here is ugly.

    1. Should I create a separate function to handle chdir for GitClient and have all calls to GitCleint.get_repository_info() call that function as well?

      (GitClient.get_repository_info() has been doing the directory change for quite some time (https://reviews.reviewboard.org/r/2960/diff/1/#))

  9. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Add a blank line between these.

  10. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    We generally prefer to have the joining space at the end of the previous line instead of the beginning of the next.

  11. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line between these.

  12. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line between these.

  13. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line between these.

  14. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
    Show all issues

    Also not necessary if we fix up GitClient.

  15. rbtools/clients/__init__.py (Diff revision 8)
     
     
    Show all issues

    This looks like leftover debug output. Can we get rid of it?

    1. I thought it would be helpful to have that as part of the output when -debug is specified... Unneccessary? Better phrasing maybe?

  16. rbtools/clients/__init__.py (Diff revision 8)
     
     
    Show all issues

    More fallout from GitClient being dumb.

  17. rbtools/clients/__init__.py (Diff revision 8)
     
     
     
     
     
    Show all issues

    And here.

  18. rbtools/clients/cvs.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line between these.

  19. rbtools/clients/git.py (Diff revision 8)
     
     
     
    Show all issues

    Too many blank lines here now.

  20. rbtools/clients/git.py (Diff revision 8)
     
     
     
    Show all issues

    Not enough blank lines here now.

  21. rbtools/clients/git.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line here.

  22. rbtools/clients/git.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line here.

  23. rbtools/clients/perforce.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line here.

  24. rbtools/clients/svn.py (Diff revision 8)
     
     
     
    Show all issues

    Blank line here.

  25. rbtools/clients/svn.py (Diff revision 8)
     
     
     
    Show all issues

    This should fit all on one line.

  26. 
      
rpolyano
  1. 
      
  2. rbtools/clients/git.py (Diff revision 8)
     
     
    Show all issues

    I think this function might be a bit too long. Might be a good idea to break it up, for example some of the if/branches can be separate functions.

  3. rbtools/clients/git.py (Diff revision 8)
     
     
    Show all issues

    Would it make sense to move all of these Regexes out into one place and a) have them organized by version ranges (e.x. git may change these in some version) and b) compile them

  4. 
      
MA
jshephard
  1. 
      
  2. rbtools/clients/__init__.py (Diff revision 9)
     
     
     
    Show all issues

    From my understanding, the idea here is to find the deepest repo in terms of directory depth right? Using the length of the path to determine this might result in selecting a repo that is in a directory with a large name over another repo that is deeper.

    I'm not sure if this is an issue here though, as your description makes it sound like you're just looking at parent directories of the user's current working directory. In that case this is a non-issue.

    1. Good insticts asking this question, but your caveat is correct--the selected directories will always be parents of the cwd.

  3. 
      
JT
  1. 
      
  2. rbtools/clients/__init__.py (Diff revision 9)
     
     
    Show all issues

    Does the >>>>>>>> mean anything or is it a part of the reviewboard UI?

    1. This is Review Board's diff viewer showing that the code was indented but otherwise unchanged.

  3. rbtools/clients/git.py (Diff revision 9)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    Same comment as above. I'm not sure if the chevrons are appearing as part of the UI or not.

  4. 
      
david
  1. 
      
  2. rbtools/clients/__init__.py (Diff revision 9)
     
     
     
    Show all issues

    This would wrap more nicely as:

    if (repo.local_root and
        len(os.path.normpath(repo.local_root)) > deepest_repo):
    
  3. rbtools/clients/__init__.py (Diff revision 9)
     
     
    Show all issues

    Please use single quotes instead of double, and add a blank line above this.

  4. 
      
JT
  1. 
      
  2. rbtools/clients/__init__.py (Diff revision 9)
     
     
    Show all issues

    Oh I see! That makes a lot more sense. Thank you!

  3. 
      
MA
david
  1. Fixed up remaining issues and landing. Thanks!

  2. 
      
MA
Review request changed
Status:
Completed
Change Summary:
Pushed to release-1.0.x (72dc722)