Multiple repos – good progress

Today I managed to make quite a bit of progress trying to incorporate multiple ports trees into the commit processing. The diff is about 985 lines long. It’s not as complex as it sounds. I just have to pass $CommitBranch around to various functions.

The result: I have the commits going into the database, but not all the associated processing is completed. For example, dependencies are not recorded properly.

Current status

The database now has the ability to hold multiple ports on multiple branches:

freshports.org=# select id, name, category, element_id, element_pathname(element_id) from ports_active where name = 'spellathon';
  id   |    name    | category | element_id |               element_pathname                
-------+------------+----------+------------+-----------------------------------------------
 24964 | spellathon | games    |     324899 | /ports/head/games/spellathon
 34159 | spellathon | games    |     559872 | /ports/branches/RELENG_9_1_0/games/spellathon
(2 rows)

freshports.org=# 

However, some of the supporting functions work on category/port and cannot distinguish between the above two ports. They are going to fail.

For example, when I go to add dependencies to this port, it errors out with duplicate key:

freshports.org=# SELECT PortsDependenciesAdd( 'games/spellathon', 'devel/libpthread-stubs', 'L' );
ERROR:  duplicate key value violates unique constraint "port_dependencies_pkey"
DETAIL:  Key (port_id, port_id_dependent_upon, dependency_type)=(24964, 19850, L) already exists.
CONTEXT:  SQL statement "INSERT INTO port_dependencies (port_id, port_id_dependent_upon, dependency_type)
            VALUES (l_PortID, l_PortIDDependency, p_DependencyType)"
PL/pgSQL function portsdependenciesadd(text,text,text) line 19 at SQL statement
freshports.org=# 

I think the cause of this problem is this function:

select GetPort('games/spellathon');
 getport 
---------
   24964
(1 row)

Looking at the code, I see this:

CREATE OR REPLACE FUNCTION GetPort(text) RETURNS int4 AS $$
   DECLARE
      category_port ALIAS for $1;
      pathname         text;
      port_element_id  int4;
      port_id          int4;
   BEGIN
      pathname        := '/ports/head/' || category_port;
      port_element_id := Pathname_ID(pathname);
      if port_element_id IS NOT NULL THEN
         select id
           into port_id  
           from ports    
          where element_id = port_element_id;
      END IF;
      return port_id;
   END;
$$ LANGUAGE 'plpgsql';  

See that hardcoded path on line 8? That’s what we have to cope with.

There is another function, which takes two parameters:

CREATE OR REPLACE FUNCTION GetPort(text, text) RETURNS int4 AS $$
   DECLARE
      p_Category ALIAS for $1;
      p_Port     ALIAS for $2;

      l_port_id          int4;
   BEGIN
      SELECT id
        INTO l_port_id
        FROM ports_active
       WHERE name     = p_Port
         AND category = p_Category;

      RETURN l_port_id;
   END;
$$ LANGUAGE 'plpgsql' STABLE;

This function is also suspect:

CREATE OR REPLACE FUNCTION GetPortID(text, text) returns bigint AS $$
   DECLARE
      CategoryName ALIAS for $1;
      PortName     ALIAS for $2;

      CategoryID   int8;
      IsPrimary    boolean;
      PortID       int8;

   BEGIN

      SELECT id, is_primary
        INTO CategoryID, IsPrimary
        FROM categories
       WHERE name = CategoryName;

      IF FOUND THEN
         IF IsPrimary THEN
            SELECT ports_all.id
              INTO PortID
              FROM ports_all, categories
             WHERE ports_all.category_id = categories.id   
               AND ports_all.name        = PortName
               AND categories.id         = CategoryID;
         ELSE
            SELECT ports_all.id
              INTO PortID
              FROM ports_categories, ports_all
             WHERE ports_categories.port_id     = ports_all.id
               AND ports_categories.category_id = CategoryID
               AND ports_all.name               = PortName;
         END IF;
      ELSE
      END IF;

      return PortID;

   END
$$ LANGUAGE 'plpgsql';

Also on my list are:

  1. PortsMovedAdd()
  2. PortsUpdatingPortsXrefAdd()
  3. SetSlavePort()
  4. PortsDependenciesAdd() – mentioned at the start of this post

What’s next?

I have to figure out a way for these functions to know which BRANCH we are working on. That may involve a global setting, a parameter, a setting… I’m not sure yet.

What I do know for sure is that’s going to have to wait for another day.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

1 thought on “Multiple repos – good progress”

Leave a Comment

Scroll to Top