Skip to content

Commit

Permalink
Component: Use key where more appropriate
Browse files Browse the repository at this point in the history
This patch updates the function documentation, prototypes and
implementation for new() and copy() functions of Modulemd.Component
to make it clear when the feature uses is the key and when it is
the real component name.

Signed-off-by: Stephen Gallagher <[email protected]>
  • Loading branch information
sgallagher committed Mar 14, 2019
1 parent e219b93 commit 5e42e86
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
5 changes: 3 additions & 2 deletions modulemd/v2/include/modulemd-2.0/modulemd-component-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ G_DECLARE_FINAL_TYPE (ModulemdComponentModule,

/**
* modulemd_component_module_new:
* @name: (not nullable): The name of this module component.
* @key: (not nullable): The key of this module component. Used when looking up
* components from a #ModulemdModuleStream.
*
* Returns: (transfer full): A newly-allocated #ModulemdComponentModule object.
*
* Since: 2.0
*/
ModulemdComponentModule *
modulemd_component_module_new (const gchar *name);
modulemd_component_module_new (const gchar *key);


/**
Expand Down
5 changes: 3 additions & 2 deletions modulemd/v2/include/modulemd-2.0/modulemd-component-rpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ G_DECLARE_FINAL_TYPE (ModulemdComponentRpm,

/**
* modulemd_component_rpm_new:
* @name: (not nullable): The name of this module component.
* @key: (not nullable): The key of this module component. Used when looking up
* components from a #ModulemdModuleStream.
*
* Returns: (transfer full): A newly-allocated #ModulemdComponentRpm object.
*
* Since: 2.0
*/
ModulemdComponentRpm *
modulemd_component_rpm_new (const gchar *name);
modulemd_component_rpm_new (const gchar *key);


/**
Expand Down
8 changes: 5 additions & 3 deletions modulemd/v2/include/modulemd-2.0/modulemd-component.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct _ModulemdComponentClass
{
GObjectClass parent_class;

ModulemdComponent *(*copy) (ModulemdComponent *self, const gchar *name);
ModulemdComponent *(*copy) (ModulemdComponent *self, const gchar *key);
void (*set_name) (ModulemdComponent *self, const gchar *name);
const gchar *(*get_name) (ModulemdComponent *self);

Expand All @@ -44,14 +44,16 @@ struct _ModulemdComponentClass
/**
* modulemd_component_copy:
* @self: This #ModulemdComponent object
* @name: (in) (nullable): An optional new name for the copied component
* @key: (in) (nullable): An optional new key for the copied component which is
* used as the lookup key when this component is attached to a
* #ModulemdModuleStream.
*
* Returns: (transfer full): A newly-allocated copy of @self
*
* Since: 2.0
*/
ModulemdComponent *
modulemd_component_copy (ModulemdComponent *self, const gchar *name);
modulemd_component_copy (ModulemdComponent *self, const gchar *key);


/**
Expand Down
8 changes: 4 additions & 4 deletions modulemd/v2/modulemd-component-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ static GParamSpec *properties[N_PROPS];


ModulemdComponentModule *
modulemd_component_module_new (const gchar *name)
modulemd_component_module_new (const gchar *key)
{
return g_object_new (MODULEMD_TYPE_COMPONENT_MODULE, "name", name, NULL);
return g_object_new (MODULEMD_TYPE_COMPONENT_MODULE, "name", key, NULL);
}


Expand All @@ -64,7 +64,7 @@ modulemd_component_module_finalize (GObject *object)


static ModulemdComponent *
modulemd_component_module_copy (ModulemdComponent *self, const gchar *name)
modulemd_component_module_copy (ModulemdComponent *self, const gchar *key)
{
ModulemdComponentModule *module_self = NULL;
g_autoptr (ModulemdComponentModule) copy = NULL;
Expand All @@ -73,7 +73,7 @@ modulemd_component_module_copy (ModulemdComponent *self, const gchar *name)

copy = MODULEMD_COMPONENT_MODULE (
MODULEMD_COMPONENT_CLASS (modulemd_component_module_parent_class)
->copy (self, name));
->copy (self, key));

modulemd_component_module_set_ref (
copy, modulemd_component_module_get_ref (module_self));
Expand Down
8 changes: 4 additions & 4 deletions modulemd/v2/modulemd-component-rpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ static GParamSpec *properties[N_PROPS];


ModulemdComponentRpm *
modulemd_component_rpm_new (const gchar *name)
modulemd_component_rpm_new (const gchar *key)
{
return g_object_new (MODULEMD_TYPE_COMPONENT_RPM, "name", name, NULL);
return g_object_new (MODULEMD_TYPE_COMPONENT_RPM, "name", key, NULL);
}


Expand Down Expand Up @@ -100,7 +100,7 @@ static const gchar *
modulemd_component_rpm_get_name (ModulemdComponent *self);

static ModulemdComponent *
modulemd_component_rpm_copy (ModulemdComponent *self, const gchar *name)
modulemd_component_rpm_copy (ModulemdComponent *self, const gchar *key)
{
ModulemdComponentRpm *rpm_self = NULL;
g_autoptr (ModulemdComponentRpm) copy = NULL;
Expand All @@ -109,7 +109,7 @@ modulemd_component_rpm_copy (ModulemdComponent *self, const gchar *name)

copy = MODULEMD_COMPONENT_RPM (
MODULEMD_COMPONENT_CLASS (modulemd_component_rpm_parent_class)
->copy (self, name));
->copy (self, key));

modulemd_component_rpm_set_ref (copy,
modulemd_component_rpm_get_ref (rpm_self));
Expand Down
20 changes: 13 additions & 7 deletions modulemd/v2/modulemd-component.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ modulemd_component_finalize (GObject *object)


ModulemdComponent *
modulemd_component_copy (ModulemdComponent *self, const gchar *name)
modulemd_component_copy (ModulemdComponent *self, const gchar *key)
{
g_return_val_if_fail (self, NULL);

Expand All @@ -69,20 +69,20 @@ modulemd_component_copy (ModulemdComponent *self, const gchar *name)
klass = MODULEMD_COMPONENT_GET_CLASS (self);
g_return_val_if_fail (klass->copy, NULL);

return klass->copy (self, name);
return klass->copy (self, key);
}


static ModulemdComponent *
modulemd_component_copy_component (ModulemdComponent *self, const gchar *name)
modulemd_component_copy_component (ModulemdComponent *self, const gchar *key)
{
ModulemdComponentPrivate *priv =
modulemd_component_get_instance_private (self);
g_autoptr (ModulemdComponent) m = NULL;
if (name == NULL)
name = priv->name;
if (key == NULL)
key = priv->name;

m = g_object_new (G_OBJECT_TYPE (self), "name", name, NULL);
m = g_object_new (G_OBJECT_TYPE (self), "name", key, NULL);

modulemd_component_set_buildorder (m,
modulemd_component_get_buildorder (self));
Expand Down Expand Up @@ -214,6 +214,9 @@ modulemd_component_get_property (GObject *object,
break;

case PROP_NAME:
/* On lookups, return the real name value, not the key. This differs from
* the set function, which always assigns the key.
*/
g_value_set_string (value, modulemd_component_get_name (self));
break;

Expand Down Expand Up @@ -241,6 +244,7 @@ modulemd_component_set_property (GObject *object,
break;

case PROP_NAME:
/* On object creation, we set the key. */
modulemd_component_set_key (self, g_value_get_string (value));
break;

Expand Down Expand Up @@ -277,7 +281,9 @@ modulemd_component_class_init (ModulemdComponentClass *klass)
properties[PROP_NAME] = g_param_spec_string (
"name",
"Name",
"The name of the component.",
"The name of the component. This is the real name of the component and "
"may differ from the key used to associate this component with the "
"ModuleStream.",
C_DEFAULT_STRING,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_RATIONALE] =
Expand Down

0 comments on commit 5e42e86

Please sign in to comment.