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

Legit closify remove global vcs #1538

Merged
merged 50 commits into from
Sep 24, 2024

Conversation

vindarel
Copy link
Collaborator

@vindarel vindarel commented Sep 22, 2024

Legit's code base is now a little OO and the VCS logic is split into their own files.

The goal that is now achieved without bugs is that we can have more than 1 interactive rebase in process, without re-inventing an OO with too many global variables and manual dispatch.

I tested the best I can, specialy the interactive rebase, for git and other VCSs (which must show a message, not fail).

replaces #1451

anlsh and others added 30 commits September 22, 2024 15:51
Yes, Emacs makes extensive use of dynamic bindings/scope: that's not a
reason we should do the same. Common Lisp supports lexical scoping,
unlike Elisp when it started out, and in my opinion we should really,
*really*, try to avoid dynamic binds where a function parameter would
do.

Yes, this adds the need to plumb an extra parameter around. That's well
worth the cost: we can always package/split function parameters as
needed and as they make sense, whereas dynamic bindings may prove to be
a *huge* pain point in the future if Lem starts making use of paralellism.

The Emacs documentation itself puts it succinctly [1]

> Lexical binding opens up many more opportunities for optimization,
> so programs using it are likely to run faster in future Emacs versions.
> Lexical binding is also more compatible with concurrency,

Now, focusing on Legit itself: much of the in lem/porcelain uses the
pattern

```
(defun some-legit-function (vcs)
  (case vcs
    (:git (git-fn))
    (:hg (hg-fn))
    (:t (fallthrough))))
```

There's no reason to have all of this dispatch logic done manually: this
is a textbook case for using generic functions. Now, the thing is that
generic functions need something to dispatch *on*. And it's pretty clear
that the VCS parameter (representing, really, the repository [2]) is the
perfect thing for that.

By switching all the `legit-function`s to be generic functions, the
implementation for each VCS can also define their `vcs` objects to
contain whatever data they might find useful: whether that's some sort
of legit-side cache for commits, FFI handles (will be useful for libgit2
support for instance), etc.

[1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html
[2] Might be worth a rename, but I don't want to clutter this particular
change.
It doesn't do anything: the one place it's actually called, we know that
we're in a git project already. The equivalent hg and fossil callsites
actually call the bespoke functions directly
The variable is unused, according to grep
The system is loaded by default now.
@vindarel
Copy link
Collaborator Author

the failed CI is


;; testing 'lem-tests/language-server/tests'
initialize
CORRUPTION WARNING in SBCL pid 4134 tid 4187:
Memory fault

@vindarel vindarel merged commit 87fbab3 into lem-project:main Sep 24, 2024
1 of 2 checks passed
@vindarel vindarel deleted the legit-closify-remove-global-vcs branch September 24, 2024 16:38
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

Successfully merging this pull request may close these issues.

2 participants