Hi,
could you include the following function in versioncontrol.module (or in backend, doesn't matter for me). I need it for the git backend to see which branches are already in the database. This is needed because git doesn't track branches, so we will never add/delete branches in an $operation.

/**
 * Returns an array of all labels in a repository, and if $type is given, filters by TAG or BRANCH.
 * 
 * @param $repository As given by the API
 * @param $type Set the filter type, possibel values are VERSIONCONTROL_OPERATION_{TAG,BRANCH}
 * @return array An array of strings with the label names.
 */
function versioncontrol_get_label_list($repository, $type = FALSE)
{
  $query = "SELECT label_id, repo_id, name, type FROM {versioncontrol_labels}
      WHERE repo_id = %d";
  if ($type !== FALSE) {
     $query .= " AND type = %d";
     $result = db_query($query, $repository['repo_id'], $type);
  }
  else
  {
    $result = db_query($query, $repository['repo_id']);
  }
  $labels = array();
  while ($row = db_fetch_object($result)) {
    $labels[] = $row->name;
  }
  return $labels;
}
CommentFileSizeAuthor
#2 versioncontrol-get-labels.diff3.99 KBjpetso

Comments

jpetso’s picture

Status: Active » Needs work

I totally want such a function in the API module. However, for consistency with the other getter functions (get_operations(), get_repositories(), get_accounts()), I'd like to see a function signature like versioncontrol_get_labels($constraints = array()) with repository and type being optional constraints that are added to the query if they exist. Later on, we could also add a constraint for label ids, affected operations or whatever.

If the API and apidox are ok, those additional features can of course wait until someone (for example, me) is motivated to implement them - I've got no problem adding partial solutions if they're prepared to stand the test of time :P

jpetso’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB

Please have a look if the attached patch works for you.

I decided to leave the repository as separate (required) argument, as the repo_id is not a standard element of label arrays, which would make the set of labels ambiguous if labels are retrieved from different repositories. Probably the feature of requesting labels from different repositories won't be needed anyways.

CorniI’s picture

Status: Needs review » Reviewed & tested by the community

looks good. But as a side node, I just discovered that further optimization of my code made the function unnecessary for the moment (You know, code is still in flux). But ithisis a handy func, so please include it anyways, we could need it later.

jpetso’s picture

Status: Reviewed & tested by the community » Fixed

k, committed. I don't mind if you don't need it at the moment, as I wanted this function anyways (but didn't get around to code it until now).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 02689f8 on 6.x-1.x, repository-families, drush-vc-sync-unlock by jpetso:
    #426284 by jpetso: Introduce a new versioncontrol_get_labels() function...

  • Commit 02689f8 on 6.x-1.x, repository-families by jpetso:
    #426284 by jpetso: Introduce a new versioncontrol_get_labels() function...