How To Use Trunk Version?

Development-related discussion, including bundled plugins
User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: How To Use Trunk Version?

Postby sleeper_service » 09 Jun 2013, 09:45

gbcox wrote:More like kaboom... patch wasn't intended for what you're trying to do.

you crack me up, you know? you really do.

Code: Select all

DESCRIPTION
       patch takes a patch file patchfile containing a difference listing pro‐
       duced by the diff program and applies those differences to one or  more
       original  files, producing patched versions.  Normally the patched ver‐
       sions are put in place of the originals.

patch was *precisely* intended for what I'm doing, and it works quite well for anybody that doesn't start out trying to break it.

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 09 Jun 2013, 09:48

I just ran it though the same test cases I prepared for my own code. Sorry that it didn't pass.

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: How To Use Trunk Version?

Postby sleeper_service » 09 Jun 2013, 10:47

gbcox wrote:I just ran it though the same test cases I prepared for my own code. Sorry that it didn't pass.

without knowing exactly what you *did*, I can't tell you what went wrong.

it's very easy to prove that my script works properly...
posit, you've got a working config.php (shortened version to save a bit of space)

Code: Select all

<?php

        define('DB_TYPE', "pgsql"); // or mysql
        define('DB_HOST', "myhost");
        define('DB_USER', "myuser");
        define('DB_NAME', "ttrss");
        define('DB_PASS', "mypass");
        define('DB_PORT', '5432'); // when neeeded, PG-only

        define('MYSQL_CHARSET', 'UTF8');
        // Connection charset for MySQL. If you have a legacy database and/or experience
        // garbage unicode characters with this option, try setting it to a blank string.

        define('FEED_CRYPT_KEY', 's9ehfrksu5gosqftbb8s2se35');
        // Key used for encryption of passwords for password-protected feeds
        // in the database. A string of 24 random characters. If left blank, encryption
       
        define('LOG_DESTINATION', 'syslog');
        // Log destination to use. Possible values: sql (uses internal logging
        // you can read in Preferences -> System), syslog - logs to system log.
        // Setting this to blank uses PHP logging (usually to http server
        // error.log).

        define('CONFIG_VERSION', 26);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).

        // vim:ft=php
?>

and the unaltered config.php-dist

Code: Select all

<?php
        // *******************************************
        // *** Database configuration (important!) ***
        // *******************************************

        define('DB_TYPE', "pgsql"); // or mysql
        define('DB_HOST', "localhost");
        define('DB_USER', "fox");
        define('DB_NAME', "fox");
        define('DB_PASS', "XXXXXX");
        define('DB_PORT', ''); // usually 5432 for PostgreSQL, 3306 for MySQL

        define('MYSQL_CHARSET', 'UTF8');
        // Connection charset for MySQL. If you have a legacy database and/or experience
        // garbage unicode characters with this option, try setting it to a blank string.

        define('FEED_CRYPT_KEY', '');
        // Key used for encryption of passwords for password-protected feeds
        // in the database. A string of 24 random characters. If left blank, encryption
       
        define('LOG_DESTINATION', 'sql');
        // Log destination to use. Possible values: sql (uses internal logging
        // you can read in Preferences -> System), syslog - logs to system log.
        // Setting this to blank uses PHP logging (usually to http server
        // error.log).

        define('CONFIG_VERSION', 26);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).

        // vim:ft=php
?>

now, you run the two commands I said to run:
cp config.php-dist config.php-dist-old
diff -c config.php-dist config.php > config.php.patch

now, you do a pull and there's a new conifg.php-dist

Code: Select all

<?php
        // *******************************************
        // *** Database configuration (important!) ***
        // *******************************************

        define('DB_TYPE', "pgsql"); // or mysql
        define('DB_HOST', "localhost");
        define('DB_USER', "fox");
        define('DB_NAME', "fox");
        define('DB_PASS', "XXXXXX");
        define('DB_PORT', ''); // usually 5432 for PostgreSQL, 3306 for MySQL

        define('MYSQL_CHARSET', 'UTF8');
        // Connection charset for MySQL. If you have a legacy database and/or ex
perience
        // garbage unicode characters with this option, try setting it to a blan
k string.

        define('FEED_CRYPT_KEY', '');
        // Key used for encryption of passwords for password-protected feeds
        // in the database. A string of 24 random characters. If left blank, enc
ryption
       
        define('LOG_DESTINATION', 'sql');
        // Log destination to use. Possible values: sql (uses internal logging
        // you can read in Preferences -> System), syslog - logs to system log.
        // Setting this to blank uses PHP logging (usually to http server
        // error.log).

        define('CONFIG_VERSION', 26);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).

        define{'SCHEMA_VERSION','121');
        // I just decided to put this in here, just cuz.

        // vim:ft=php
?>

run my scirpt.

Code: Select all

$ ./fixconfig                           
patching file config.php
config changes:
33a34,36
>         define{'SCHEMA_VERSION','121');
>         // I just decided to put this in here, just cuz.
>
$

check config.php:

Code: Select all

<?php
        // *******************************************
        // *** Database configuration (important!) ***
        // *******************************************

        define('DB_TYPE', "pgsql"); // or mysql
        define('DB_HOST', "myhost");
        define('DB_USER', "myuser");
        define('DB_NAME', "ttrss");
        define('DB_PASS', "mypass");
        define('DB_PORT', '5432'); // usually 5432 for PostgreSQL, 3306 for MySQL

        define('MYSQL_CHARSET', 'UTF8');
        // Connection charset for MySQL. If you have a legacy database and/or ex
perience
        // garbage unicode characters with this option, try setting it to a blan
k string.

        define('FEED_CRYPT_KEY', '');
        // Key used for encryption of passwords for password-protected feeds
        // in the database. A string of 24 random characters. If left blank, enc
ryption
       
        define('LOG_DESTINATION', 'sql');
        // Log destination to use. Possible values: sql (uses internal logging
        // you can read in Preferences -> System), syslog - logs to system log.
        // Setting this to blank uses PHP logging (usually to http server
        // error.log).

        define('CONFIG_VERSION', 26);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).

        define{'SCHEMA_VERSION','121');
        // I just decided to put this in here, just cuz.

        // vim:ft=php
?>


I'm sorry if it doesn't work for you.

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 09 Jun 2013, 11:54

When I add additional comment lines to an existing define in the new config.php-dist as follows:

define('MYSQL_CHARSET', 'UTF8');
// Connection charset for MySQL. If you have a legacy database and/or experience
// garbage unicode characters with this option, try setting it to a blank string.
// additional lines
// additional lines
// additional lines
it fails.

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: How To Use Trunk Version?

Postby sleeper_service » 09 Jun 2013, 12:07

as I said... I'm sorry if it doesn't work for you.

Athanasius
Bear Rating Trainee
Bear Rating Trainee
Posts: 38
Joined: 02 Apr 2013, 21:01

Re: How To Use Trunk Version?

Postby Athanasius » 09 Jun 2013, 18:20

gbcox wrote:When I add additional comment lines to an existing define in the new config.php-dist as follows:

define('MYSQL_CHARSET', 'UTF8');
// Connection charset for MySQL. If you have a legacy database and/or experience
// garbage unicode characters with this option, try setting it to a blank string.
// additional lines
// additional lines
// additional lines
it fails.


It might be worth playing with the 'fuzz' option of patch:

-F num or --fuzz=num
Set the maximum fuzz factor. This option only applies to diffs that
have context, and causes patch to ignore up to that many lines in
looking for places to install a hunk. Note that a larger fuzz fac‐
tor increases the odds of a faulty patch. The default fuzz factor
is 2, and it may not be set to more than the number of lines of con‐
text in the context diff, ordinarily 3.


As basically your extra lines will cause patch to be unable to find subsequent excerpts to match up to the diff bits.

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 09 Jun 2013, 20:46

As basically your extra lines will cause patch to be unable to find subsequent excerpts to match up to the diff bits.

Yup... that was the point. :wink:

If you're going to build something many people can use, you really only know one thing... (maybe) and that is the state of the current.php-dist... you have no idea what is in config.php except that if ttrss is running that the "define" statements probably aren't screwed up - and who knows what wonders lurk in the config.php-dist_new. That is why I made the assumption that config.php-dist_new would be the base and then the "define" statements would be examined against what was in the old local version config.php and the old config.php-dist.

If the define statement on config.php-dist_new matched config.php-dist_old it would be probably safe to apply the change if any from the old local - that would be a yellow comment. If not, the new would take precedence and you'd get a message that it needed to be manually examined since something has changed - that would be a red comment. If the define statements from all three files matched, that is a green comment. New define statements not in old local or old dist are a blue comment. All the comments from the config.php-dist_new are saved - since if they were changed, added or deleted it was done for some reason.

diff and patch just aren't suited for this... if they were, you wouldn't see all those config.rpmnew files when you do updates. Changing config files is something that really doesn't lend itself nicely to automation, and certainly not on a one size fits all, let's throw diff and patch at it scale. The approach I took just automates the comparison of the three files, to a point - and provides a status for each "define" line it builds. I wanted to take some of the drudgery out of this necessary task - and I think based upon the way I approached it, it actually makes it a bit more accurate - but you still gotta read those status comments.

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: How To Use Trunk Version?

Postby sleeper_service » 10 Jun 2013, 00:45

Athanasius wrote:
It might be worth playing with the 'fuzz' option of patch:

As basically your extra lines will cause patch to be unable to find subsequent excerpts to match up to the diff bits.


I'm pretty sure that he's not able to see any way that something as "simple" as patch and diff can work, but *shrug* doesn't matter to me.

I believe the problem is that he changed stuff that was within the context of the patch, so that chunk was rejected, requiring manual intervention for that bit, easy enough to do, and easy enough to catch.

watching the error status of patch should smooth things out.

Code: Select all

#!/bin/sh
diff config.php-dist-old config.php-dist > config.php.changes
if [ -s config.php.changes ]; then
  echo config changes:
  cat config.php.changes
  cp config.php-dist config.php
  cp config.php-dist config.php-dist-old
  patch < config.php.patch
  if [ $? -eq 0 ]; then
    diff -c config.php-dist config.php > config.php.patch
  else
    echo "patch problems, review the .rej file and apply manually and then run"
    echo "diff -c config.php-dist config.php > config.php.patch"
  fi
fi


yes, gb, I know it doesn't work for you, and you don't like it, but, then, you don't like any of my ideas (at least not at first) anyway ;)

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 10 Jun 2013, 02:43

ROFL..... Dude, this isn't an Iron Chef competition where you're required to use diff and patch.... you're just being ridiculous now...

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: How To Use Trunk Version?

Postby sleeper_service » 10 Jun 2013, 03:21

gbcox wrote:ROFL..... Dude, this isn't an Iron Chef competition where you're required to use diff and patch.... you're just being ridiculous now...

what's this? the 'foe' setting? should be the "how to remove irrelevant drivel" setting. in the spirit of 'do not feed the trolls", done!

I'll just leave this for you, gb.

Image

User avatar
blainemono
Gaping Anus of Eternity
Gaping Anus of Eternity
Posts: 246
Joined: 05 Jun 2009, 18:13

Re: How To Use Trunk Version?

Postby blainemono » 10 Jun 2013, 09:44

hello

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 11 Jun 2013, 00:45

Good grief... my family yelled at me for being mean... so I'm sorry if I hurt your feelings...

I'm pretty sure that he's not able to see any way that something as "simple" as patch and diff can work, but *shrug* doesn't matter to me.


I understand that it "can" work, but only if you're lucky and the stars align. I was just trying to point out that you don't tend to get the results you want when you apply a patch created from two files to a third.

The reality is that the third file is going to be different, in ways that can't be predicted. Patch isn't intended to be used in this manner. Go back and re-read the description you posted. The third file isn't an original file. That's why it isn't working.

I believe the problem is that he changed stuff that was within the context of the patch...

Yes, that was me trying to point out that you really don't know what is going to change, so again, applying a patch made with two files and applying to a third isn't a good idea.

The change I made to make your approach fail wasn't something that will never happen in real life. If you take a look at "git whatchanged -p config.php-dist" you'll see that config.php-dist does change, and using diff and patch in the manner in which you are using them isn't going to work reliably.

If you can get diff and patch to work more reliably than the approach I took, I'll be the first to admit I'm wrong - but having the patch fail and putting out an error message that you need to fix it manually isn't a better approach.

gbcox
Bear Rating Master
Bear Rating Master
Posts: 149
Joined: 25 Apr 2013, 04:52

Re: How To Use Trunk Version?

Postby gbcox » 11 Jun 2013, 08:37

You're correct... by the manual it states that once a constant is defined, it can never be changed or undefined.
PHP will report this as an error, and ignore subsequent duplicates since they aren't suppose to be there - and it really isn't a good idea to purposely induce an error; programs may change the way they handle error conditions in future releases. Not to mention, it's just bad form.
If anything ever changes on those entries, you're not going to detect it with this method.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: How To Use Trunk Version?

Postby fox » 11 Jun 2013, 10:04

>tail +2 config.php-dist >> config.php

Adding yet another level of indirection there sounds like a great idea.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: How To Use Trunk Version?

Postby fox » 11 Jun 2013, 10:22

Much like zfs backup of databases, this also might work most of the time, but not something I would recommend doing and/or relying on.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 5 guests