Hi,
to simplify some code for versioncontrol_git related to tags I'd need a function which updates either a whole operation or just the labels assigned to it. Really cool would be a function which you pass the operation and an array of the keys you want to be replaced. Another possibility would be a function to add another label to an operation. If you don't like both, it may be a bug that a tag doesn't autoadd itself to the tagged commit which then should be fixed :P

Comments

CorniI’s picture

update: As code evolved, I need particular a fast function to replace all branches which are assigned to an $operation with an array of labels without using the database directly. This is pretty critical for the versioncontrol_git speed. More generalized, but slower, functions, are appreciated, too, for usage in less speed-critical code paths.

jpetso’s picture

Both approaches sound useful to me, although restricting changes to labels for now might be easier to implement, given the potential changes that come with operation changes. (Note that modules are able to implement hook_versioncontrol_operation() so they might rely on some of the stuff in the operation, all of that would need to be checked and changed for an actual whole-operation update.)

An actual API for label management is badly missing in Version Control API, I would love to have a set of get_labels() and delete_label() functions. Your other issue (#426284: API request: versioncontrol_get_label_list()) is an important step into the right direction, and a function that updates operation labels would be similarly welcome. Should also provide some hook for modules that store something that uses operation label information.

Note that this is not top priority for me though at the moment (sorry), so I might not come up with such a function by myself. Anyways, how about versioncontrol_update_operation_labels($operation, $labels) as function signature?

CorniI’s picture

My problem with versioncontrol_update_operation_labels($operation, $labels) is that for everey commit I want to update the branches for i'd have to retrieve the tags, too. I looked at VCS-API and it would need this info anyways, but I think that we want the type of a label in versioncontrol_operation_labels, too, so we can update branches without updating/deleting tags. I think I could come up with a patch for doing that.

CorniI’s picture

I'm sorry, i've not any experience with hooks, this task is left for you :P

/**
 * Replaces the labels in one operation with the one in @p $labels
 * @param $operation The operation to replace the labels for
 * @param array $labels  An array of label-arrays to use for the given operation 
 */
function versioncontrol_update_operation_labels($operation, $labels) {
  db_query("DELETE FROM {versioncontrol_operation_labels}
            WHERE vc_op_id = %d",
            $operation['vc_op_id']);
  foreach ($labels as $label) {
    db_query("INSERT INTO {versioncontrol_operation_labels}
              (vc_op_id, label_id, action) VALUES (%d, %d, %d)",
              $operation['vc_op_id'], $label['label_id'], $label['action']);
  }
}

Works well on my end :)

jpetso’s picture

Status: Active » Needs review
StatusFileSize
new7.67 KB

Creating a workable API for the hook was a bit of a challenge - would this patch work for you?

CorniI’s picture

works fine, thanks. Please go ahead and commit the patch :)

jpetso’s picture

Status: Needs review » Fixed

k, committed as is.

Status: Fixed » Closed (fixed)

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

  • Commit e20528f on 6.x-1.x, repository-families, drush-vc-sync-unlock by jpetso:
    #426376 by CorniI and jpetso: New API function...

  • Commit e20528f on 6.x-1.x, repository-families by jpetso:
    #426376 by CorniI and jpetso: New API function...