LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   [Request] Slackpkg custom merge tool. (https://www.linuxquestions.org/questions/slackware-14/%5Brequest%5D-slackpkg-custom-merge-tool-4175478346/)

NoStressHQ 09-24-2013 09:53 AM

[Request] Slackpkg custom merge tool.
 
Hi,

I checked slackpkg sources, and found that it was using sdiff to merge configurations files.

I'd like to use another merge tool (emacs to be precise :) ).

Would it be possible to make the merge tool customizable ?

It would be great to be able to change the sdiff default using an environment variable.

If any help needed, I'd be glad to participate (at least for testing ;) ).

Thanks !

Bests,

Garry.

Edit: It could be in slackpkg.conf too, but an external environment variable could make this more "versatile".

willysr 09-24-2013 10:15 AM

so that means all users wanting to use slackpkg should install emacs?
i don't think most users will agree on this one :)

i personally don't install emacs and i think sdiff works for me

NoStressHQ 09-24-2013 10:18 AM

Quote:

Originally Posted by willysr (Post 5033891)
so that means all users wanting to use slackpkg should install emacs?
i don't think most users will agree on this one :)

i personally don't install emacs and i think sdiff works for me

That's not at all what I wrote...

I asked to be able to choose which merge tool you want to use. With an environment variable. I mentioned emacs just because it's the one I want to use in my particular situation...

willysr 09-24-2013 10:22 AM

i guess the main important is what's the advantage of using emacs compared to sdiff?

NoStressHQ 09-24-2013 10:27 AM

Quote:

Originally Posted by willysr (Post 5033898)
i guess the main important is what's the advantage of using emacs compared to sdiff?

... Is it a joke ? Do I tell you how you need to work ?

TobiSGD 09-24-2013 10:32 AM

Quote:

Originally Posted by NoStressHQ (Post 5033901)
... Is it a joke ? Do I tell you how you need to work ?

willysr indeed has a point there. Having multiple options for that means that someone has to implement and test that every time changes are made to slackpkg, with all possible options. If there isn't an obvious advantage of using Emacs or anything else to do the job I don't see why the developer should add this.

But I am really curious about that, what exactly do you want to achieve with the switch to Emacs?

willysr 09-24-2013 10:36 AM

no, it's not a joke
i know emacs is a great application and some might like it and prefer it compared to vi or nano, but i don't see anything different with the results of diff by changing to emacs (please, CMIIW)

NoStressHQ 09-24-2013 10:41 AM

Quote:

Originally Posted by TobiSGD (Post 5033907)
willysr indeed has a point there. Having multiple options for that means that someone has to implement and test that every time changes are made to slackpkg, with all possible options. If there isn't an obvious advantage of using Emacs or anything else to do the job I don't see why the developer should add this.

But I am really curious about that, what exactly do you want to achieve with the switch to Emacs?

Alright, that's a better approach to the question. At least I cant understand your point about maintainability.

It's before all a matter of being more productive to be able to use the tool you're used to use in your daily tasks. That's seems obvious to me.

Beside I don't ask for emacs (I thought my OP was clear about that)...

I ask to be able to have an environment variable to be able to customize.

Default would be ie:

Code:

SLACKPKG_MERGE_TOOL=sdiff -s -o
And people would be able to do something else
Code:

SLACKPKG_MERGE_TOOL=mymergetool-of-my-choice --with --my --args
That's it. I might be wrong but those modifying (customizing) this variable should be aware enough to understand how it works and being responsible to maintain their own customization.

I use emacs, but many others use vim so I'm not doing some "emacs evangelization" and don't want to enter in this mode...

I was just talking about giving slackpkg some more flexibility.

And I'm open to any point which could be about "not in the plan" or "difficult to maintain" although I really don't see (I might be wrong) any difficult problem here.

In practice it could even be a wrapper script that shuffle arguments if the wanted merge tool is too exotic.

Thanks

Garry.

NoStressHQ 09-24-2013 10:45 AM

Quote:

Originally Posted by willysr (Post 5033909)
no, it's not a joke
i know emacs is a great application and some might like it and prefer it compared to vi or nano, but i don't see anything different with the results of diff by changing to emacs (please, CMIIW)

Ok sorry I took it badly, it's just it was not at all the point of my post.

And I don't see the need to argue "which one is better" because ultimately, it's a matter of choice, is it personal or professional/corporate... Anyway.

I'm not saying sdiff is rubbish, sdiff is good when you don't have anything else accessible.

I'd just rather use emacs for that, it's a choice as any choice.

Edit: obviously, I hope there's no difference in the 'result of diff' haha... It's on the way you do the merge, which color you want etc. Usability in short, productivity for a longer word.

Edit2: also it's less error prone to use something you're used to use... And config files merges can sometimes be "sensible".

Edit3: sorry, I can understand the problem now, I'm talking about having 'interactive merge tool'. And now I see that it might introduce more changes in slackpkg behavior. But I guess it's not something impossible. So that was maybe the source of misunderstanding. But sdiff is interactive too so at the end, it seems to me that the point is the same.

allend 09-24-2013 05:34 PM

Slackpkg is designed to be easy to customise. I actually implement a custom merge using vimdiff. I find it useful for updating large config files with custom entries e.g. for cups and ssh. Adapting this for emacs should not be difficult.
I edit /usr/libexec/slackpkg/functions.d/postfunctions.sh
Code:

--- post-functions.sh.orig        2013-02-21 21:07:05.408637573 +1100
+++ post-functions.sh        2013-02-21 22:08:22.885260049 +1100
@@ -10,6 +10,18 @@
        fi
 }
 
+runvimdiff() {
+        BASENAME=$(basename $i .new)
+        FILEPATH=$(dirname $i)
+        FULLNAME="${FILEPATH}/${BASENAME}"
+
+        if [ -e ${FULLNAME} ]; then
+            vimdiff ${FULLNAME} ${FULLNAME}.new
+        else
+            echo "file $FULLNAME doesn't exist"
+        fi
+}
+
 showmenu() {
        echo -e "$1 - \c"
        tput sc
@@ -166,7 +178,7 @@
                                        GOEX=0
                                        while [ $GOEX -eq 0 ]; do
                                                echo
-                                                showmenu $i "(K)eep" "(O)verwrite" "(R)emove" "(D)iff" "(M)erge"
+                                                showmenu $i "(K)eep" "(O)verwrite" "(R)emove" "(D)iff" "(M)erge" "(V)imdiff [dp put, do obtain, ^W^W switch]"
                                                read ANSWER
                                                case $ANSWER in
                                                        O|o)
@@ -183,6 +195,9 @@
                                                        M|m)
                                                                mergenew $1
                                                        ;;
+                                                        V|v)
+                                                                runvimdiff $1
+                                                        ;;
                                                        K|k|*)
                                                                GOEX=1
                                                        ;;


NoStressHQ 09-24-2013 06:02 PM

Quote:

Originally Posted by allend (Post 5034101)
Slackpkg is designed to be easy to customise. I actually implement a custom merge using vimdiff. I find it useful for updating large config files with custom entries e.g. for cups and ssh. Adapting this for emacs should not be difficult.
I edit /usr/libexec/slackpkg/functions.d/postfunctions.sh

Yes, that's what I meant ! :)

I know this file, it's just I'd rather not modify/patch it, and I myself don't want to use emacs all the time. That's why I was talking about an environment variable... In the function mergenew(),

instead of:

Code:

sdiff -s -o "${FULLNAME}.smerge" "${FULLNAME}" "${FULLNAME}.new"
it could be:

Code:

$SLACKPKG_MERGE_TOOL "${FULLNAME}.smerge" "${FULLNAME}" "${FULLNAME}.new"
While in slackpkg.conf we could have (bash syntax, dunno for "pure" /bin/sh):

Code:

SLACKPKG_MERGE_TOOL=${SLACKPKG_MERGE_TOOL:-sdiff -s -o}
Then slackpkg should work as usual, but if we want a another merge tool we could just set the SLACKPKG_MERGE_TOOL variable to the right command...

As simple as this. No one lose anything, does it ?

Cheers

Garry.

allend 09-24-2013 07:52 PM

I find that having another menu entry is more convenient than setting an environment variable.
Editing postfunctions.sh is only a problem when it gets overwritten by a package update.

NoStressHQ 09-24-2013 08:04 PM

Quote:

Originally Posted by allend (Post 5034163)
I find that having another menu entry is more convenient than setting an environment variable.
Editing postfunctions.sh is only a problem when it gets overwritten by a package update.

Well here are my points:
- consistency: it's like the common $EDITOR env var used in many places.
- complexity: a menu requires more modification and imply to know which options you want to provide, and each must be tested upstream (this might become a PITA for developers)
- flexibility: a variable can be set to anything the user want, even a yet unknown tool or a wrapper script that provide an "unified" interface.

Plus you can set the variable in a script (or the .bashrc file) and it's not difficult.

On my point of view the variable is more "UNIX" in style and flavor, it's a very tiny modification and open to more choice.

BTW, it's my developer reflex and my preference, I don't know what slackpkg developers prefer, it's up to them.

allend 09-24-2013 08:09 PM

One argument for avoiding using emacs is that it requires X to be running. I prefer to do my upgrades from run level 3, so vimdiff is a viable choice for that.

NoStressHQ 09-24-2013 08:12 PM

Quote:

Originally Posted by allend (Post 5034173)
One argument for avoiding using emacs is that it requires X to be running. I prefer to do my upgrades from run level 3, so vimdiff is a viable choice for that.

Have you noticed "emacs-24.2-no-x11" ? As a matter of fact I got an alias as "emacs-console" for my headless server... :)

(Edit: And even in graphical environment I tend to use the console version of emacs...)


All times are GMT -5. The time now is 01:36 AM.