public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Brian Dolbec <dolsen@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH 1/2] dblink: case insensitive support for bug #524236
Date: Sun, 16 Nov 2014 10:11:15 -0800	[thread overview]
Message-ID: <20141116101115.6c61ce58.dolsen@gentoo.org> (raw)
In-Reply-To: <1416134515-31943-1-git-send-email-zmedico@gentoo.org>

On Sun, 16 Nov 2014 02:41:54 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> This adds dblink._contents_contains, _contents_iter, and
> _contents_key methods that provide an interface for contents
> operations with "implicit" case handling.
> 
> X-Gentoo-Bug: 524236
> X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=524236
> ---
>  pym/portage/dbapi/vartree.py | 43
> +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43
> insertions(+)
> 
> diff --git a/pym/portage/dbapi/vartree.py
> b/pym/portage/dbapi/vartree.py index 8b06f4c..2d1003f 100644
> --- a/pym/portage/dbapi/vartree.py
> +++ b/pym/portage/dbapi/vartree.py
> @@ -1515,6 +1515,8 @@ class dblink(object):
>  		self.contentscache = None
>  		self._contents_inodes = None
>  		self._contents_basenames = None
> +		self._contents_case_insensitive = None
> +		self._contents_case_reverse_map = None

I like that you've prefixed the new variables with _contents_.

I also see there already are a number of _contents_ prefixed variables
and now newly added functions below.



>  		self._linkmap_broken = False
>  		self._device_path_map = {}
>  		self._hardlink_merge_map = {}
> @@ -1526,6 +1528,15 @@ class dblink(object):
>  		# compliance with RESTRICT=preserve-libs.
>  		self._preserve_libs = "preserve-libs" in
> mysettings.features 
> +		if "case-insensitive-fs" in self.settings.features:
> +			self._contents_key =
> self._contents_key_case_insensitive
> +			self._contents_contains =
> self._contents_contains_case_insensitive
> +			self._contents_iter =
> self._contents_iter_case_insensitive
> +		else:
> +			self._contents_key =
> self._contents_key_case_sensitive
> +			self._contents_contains =
> self._contents_contains_case_sensitive
> +			self._contents_iter =
> self._contents_iter_case_sensitive +
>  	def __hash__(self):
>  		return hash(self._hash_key)
>  
> @@ -1612,6 +1623,8 @@ class dblink(object):
>  		self.contentscache = None
>  		self._contents_inodes = None
>  		self._contents_basenames = None
> +		self._contents_case_insensitive = None
> +		self._contents_case_reverse_map = None
>  
>  	def getcontents(self):
>  		"""
> @@ -1716,6 +1729,36 @@ class dblink(object):
>  		self.contentscache = pkgfiles
>  		return pkgfiles
>  
> +	def _contents_case_insensitive_init(self):
> +		self._contents_case_insensitive = dict(
> +			(k.lower(), v) for k, v in
> self.getcontents().items())
> +		self._contents_case_reverse_map = dict(
> +			(k.lower(), k) for k in self.getcontents())
> +
> +	def _contents_iter_case_insensitive(self):
> +		if self._contents_case_insensitive is None:
> +			self._contents_case_insensitive_init()
> +		return iter(self._contents_case_insensitive)
> +
> +	def _contents_key_case_insensitive(self, key):
> +		if self._contents_case_reverse_map is None:
> +			self._contents_case_insensitive_init()
> +		return self._contents_case_reverse_map[key]
> +
> +	def _contents_contains_case_insensitive(self, key):
> +		if self._contents_case_insensitive is None:
> +			self._contents_case_insensitive_init()
> +		return key.lower() in self._contents_case_insensitive
> +
> +	def _contents_key_case_sensitive(self, key):
> +		return key
> +
> +	def _contents_iter_case_sensitive(self):
> +		return iter(self.getcontents())
> +
> +	def _contents_contains_case_sensitive(self, key):
> +		return key in self.getcontents()
> +
>  	def _prune_plib_registry(self, unmerge=False,
>  		needed=None, preserve_paths=None):
>  		# remove preserved libraries that don't have any
> consumers left


These truly have little interaction with the rest of the dblink class.
I would like to see them moved to an independent class.  With that move
the names could be shortened without the _contents prefix since they
would be Contents class referenced.  It also looks like there should be
additional code from the dblink class moved into this new class.
Primarily the getcontents(), but that is a much larger refactor.  That
would also require the cache, re's and probably some others.  Then all
the references to these functions in the vardbapi to the class
instance instead.

On that note, I propose we put this new code in a new class (avoiding
adding to the bloat), pass in the getcontents() pointer along with some
others needed. In later commits do the major re-factor moving more
contents specific handling code into the new class.  Bare in mind I
have not looked that extensively in dblink and vardbapi, but it does
look doable. 

Are you up for the challenge? ;)  
I think it would certainly make the code more maintainable, less
daunting and more clearly defined.  We could even split vartree.py into
some smaller files or sub-pkg.  I dislike multi-thousand lines of code
files and classes.  It makes it much more difficult to move around and
keep track of interactions between the code (complexity) and to learn
everything it does.

-- 
Brian Dolbec <dolsen>



  parent reply	other threads:[~2014-11-16 18:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13  1:22 [gentoo-portage-dev] [PATCH] FEATURES=case-insensitive-fs for bug #524236 Zac Medico
2014-11-13 10:29 ` Alexander Berntsen
2014-11-13 17:58   ` Zac Medico
2014-11-16 10:41     ` [gentoo-portage-dev] [PATCH 1/2] dblink: case insensitive support " Zac Medico
2014-11-16 10:41       ` [gentoo-portage-dev] [PATCH 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-16 18:11       ` Brian Dolbec [this message]
2014-11-17  1:29         ` [gentoo-portage-dev] [PATCH v2 1/2] dblink: case insensitive support " Zac Medico
2014-11-17  1:29           ` [gentoo-portage-dev] [PATCH v2 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-17  4:58           ` [gentoo-portage-dev] [PATCH v2 1/2] dblink: case insensitive support " Brian Dolbec
2014-11-17 20:29             ` [gentoo-portage-dev] [PATCH v3 " Zac Medico
2014-11-17 20:29               ` [gentoo-portage-dev] [PATCH v3 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-17 22:09               ` [gentoo-portage-dev] [PATCH v3 1/2] dblink: case insensitive support " Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141116101115.6c61ce58.dolsen@gentoo.org \
    --to=dolsen@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox