Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Keep annoations seperate from branch to branch #68

Closed
gopar opened this issue May 28, 2020 · 13 comments
Closed

Feature Request: Keep annoations seperate from branch to branch #68

gopar opened this issue May 28, 2020 · 13 comments

Comments

@gopar
Copy link

gopar commented May 28, 2020

Hey!
Thanks for the awesome package :)

Would it be possible to keep annotations from one git branch separate from another branch?

@cage2
Copy link
Collaborator

cage2 commented May 29, 2020 via email

@cage2
Copy link
Collaborator

cage2 commented Jun 10, 2020

Hi @gopar!

We just merged some modification to the code that allow to change database annotation during your Emacs session. Even this does not exactly address your request i believe could be a good starting point for other people to implement a mechanism to load different annotations depending from the git branch you are using. In my opinion, this package should not deal with VCS at all because i think expanding the program in this direction will conflict whit the main goal of the package.

But at least there is a starting point! :)

Feel free to comment on that modification if you please and, again thank you, for your request.

Bye!
C.

@cage2
Copy link
Collaborator

cage2 commented Jul 16, 2020

Hi @gopar!

I hacked something that i hope could address your request someway.

The code is here: https://www.autistici.org/interzona/emacs.html#org8d01ff4

The code you will find following the link above is very far from clean but i think could be someway useful to you.

Of course for this snippets to works annotate.el should be loaded before.

Bye!
C.

Edit: removed repeated word

@gopar
Copy link
Author

gopar commented Nov 11, 2020

Hey @cage2 !

I finally got some time to work on this. Have a question on why the following snippet doesn't work?
Originally thought that setting the annotate-file to buffer local and pointing to where I want would solve the problem, but it seems that it doesn't want to read the file? I don't know too much about the internals of annotate to figure out the issue. Hoping you can give some pointers.

(defun gopar-annotate-setup ()
  "Setup annotate to read from branch specific db.
Useful for keeping annotations seperate from git branch to branch."
  ;; I'm pretty sure magit/projectile will be loaded at this point
  (when (magit-get-current-branch)
    (let ((branch (magit-get-current-branch))
          (default-directory (projectile-project-root)))
      (setq-local annotate-file (expand-file-name (concat ".annotate/" branch)))
      ;; If file doesn't exist create it
      (unless (file-exists-p annotate-file)
        (make-directory (file-name-directory annotate-file) t)
        (with-temp-file annotate-file))
      (annotate-mode)
      ;; Looks like even forcing it doesn't work???
      (annotate-switch-db t annotate-file))))

@cage2
Copy link
Collaborator

cage2 commented Nov 11, 2020 via email

@gopar
Copy link
Author

gopar commented Nov 12, 2020

Hey @cage2

I seem to have figured out the issue.
Since I'm making annotate-file a buffer variable (via setq-local), that means that this new subtle issue arises in annotate-load-annotation-data func.

(defun annotate-load-annotation-data (&optional ignore-errors)
  "Read and return saved annotations."
  (cl-flet ((%load-annotation-data ()
              (with-temp-buffer  ...))))) ;; <- problem

When (with-temp-buffer ...) is called, it's creating its own buffer with new local variables which will have the original default value. The workaround is to wrap it in a let expression like so:

(defun annotate-load-annotation-data (&optional ignore-errors)
  "Read and return saved annotations."
  (let ((outer-file annotate-file)) ;; track current buffer var
       (cl-flet ((%load-annotation-data ()
              (with-temp-buffer  
                   (setf annotate-file outer-file) ;; update to match what we want
                    ....))))))

I suspect there will be other instances like this throughout the codebase since its not expected to be used as a buffer local var.

It be nice if annotate.el did support it though 😉

@cage2
Copy link
Collaborator

cage2 commented Nov 12, 2020 via email

@gopar
Copy link
Author

gopar commented Nov 16, 2020

So far the branch has been working, with the exception of annotate-switch-db. It has the same problem as previously stated in its (with-current-buffer ...) expression. I suspect that there will be more instances of this happening but haven't ran into them (probably b/c my current testing very minimal manual checking).

If you could update that part accordingly that would be great :)

Another comment I have (not related to this issue) is if there was a way to turn of the warnings of when the a file has changed? Looks like adding a bool for handling that part would be enough :)
I can open up a diff ticket for this since it's off topic.

Thanks!

@cage2
Copy link
Collaborator

cage2 commented Nov 16, 2020 via email

@gopar
Copy link
Author

gopar commented Nov 20, 2020

Hmm looks like I was doing something wrong last time. I am no longer receiving the error i was getting before \o/
Looks like all is good :)

@cage2
Copy link
Collaborator

cage2 commented Nov 20, 2020 via email

@gopar
Copy link
Author

gopar commented Nov 20, 2020

Yeah gopar is fine :)
Thanks! \o/

@cage2
Copy link
Collaborator

cage2 commented Nov 20, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants