Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: landyvlad on March 19, 2019, 10:37:29 PM

Title: Keeping track of code changes - best method?
Post by: landyvlad on March 19, 2019, 10:37:29 PM
Can anyone suggest an efficient way of keeping track of changes done to smf files?

I'm thinking of just keeping track of what has been edited and why.
Title: Re: Keeping track of code changes - best method?
Post by: skb on March 19, 2019, 10:46:07 PM
I use a (admin only) thread in which I record all the changes. New post for each change. I change the subject line every time to a more relevant / understandable / searchable one.
Title: Re: Keeping track of code changes - best method?
Post by: shawnb61 on March 19, 2019, 11:23:23 PM
I've started my own local git repository. 

I hope to recreate all customizations/tweaks to little mods.  I want to get to the point where I can rebuild the forum completely via package manager. 
Title: Re: Keeping track of code changes - best method?
Post by: GL700Wing on March 20, 2019, 03:29:30 AM
I always do the following:
1.  Insert a comment explaining what I've done and why and add my initials to the end of the line (I can then search a file for my initials);
2.  If the change came about as a result of something I read on this forum (or, very occasionally, somewhere else) I include the URL of the source of the information; and
3.  Keep a copy of the original line/lines of code as comments (very important for installing/uninstalling/reinstalling mods later on);

Here's an example from ./Sources/Load.php on one of my forums.
Quote// Fix for bug in Display Additional Membergroups on Profile mod. KL
        // See https://www.simplemachines.org/community/index.php?topic=141200.msg3031487#msg3031487
        //'list_additional_groups' => $profile['list_additional_groups'],
        'list_additional_groups' => !empty($profile['list_additional_groups']) ? $profile['list_additional_groups'] : '',
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 20, 2019, 03:36:47 AM
Git repository with build tools to automate syncing from local to server. (But I have multiple sites, multiple platforms and this lets me manage patching too, mostly.)
Title: Re: Keeping track of code changes - best method?
Post by: landyvlad on March 20, 2019, 07:03:22 AM
Thanks all

GL700wing yep i agree with your method and that's great for individual code but I'd like to keep some master list so I easily know what files I've made manual edits to; as well.


Arantor & shawn Git repositories are well beyond me :)

skb yes but if the forum is down, so is that thread !



Title: Re: Keeping track of code changes - best method?
Post by: GL700Wing on March 20, 2019, 07:41:31 AM
Quote from: landyvlad on March 20, 2019, 07:03:22 AM
GL700wing yep i agree with your method and that's great for individual code but I'd like to keep some master list so I easily know what files I've made manual edits to; as well.
Easy enough to do with a UNIX/Linux command ...

Quotecd ~/www/forum ; find . \( -name \*php -o -name \*css \) -type f -exec grep -l KL {} \; | sort -f
./proxy.php
./Sources/Load.php
./Sources/LogInOut.php
./Sources/ManageMembers.php
./Sources/ManageSettings.php
./Sources/Memberlist.php
./Sources/PersonalMessage.php
./Sources/Post.php
./Sources/Profile-Modify.php
./Sources/Profile.php
./Sources/Subs-Graphics.php
./Sources/Subs-Post.php
./Sources/Subs.php
./Themes/default/Admin.template.php
./Themes/default/css/admin.css
./Themes/default/css/index.css
./Themes/default/Display.template.php
./Themes/default/GenericControls.template.php
./Themes/default/index.template.php
./Themes/default/languages/Admin.english-utf8.php
./Themes/default/languages/Admin.english.php
./Themes/default/languages/ManageSettings.english.php
./Themes/default/Login.template.php
./Themes/default/ManageMembers.template.php
./Themes/default/PersonalMessage.template.php
./Themes/default/Profile.template.php
Title: Re: Keeping track of code changes - best method?
Post by: landyvlad on March 20, 2019, 09:30:58 PM
I have no idea how that works or what it does....
Title: Re: Keeping track of code changes - best method?
Post by: GL700Wing on March 21, 2019, 04:59:06 AM
Quote from: landyvlad on March 20, 2019, 09:30:58 PM
I have no idea how that works or what it does....
That's OK - here's a PHP file that does the same thing.

1. Edit the file and change the value of $my_id to whatever string you use to identify your edits (eg, MKR).
2. Use the cPanel file manager to copy the file to the root/home directory/folder (ie, the same location where SSI.php and Settings.php reside) of each forum where you modify files.
3. To list the files where you've recorded details of edits open the MyFiles.php (eg, www.mywebsite.org/forum/MyFiles.php) and wait for it to display the results.




Here's the code ...

Quote<?php
$my_id = "KL";
$this_dir = getcwd();
$command = "find . \( -name \*php -o -name \*css \) -type f -exec grep -liz $my_id\[\[:space:\]\] {} \; | sort -f";
$output = shell_exec($command);
echo "List of all .php and .css files containing string \"$my_id\" in $this_dir";
echo nl2br("\n\n$output\n");
echo "Finished listing .php and .css files containing string \"$my_id\" in $this_dir";
?>
Title: Re: Keeping track of code changes - best method?
Post by: Biology Forums on March 21, 2019, 08:08:18 AM
Quote from: Arantor on March 20, 2019, 03:36:47 AM
Git repository with build tools to automate syncing from local to server. (But I have multiple sites, multiple platforms and this lets me manage patching too, mostly.)

I feel that's too risky, b/c what if Github gets hacked or they change a setting (like Facebook as done in the past), where all your private information becomes public. I like the idea, but it's scary
Title: Re: Keeping track of code changes - best method?
Post by: Illori on March 21, 2019, 08:10:46 AM
you can have a git repo without GitHub being involved.
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 21, 2019, 08:41:22 AM
Indeed, I use my VPS for that. Others use Bitbucket, others use GitLab, Gerrit, or even just Git itself can be used that way with care.

I doubt Github will hit that problem, it's not in Microsoft's interest to let that happen.
Title: Re: Keeping track of code changes - best method?
Post by: Gwenwyfar on March 21, 2019, 09:46:54 AM
You could also have only a local repository. So it's essentially no different than having the files stored in your computer.

This is what I do, personally.
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 21, 2019, 09:57:51 AM
I just have the master repository in my server so build tools can work with it and deploy things.
Title: Re: Keeping track of code changes - best method?
Post by: Gwenwyfar on March 21, 2019, 10:04:26 AM
Yeah, that sounds better. My setup isn't that elaborate. I still miss FireFTP auto-uploading things for me though.
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 21, 2019, 10:07:56 AM
Yeah but I host a bunch of stuff.
Title: Re: Keeping track of code changes - best method?
Post by: GL700Wing on March 21, 2019, 06:03:57 PM
Quote from: Gwenwyfar on March 21, 2019, 10:04:26 AM
Yeah, that sounds better. My setup isn't that elaborate. I still miss FireFTP auto-uploading things for me though.
I'm still using FireFTP - I use a portable version of Firefox ESR (https://portableapps.com/news/2018-07-10--firefox-portable-legacy-52.9.0-released) and installed FireFTP as an unsigned add-on (https://support.mozilla.org/en-US/kb/add-on-signing-in-firefox?as=u&utm_source=inproduct#w_what-are-my-options-if-i-want-to-use-an-unsigned-add-on-advanced-users).

Alternatively, you could use Waterfox (https://www.waterfoxproject.org/en-US/) - FireFTP installs without the need to enable unsigned add-ons.
Title: Re: Keeping track of code changes - best method?
Post by: landyvlad on March 27, 2019, 03:29:23 AM
GL700 wing - thank you that's awesome !


Quote from: Gwenwyfar on March 21, 2019, 09:46:54 AM
You could also have only a local repository.

With a 1 Mbps (yep one megabit per second) download and 0.22 Mbps upload speed, no that doesn't work for me ROFL
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 27, 2019, 03:56:33 AM
Um, why not? A local repository sits on your computer...
Title: Re: Keeping track of code changes - best method?
Post by: live627 on March 27, 2019, 04:10:14 AM
Quote from: landyvlad on March 27, 2019, 03:29:23 AM
Quote from: Gwenwyfar on March 21, 2019, 09:46:54 AM
You could also have only a local repository.

With a 1 Mbps (yep one megabit per second) download and 0.22 Mbps upload speed, no that doesn't work for me ROFL
no internet required
Title: Re: Keeping track of code changes - best method?
Post by: Looking on March 27, 2019, 05:34:00 AM
I do the same as GL700Wing and also keep dated backups before major changes.
Title: Re: Keeping track of code changes - best method?
Post by: GL700Wing on March 27, 2019, 06:05:27 AM
Quote from: Looking on March 27, 2019, 05:34:00 AM
... also keep dated backups before major changes.
Ditto - plus I have a test forum with all the same Sources/Themes files where I stage and test *all* changes before making them on the production forum. 
Title: Re: Keeping track of code changes - best method?
Post by: Gwenwyfar on March 27, 2019, 08:04:55 AM
Quote from: Arantor on March 27, 2019, 03:56:33 AM
Um, why not? A local repository sits on your computer...
And unless you're messing with attachments or avatars, most files are under a hundred kb, when you upload them to the forum server... Not that it even makes any difference compared to downloading backups or uploading packages to the forum... Even a full zip with all files doesn't go over some 5mb.

(Ps: My Internet has roughly the same rates...)
Title: Re: Keeping track of code changes - best method?
Post by: landyvlad on March 28, 2019, 10:58:39 PM
OK maybe I misunderstood local repository to mean FULL back up.

Does it just mean ' a copy of files I've changed ' ?
Title: Re: Keeping track of code changes - best method?
Post by: Aleksi "Lex" Kilpinen on March 29, 2019, 12:44:44 AM
You would probably want a full mirror of your files, but that wouldn't be much to download once.
Title: Re: Keeping track of code changes - best method?
Post by: Arantor on March 29, 2019, 03:40:10 AM
Quote from: landyvlad on March 28, 2019, 10:58:39 PM
OK maybe I misunderstood local repository to mean FULL back up.

Does it just mean ' a copy of files I've changed ' ?

No, it means a system designed to track every change made and let you leave yourself notes as to what changed and why.
Title: Re: Keeping track of code changes - best method?
Post by: landyvlad on March 29, 2019, 11:14:00 AM
and that's what Im getting at - how best to structure such a system ?
Title: Re: Keeping track of code changes - best method?
Post by: Gwenwyfar on March 29, 2019, 11:16:15 AM
A local repository is the same as a github repository (or whichever other git repositories out there), except it is only in your computer, and not on the internet.
Title: Re: Keeping track of code changes - best method?
Post by: shawnb61 on March 29, 2019, 11:20:30 AM
A 'repository' is all of the above.  A source code control system.  Repositories have a copy of the code as well as methods to regulate & track all of the changes.  More traditional source code control systems  (old school...) would have a 'checkout' function, like a library, to make sure folks' changes didn't conflict with each other; only one person was allowed to udpate a file at a time.  More modern source code controls systems (like Git) work at the 'commit' level - specific lines of code changed, "diffs" - which enable different folks to work on the same file concurrently (but have an added layer of complexity as a result for resolving the conflicts that will happen). 

Git is one of the more popular repositories in use today.  Using SMF 2.1 as an example, you have:
- a copy of all the current source code: 
         https://github.com/SimpleMachines/SMF2.1/tree/release-2.1/Sources
- a log of changes made: 
         https://github.com/SimpleMachines/SMF2.1/commits/release-2.1
- with each detailed "commit" having specific changes made with notes as to why: 
         https://github.com/SimpleMachines/SMF2.1/pull/5545/files

Note that with Git, you do not have to use Github.com at all if you don't want to - you can have a local copy on your PC.  OR, you can have a private copy up on Github. 

Git is kinda complex, but extremely powerful.  Worth learning & using, IMO. 
Title: Re: Keeping track of code changes - best method?
Post by: vondes on December 09, 2019, 01:59:38 AM
Thanks all

GL700wing yep i agree with your method and that's great for individual code but I'd like to keep some master list so I easily know what files I've made manual edits to; as well.


Arantor & shawn Git repositories are well beyond me :)

skb yes but if the forum is down, so is that thread !
Title: Re: Keeping track of code changes - best method?
Post by: m4z on December 09, 2019, 03:21:35 AM
Quote from: vondes on December 09, 2019, 01:59:38 AM
Arantor & shawn Git repositories are well beyond me :)

If you're willing, you can change that (https://git-scm.com/book/en/v2).