Bug 266196 - [repo] flags used in getKnownRepositories(int) are confusing
Summary: [repo] flags used in getKnownRepositories(int) are confusing
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2009-02-25 14:27 EST by Susan McCourt CLA
Modified: 2010-03-05 15:42 EST (History)
2 users (show)

See Also:


Attachments
Fix (4.25 KB, patch)
2010-03-05 15:41 EST, John Arthorne CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Susan McCourt CLA 2009-02-25 14:27:57 EST
I find the repo flags used in IRepositoryManager.getKnownRepositories(flags) confusing.  They aren't truly bits that can be OR'ed together, although they appear on first glance that way. Some act as filters to the other bits, some do not.

REPOSITORIES_DISABLED | REPOSITORIES_LOCAL will give me all disabled local repos
REPOSITORIES_ALL | REPOSITORIES_LOCAL gives all enabled local repos

To get all (enabled and disabled) local repos I have to combine them myself using the above two calls.

I'd rather be able to say 
REPOSITORIES_LOCAL | REPOSITORIES_ENABLED | REPOSITORIES_DISABLED

Likewise I can't say
REPOSITORIES_SYSTEM | REPOSITORIES_NON_SYSTEM | REPOSITORIES_DISABLED
to get all the disabled repos.  I have to do it twice, once for system and once for non-system.

I find I always have to refer to the implementation of matchesFlag to figure out how to do what I want, ie, which ones are filters that disregard the other bits and which ones are bits that can truly be combined with others.

This causes problems in the UI because I'd like to let clients pass me the repo bits to fully describe which repos they want to see, but they can't do that.  So I've had to introduce extra flags like "includeDisabledRepositories" so that I can make the multiple calls needed to get the list of repos correct.
Comment 1 John Arthorne CLA 2009-02-25 17:37:56 EST
Yes, it is confusing. Part of the confusion is that getKnownRepositories initially had a default behaviour (all enabled repositories), so when we added flags there is essentially always an implicit REPOSITORIES_ENABLED flag.

However, I don't know how we can express what you are looking for purely with flags. This:

REPOSITORIES_LOCAL | REPOSITORIES_ENABLED | REPOSITORIES_DISABLED

Would always return everything, since every repository is either ENABLED or DISABLED. What you are trying to express is something more like:

REPOSITORIES_LOCAL & (REPOSITORIES_ENABLED | REPOSITORIES_DISABLED)

Which can't be expressed with a pure bit mask.

>Likewise I can't say
>REPOSITORIES_SYSTEM | REPOSITORIES_NON_SYSTEM | REPOSITORIES_DISABLED
>to get all the disabled repos.  I have to do it twice, once for system and once
>for non-system.

I think you can do this one with simply getKnownRepositories(REPOSITORIES_DISABLED).

The flags in practice act like exclusion filters (LOCAL means "exclude non-local", SYSTEM means "exclude non-system", etc). So, it might be less confusing if they were renamed as such. I'm still not sure this would allow you to express everything you want in a single mask.
Comment 2 Susan McCourt CLA 2009-02-25 18:05:08 EST
maybe just reexamining the naming and some examples in the javadoc would help.  

Part of what's odd is that in one case we provide filters for both states of a boolean (SYSTEM, NON_SYSTEM) and in other cases we do not (LOCAL, DISABLED).  So it's hard to just glance at the bits and figure out what to do.
Comment 3 Pascal Rapicault CLA 2010-01-25 14:54:21 EST
Putting that back on the list for API.
Comment 4 John Arthorne CLA 2010-03-05 15:41:38 EST
Created attachment 161189 [details]
Fix

Here's my attempt at clarifying this without completely reinventing how this works. I have just added more javadoc on each of the flags and on getKnownRepositories to describe how they behave. I have also added a NON_LOCAL flag for symmetry with LOCAL, although I'm not sure if there is any demand for it.

I also played around with inverting the flag names (REPOSITORIES_SYSTEM becomes REPOSITORIES_EXCLUDE_NON_SYSTEM), but with a few samples it didn't look any more intuitive to me with double-negative terms like this.
Comment 5 John Arthorne CLA 2010-03-05 15:42:52 EST
Released in HEAD.