Skip to content

Commit

Permalink
[Fix #667] Use file-truename when caching current file
Browse files Browse the repository at this point in the history
  • Loading branch information
colonelpanic8 committed Jun 12, 2015
1 parent cc56126 commit 924d731
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
### Bugs fixed

* [#721](https://github.com/bbatsov/projectile/issues/721#issuecomment-100830507): Remove current buffer from `helm-projectile-switch-project`.
* [#667](https://github.com/bbatsov/projectile/issues/667) Use `file-truename` when caching filenames to prevent duplicate/symlinked filepaths from appearing when opening a project file.

## 0.12.0 (03/29/2015)

Expand Down
8 changes: 4 additions & 4 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ The cache is created both in memory and on the hard drive."
(defun projectile-cache-current-file ()
"Add the currently visited file to the cache."
(interactive)
(let* ((current-project (projectile-project-root))
(abs-current-file (buffer-file-name (current-buffer)))
(current-file (file-relative-name abs-current-file current-project)))
(let ((current-project (projectile-project-root)))
(when (gethash (projectile-project-root) projectile-projects-cache)
(let* ((abs-current-file (file-truename (buffer-file-name (current-buffer))))
(current-file (file-relative-name abs-current-file current-project)))
(unless (or (projectile-file-cached-p current-file current-project)
(projectile-ignored-directory-p (file-name-directory abs-current-file))
(projectile-ignored-file-p abs-current-file))
Expand All @@ -566,7 +566,7 @@ The cache is created both in memory and on the hard drive."
(projectile-serialize-cache)
(message "File %s added to project %s cache."
(propertize current-file 'face 'font-lock-keyword-face)
(propertize current-project 'face 'font-lock-keyword-face))))))
(propertize current-project 'face 'font-lock-keyword-face)))))))

;; cache opened files automatically to reduce the need for cache invalidation
(defun projectile-cache-files-find-file-hook ()
Expand Down

3 comments on commit 924d731

@kaushalmodi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier behavior was a feature for me and this change is a bug.

The revision control system we use saved all file revisions in a central cache and a user, if not intending to modify a file, simply accesses a symbolic link to that file in cache.

In that case, the truename is horrendous: ../../../sos_cache/prj_name/prj_name_sos_cache/prj_name/FILES/dir1#dir1_1#dir1_1_1#file_name_v_1.23_456789

I would like to have a defvar to switch to the earlier behavior.

@bbatsov
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to open a ticket/PR. I'm guessing for most people this commit was a bugfix. :-)

@colonelpanic8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. @kaushalmodi sorry about that. This is only tangentially related, but I think we should also think about maybe allowing symlinks that ARE in the repository be accessed in this way? Thoughts?

Please sign in to comment.