Open pa-0 opened 4 weeks ago
I've considered a Gist integration before, but never got round to implementing it.
How would you see Git/GitHub integration working from a user's perspective? For example:
I've no experience of doing Git integration but am happy to investigate. Any relevant resources you can point me at would be helpful.
On a related point I have considered building some kind of limited version control within CodeSnip - something like Delphi offers where changes are tracked and can be diffed and / or reverted. Just wondering how useful that might be.
I'd defer to your vision, of course, since this is your baby. 😄 I could see an SCM integration (especially one that integrates with GitHub / some other remote host) potentially useful for multiple usecase, including a possible means to:
I'm a beginner in Pascal by the way, but pretty interested in and serious about learning it. I'm actually surprised that it's not more popular, especially in Windows since it compiles to native, lightweight and super fast binaries, not to mention that it's (from what I've read) an ideal language for new coders, originally created as a way to teach Programming.
The point in this explanation is that I'd much prefer to contribute these features myself rather than simply suggest/request them, and I would were I able to. I love your application, so once I am able to, I look forward to contributing to it.
Great thanks.
I think I've got the gist (pun fully intended) of what you're looking for.
I'll go off and research the GitHub API to see what may be possible and come back if and when I can work out what needs to be done.
Once you're feeling up to speed in Pascal I'd really welcome contributions. The main downside is that I'm stuck using Delphi XE for CodeSnip (reasons here) and not a lot of people still use it.
I'm glad you like CodeSnip. I've been developing it on and off since 2005. That does bring some problems though in that the code has become a bit of a mess over the years. It really needs a rewrite, but I've tried and failed to do that numerous times. Being a single-handed hobbyist coder with other interests means I don't spend a lot of time on it these days.
After some poking around the net I've discovered a couple of projects that ease the access to the Git API. However many people suggest that it's easier, and more portable, to call git from the command line to perform desired actions. CodeSnip already has the facility to run external programs (currently the Delphi / FPC compiler) so calling git should be relatively easy (famous last words)
@pa-0
You got me hooked! I've been doing a lot of thinking and poking around in long forgotten corners of the CodeSnip source code.
The TL;DR version is in the summary at the end of this comment. How much sense it makes without the following I don't know!
Here are a few initial thoughts on your suggestions:
- source control and backup ones snippets database at the same time, also allowing the user to easily share that database of code across multiple machines
If this is restricted to the current CodeSnip user database (i.e. your own snippets) then I think this is doable.
With a few tweaks the user database could be converted to a Git repo. That would enable Git to be used to commit / restore changes etc and to push and pull to a remote repo.
However, this would require the repo content to conform to the CodeSnip user database format, which essentially is an XML file containing meta data and a .dat
for each snippet, containing the source code. Those file names are simply numbers, so aren't exactly informative, although it might be relatively easy to change that.
It strikes me that implementing Git inside CodeSnip could be done incrementally over different releases because whatever Git functionality isn't in CodeSnip can easily be achieved using Git from the command line.
- add new code snippets found online by way of external repositories / gists
Quite a bit harder!!
The difficulty is nothing to do with adding Git support but is concerned with how CodeSnip stores snippets. It requires meta data: every snippet MUST have a unique ID, a display name and a description. A lot of code breaks if that requirement is dropped, so its non-negotiable.
Let's split external repos from Gists because they're different.
There's no way we can expect that other repos will conform to CodeSnip's requirements. Yep, we can get Git to pull them. But there's no current way of importing them into CodeSnip unless we can fudge the creation of the required ID and description. I can see ways round this though.
However, there's a bigger problem. CodeSnip only knows about two data sources: the "main" database that can be downloaded from the DelphiDabbler Code Snippets Collection and the "user" database, which contains your own snippets.
CodeSnip can currently export and import snippets from other CodeSnip users and the SWAG archive, but such imports are "lost" in the user database. The database doesn't track the source of the imported code, so it's just like it was typed in.
For external snippet sources to work properly with CodeSnip so that changes can be pulled and pushed, the architecture of how CodeSnip reads / writes user data needs to change. I've thought of an approach which may work. It is to get CodeSnip to read and write multiple data sources and to track which source each snippet comes from. Updates can then be read/written to the relevant source.
Such an approach would work whether or not the user wished to use Git. But its a precondition for your proposal.
And, although it's harder than applying Git to the user database, I'm quite motivated to implement it.
(By coincidence such a change would enable me to solve a further problem that's been bugging me for years, which is the need to keep the "main" database read-only to ensure synchronisation with the Code Snippets Collection).
Again this is one I've considered doing before, but never have!
I've not given quite so much though to this, but first thoughts are:
Maintaining a link with a specific Github user's gists in a way that make the Gists updatable will require the same architectural changes to CodeSnip's data sources as above
A single user's public gists are easy to read via the GitHub API because no authentication is required.
Pushing changes to ones own Gists does require authentication so is more difficult to implement, and there are potential security issues storing authentication details.
- integrate one's codesnips collection in other applications where the current database file couldn't easily be loaded. For example, I have a pretty naive text expander program I use built in AutoHotkey that reads in code snippets from simple text-encoded files. With a git integration, I could point Codesnips and the Autohotkey program to the same directory and access the same up-to-date code in both applications without having to manually transfer/update new snippets created/saved in Codesnips.
I think we'd get this for free if the above problems get solved!
It's been hard to explain all this, but I hope it makes some kind of sense. I'd love to get your feedback. I'm trying to get a sense of where to start 1st: update the data sources or add Git to the user databases.
Would you ever consider integrating git SCM (or a GitHub integration)?