git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-svn: do not reuse caches memoized for a different architecture
@ 2016-10-25 15:30 Johannes Schindelin
  2016-10-25 21:23 ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2016-10-25 15:30 UTC (permalink / raw)
  To: Eric Wong, git; +Cc: Gavin Lambert, Junio C Hamano

From: Gavin Lambert <github@mirality.co.nz>

Reusing cached data speeds up git-svn by quite a fair bit. However, if
the YAML module is unavailable, the caches are written to disk in an
architecture-dependent manner. That leads to problems when upgrading,
say, from 32-bit to 64-bit Git for Windows.

Let's just try to read those caches back if we detect the absence of the
YAML module and the presence of the file, and delete the file if it
could not be read back correctly.

Note that the only way to catch the error when the memoized cache could
not be read back is to put the call inside an `eval { ... }` block
because it would die otherwise; the `eval` block should also return `1`
in case of success explicitly since the function reading back the cached
data does not return an appropriate value to test for success.

This fixes https://github.com/git-for-windows/git/issues/233.

Signed-off-by: Gavin Lambert <github@mirality.co.nz>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Published-As: https://github.com/dscho/git/releases/tag/svn-multi-arch-v1
Fetch-It-Via: git fetch https://github.com/dscho/git svn-multi-arch-v1

We carried this for some time in Git for Windows.

 perl/Git/SVN.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 018beb8..025c894 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -1658,6 +1658,11 @@ sub tie_for_persistent_memoization {
 	if ($memo_backend > 0) {
 		tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
 	} else {
+		# first verify that any existing file can actually be loaded
+		# (it may have been saved by an incompatible version)
+		if (-e "$path.db") {
+			unlink "$path.db" unless eval { retrieve("$path.db"); 1 };
+		}
 		tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
 	}
 }

base-commit: 659889482ac63411daea38b2c3d127842ea04e4d
-- 
2.10.1.583.g721a9e0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-svn: do not reuse caches memoized for a different architecture
  2016-10-25 15:30 [PATCH] git-svn: do not reuse caches memoized for a different architecture Johannes Schindelin
@ 2016-10-25 21:23 ` Eric Wong
  2016-10-27 19:44   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2016-10-25 21:23 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, Gavin Lambert, Junio C Hamano

Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
> +++ b/perl/Git/SVN.pm
> @@ -1658,6 +1658,11 @@ sub tie_for_persistent_memoization {
>  	if ($memo_backend > 0) {
>  		tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
>  	} else {
> +		# first verify that any existing file can actually be loaded
> +		# (it may have been saved by an incompatible version)
> +		if (-e "$path.db") {
> +			unlink "$path.db" unless eval { retrieve("$path.db"); 1 };
> +		}

That retrieve() call is unlikely to work without "use Storable"
to import it into the current package.

I also favor setting "$path.db" once to detect typos and avoid
going over 80 columns.  Additionally, having error-checking for
unlink might be useful.

So perhaps squashing this on top:

diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 025c894..b3c1460 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -1660,10 +1660,15 @@ sub tie_for_persistent_memoization {
 	} else {
 		# first verify that any existing file can actually be loaded
 		# (it may have been saved by an incompatible version)
-		if (-e "$path.db") {
-			unlink "$path.db" unless eval { retrieve("$path.db"); 1 };
+		my $db = "$path.db";
+		if (-e $db) {
+			use Storable qw(retrieve);
+
+			if (!eval { retrieve($db); 1 }) {
+				unlink $db or die "unlink $db failed: $!";
+			}
 		}
-		tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
+		tie %$hash => 'Memoize::Storable', $db, 'nstore';
 	}
 }
 

Thoughts?  Thanks.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-svn: do not reuse caches memoized for a different architecture
  2016-10-25 21:23 ` Eric Wong
@ 2016-10-27 19:44   ` Junio C Hamano
  2016-10-27 20:51     ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2016-10-27 19:44 UTC (permalink / raw)
  To: Eric Wong; +Cc: Johannes Schindelin, git, Gavin Lambert

Eric Wong <e@80x24.org> writes:

> Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
>> +++ b/perl/Git/SVN.pm
>> @@ -1658,6 +1658,11 @@ sub tie_for_persistent_memoization {
>>  	if ($memo_backend > 0) {
>>  		tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
>>  	} else {
>> +		# first verify that any existing file can actually be loaded
>> +		# (it may have been saved by an incompatible version)
>> +		if (-e "$path.db") {
>> +			unlink "$path.db" unless eval { retrieve("$path.db"); 1 };
>> +		}
>
> That retrieve() call is unlikely to work without "use Storable"
> to import it into the current package.
>
> I also favor setting "$path.db" once to detect typos and avoid
> going over 80 columns.  Additionally, having error-checking for
> unlink might be useful.
>
> So perhaps squashing this on top:
>
> diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
> index 025c894..b3c1460 100644
> --- a/perl/Git/SVN.pm
> +++ b/perl/Git/SVN.pm
> @@ -1660,10 +1660,15 @@ sub tie_for_persistent_memoization {
>  	} else {
>  		# first verify that any existing file can actually be loaded
>  		# (it may have been saved by an incompatible version)
> -		if (-e "$path.db") {
> -			unlink "$path.db" unless eval { retrieve("$path.db"); 1 };
> +		my $db = "$path.db";
> +		if (-e $db) {
> +			use Storable qw(retrieve);
> +
> +			if (!eval { retrieve($db); 1 }) {
> +				unlink $db or die "unlink $db failed: $!";
> +			}
>  		}
> -		tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
> +		tie %$hash => 'Memoize::Storable', $db, 'nstore';
>  	}
>  }
>  
>
> Thoughts?  Thanks.

Just peeking from the sideline, but the your squash looks like an
improvement to me.

Hopefully the final version after your interaction with Dscho can
come to me via another "pull this now"?

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-svn: do not reuse caches memoized for a different architecture
  2016-10-27 19:44   ` Junio C Hamano
@ 2016-10-27 20:51     ` Eric Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-10-27 20:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git, Gavin Lambert

Junio C Hamano <gitster@pobox.com> wrote:
> Just peeking from the sideline, but the your squash looks like an
> improvement to me.

Thanks.

> Hopefully the final version after your interaction with Dscho can
> come to me via another "pull this now"?

Not sure if I'll be online the next few days,
but I've preeptively pushed the patch + squash to my repo:

The following changes since commit 2cc2e70264e0fcba04f9ef791d144bbc8b501206:

  Eleventh batch for 2.11 (2016-10-26 13:28:47 -0700)

are available in the git repository at:

  git://bogomips.org/git-svn.git svn-cache

for you to fetch changes up to a2c761ce5b7a5fd8b505b036f3509a9e6617dee8:

  git-svn: do not reuse caches memoized for a different architecture (2016-10-27 20:17:36 +0000)

----------------------------------------------------------------
Gavin Lambert (1):
      git-svn: do not reuse caches memoized for a different architecture

 perl/Git/SVN.pm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-10-27 20:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-25 15:30 [PATCH] git-svn: do not reuse caches memoized for a different architecture Johannes Schindelin
2016-10-25 21:23 ` Eric Wong
2016-10-27 19:44   ` Junio C Hamano
2016-10-27 20:51     ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).