Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

GitRepository getDirectoryStatus mishandles project root directory #9240

Closed
@glangford

Description

@glangford

When passed a project root directory, getDirectoryStatus relativizes the path into a "/". As a result, subsequent checks never match any path, since they do not start with "/". The directory status of the root is always returned as zero.

Here is the current code from git-repository.coffee; note the trailing slash at @relativize:

getDirectoryStatus: (directoryPath)  ->
    directoryPath = "#{@relativize(directoryPath)}/"
    directoryStatus = 0
    for path, status of @statuses
      directoryStatus |= status if path.indexOf(directoryPath) is 0
    directoryStatus

Suggestions:

  • Change this so that directoryStatus is correctly calculated when given the project root
  • For performance consider using .startsWith() or .lastIndexOf(str, 0) for path comparison so that entire strings are not compared
  • Consider early exit from the loop if the maximum possible value of directoryStatus is reached and logical OR of more bits won't change things (not sure what the maximum is)

Motivation for change and references:

Highlight git changes on the level of a project
atom/tree-view#564

getDirectoryStatus code
https://github.com/atom/atom/blob/master/src/git-repository.coffee#L305

String prefix
http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string#4579228

Activity

stale

stale commented on Aug 29, 2017

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

lock

lock commented on Mar 30, 2018

@lock

This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

locked and limited conversation to collaborators on Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      GitRepository getDirectoryStatus mishandles project root directory · Issue #9240 · atom/atom