-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Introduce and use more robust worktree-list wrappers #4926
Conversation
We still support even older versions, so please restore that. |
Why use a hashtable? When there are as few elements as here, then that is slower than an alist, and it makes the code harder to read. |
Do you happen have a reference for this? I'm having trouble finding actual benchmarks – just various vague remarks. It makes intuitive sense that hashmaps would have some constant overhead that could be worse than linear lookup here, but I'm very curious to the actual characteristics here. At any rate, what's hard to read about the hashmap implementation? Is it the string-valued keys or something else? I'm trying to determine if I should keep the keys as strings or intern them into symbols. I don't see a meaningful distinction between the options, so I'm not sure what direction you want this to go: (gethash "worktree" wt) (puthash "worktree" val wt)
(cdr (assoc "worktree" wt)) (setcdr (assoc "worktree" wt) val)
(cdr (assq 'worktree wt)) (setcdr (assq 'worktree wt) val)
(alist-get 'worktree wt) (setf (alist-get 'worktree wt) val)
(plist-get 'worktree wt) (plist-put 'worktree wt val) If we're going alist, I would expect either the second or forth, yeah? |
The function for this purpose, `magit-list-worktrees', is limited to providing a fairly sparse set of information about each worktree: the worktree path, its current HEAD and checked-out branch, and whether or not it's bare. This isn't sufficient for other tooling (or future Magit functionality) that wants to use other properties of the worktree (e.g., whether or not it's prunable). Introduce `magit-list-worktrees-raw' to generically capture every property reported by Git as a string-valued hashmap. The post-processing that had been present in `magit-list-worktrees' is moved to `magit-list-worktrees-fix-worktree' so that it can be mapped over `magit-list-worktrees-raw'. `magit-list-worktrees' is re-implemented in terms of these two functions to keep the existing interface for legacy code. Care is taken in the implementation of `magit-list-worktrees-raw' to avoid unnecessary string allocations by using `string-match-p' and `substring' instead of `string-split'.
a18a6d5
to
34d4407
Compare
Kludge restored 😃 |
I've adopted the |
bdf187f
to
867ad44
Compare
Funny enough I looked at this function a few days ago (because the byte-compiler complained about some dead code) and wondered whether to extend it. I decided to not do that until there is a need for it. ;P While your implementation may be more future-proof, I don't think it is more robust. Using What do you think about the extended implementation in the |
I've been working on Windows more lately (sobs) and we've seen Git tooling choke on filepaths with special characters, so the use of The direction you take with With your advice-centered approach, I would recommend feeding in the worktree list/alist/map object itself in |
I've added
I've added a comment to ping you before making a breaking change. Also, since 30-50 colleagues use Magit, could you maybe ask your employer to give me some money?
Makes sense. What do you think of the new signature? |
It's certainly in the plan for me to ask if I do get the adoption I'm expecting :-) but as it stands, I know of only three people (including myself) who use it – with a fourth 'on the way' as it were. Keep in mind though that even if 30-50 devs adopt Magit, we're still only talking ~1% of our ~3k developers – even with the customized tooling I'm building into workflows (via transients and status-/revision-buffers). I'm going to push for it, but it'll be a tough sell. Emacs is still perceived as too obscure – and performance on Windows is just not there yet. (I'm personally putting as much time as I can spare into libgit2/libgit2#6202, which should at least help a little bit with libegit integration.) Given my increased usage of it the past couple months during our migration (and that I'm using it for at $DAYJOB), I was able to start sponsoring personally at least! I'll also make a point to talk to my current teammates using Magit to consider sponsoring. So my priorities right now with making it as easy as possible for our devs to use Magit are:
One of the advantages I have in my current role is an explicit focus on developer tooling and productivity (in a 'you are paid to work on this' sense), so I'm hoping to work on these things at $DAYJOB as priorities permit. I think your new signature is good. I like the improvement of passing the propertized and padded label – that certainly makes implementing replacement functions simpler (not having to worry about I don't understand the advantage of keeping everything in a flat list that requires referencing documentation to use when more structured options are available that are more self-documenting. |
Thanks!
I agree that using an alist would result in a better interface. The advantage of not doing that, is that it is less work for me. I don't have to think about how to restructure the code, and I don't have to make any design decisions regarding the interface. E.g., should it return Since this function, like all helper functions (even if not explicitly marked as private) are primarily intended for internal purposes, I choose to optimize for that. Sometimes it makes sense to spend time getting an interface just right, but Magit is large and has few maintainers, so I do have to cut corners sometimes. For Magit's own purposes this function doesn't have to be changed at all. What I am doing now seems like a good compromise; you get the extra data you need and I don't have to invest too much time making changes, that don't actually, at this time, benefit Magit itself. So this is a bit inconvenient for you, but this is probably something you can just deal with once and then mostly forget about. |
The function for this purpose,
magit-list-worktrees
, is limited to providing a fairly sparse set of information about each worktree: the worktree path, its current HEAD and checked-out branch, and whether or not it's bare. This isn't sufficient for other tooling (or future Magit functionality) that wants to use other properties of the worktree (e.g., whether or not it's prunable).Introduce
magit-list-worktrees-raw
to generically capture every property reported by Git as a string-valued hashmap. The post-processing that had been present inmagit-list-worktrees
is moved tomagit-list-worktrees-fix-worktree
so that it can be mapped overmagit-list-worktrees-raw
.magit-list-worktrees
is re-implemented in terms of these two functions to keep the existing interface for legacy code.Care is taken in the implementation of
magit-list-worktrees-raw
to avoid unnecessary string allocations by usingstring-match-p
andsubstring
instead ofstring-split
.I'm not sure of a better name for
magit-list-worktrees-raw
than what I chose, but it certainly seems lacking. Of course use whatever name you see fit. Perhaps there are similar functions in the codebase that you're aware which can be modeled after here.