Commit 5ca19f2f authored by Marco Villegas's avatar Marco Villegas
Browse files

Issue #1704548: Remove the idea of selected label.

The process of inferring a label based on item revision information is
not always possible, and on scenarios that it would be liked to be used
that information is usually available.

Also, the way this is implemented now is hacky, so this feature can
maybe be re-introduced in the future in a clean way, but let's remove it
from now.

Conflicts:
    tests/versioncontrol_test.inc
    versioncontrol_fakevcs/includes/classes.inc
      Minor docblocks conflicts.
parent 7506f8ce
Loading
Loading
Loading
Loading
+0 −134
Changes for includes/VersioncontrolItem.php: 0 added lines, 134 removed lines.
Original line number Diff line number Diff line
@@ -96,19 +96,6 @@ abstract class VersioncontrolItem extends VersioncontrolEntity {
    VERSIONCONTROL_ACTION_REPLACED => 0, // does not happen, guard nonetheless
  );

  /**
   * Constructor.
   */
//  public function __construct($type, $path, $revision, $action, $repository, $deleted = NULL, $item_revision_id = NULL) {
//    $this->type = $type;
//    $this->path = $path;
//    $this->revision = $revision;
//    $this->action = $action;
//    $this->repository = $repository;
//    $this->deleted = $deleted;
//    $this->item_revision_id = $item_revision_id;
//  }

  /**
   * Return TRUE if the given item is an existing or an already deleted
   * file, or FALSE if it's not.
@@ -295,74 +282,6 @@ abstract class VersioncontrolItem extends VersioncontrolEntity {
    return TRUE;
  }

  /**
   * Retrieve an item's selected label.
   *
   * When first retrieving an item, the selected label is initialized
   * with a sensible value - for example,
   * VersioncontrolOperation::getItems() assigns the affected branch or
   * tag of that operation to all the items. (This is especially
   * important for version control systems like Subversion where there is
   * a need to specify the label per item and not per operation, as a
   * single commit can affect multiple branches or tags at once.)
   *
   * The selected label is also meant to help with branch/tag-based
   * navigation, so item navigation functions will try to preserve it as
   * good as possible, as far as it's accurate.
   *
   * @return
   *   In case no branch or tag applies to that item or could not be
   *   retrieved for whatever reasons, the selected label can also be
   *   NULL. Otherwise, it's a VersioncontrolLabel object(tag or branch)
   */
  public function getSelectedLabel() {
    // If the label is already retrieved, we can return it just that way.
    if (isset($this->selected_label->label)) {
      return ($this->selected_label->label === FALSE)
        ? NULL : $this->selected_label->label;
    }
    if (!isset($this->selected_label->get_from)) {
      $this->selected_label->label = FALSE;
      return NULL;
    }

    // Otherwise, determine how we might be able to retrieve the selected
    // label.
    switch ($this->selected_label->get_from) {
    case 'operation':
      $selected_label = $this->selected_label->operation->getSelectedLabel($this);
      break;
    case 'other_item':
      $selected_label = $this->getSelectedLabelFromItem($this->selected_label->other_item, $this->selected_label->other_item_tags);
      unset($this->selected_label->other_item_tags);
      break;
    }

    if (isset($selected_label)) {
      // Just to make sure that we only pass applicable info:
      // 'action' might make sense in an operation, but not in an item
      // object.
      if (isset($selected_label->action)) {
        //FIXME we are returning a label here, not an item; so, is it ok to have an action on label?
        //  unset($selected_label->action);
      }
      $selected_label->ensure();
      $this->selected_label->label = $selected_label;
    }
    else {
      $this->selected_label->label = FALSE;
    }

    // Now that we've got the real label, we can get rid of the retrieval
    // recipe.
    if (isset($this->selected_label->{$this->selected_label->get_from})) {
      unset($this->selected_label->{$this->selected_label->get_from});
    }
    unset($this->selected_label->get_from);

    return $this->selected_label->label;
  }

  /**
   * Check if the @p $path_regexp applies to the path of the given @p
   * $item.
@@ -442,11 +361,6 @@ abstract class VersioncontrolItem extends VersioncontrolEntity {
    );
    $parent_item = $this->getBackend()->buildEntity('item', $build_data);

    $parent_item->selected_label = new stdClass();
    $parent_item->selected_label->get_from = 'other_item';
    $parent_item->selected_label->other_item = &$this;
    $parent_item->selected_label->other_item_tags = array('same_revision');

    return $parent_item;
  }

@@ -579,52 +493,4 @@ abstract class VersioncontrolItem extends VersioncontrolEntity {
  public function formatRevisionIdentifier($format = 'full') {
    return $this->getBackend()->formatRevisionIdentifier($this->revision, $format);
  }

  /**
   * Retrieve a valid label (tag or branch) for a new @p $target_item
   * that is (hopefully) similar or related to that of the given @p
   * $other_item which already has a selected label assigned. If the
   * backend cannot find a related label, return any valid label. The
   * result of this function will be used for the selected label property
   * of each item, which is necessary to preserve the item state
   * throughout navigational API functions.
   *
   * @param $other_item
   *   The item revision that the selected label should be derived from.
   *   For example, if @p $other_item in a CVS repository is at revision
   *   '1.5.2.1' which is on the 'DRUPAL-6--1' branch, and the @p
   *   $target_item is at revision '1.5' (its predecessor) which is
   *   present on both the 'DRUPAL-6--1' and 'HEAD' branches, then this
   *   function should return a label array for the 'DRUPAL-6--1' branch.
   * @param $other_item_tags
   *   An array with a simple list of strings that describe properties of
   *   the @p $other_item, in relation to the @p $target_item. You can
   *   use those in order to make assumptions so that the selected label
   *   can be retrieved more accurately or with better performance.
   *   Version Control API passes a list that may contain zero or more of
   *   the following tags:
   *
   *   - 'source_item': The @p $other_item is a predecessor of the @p
   *   $target_item - same entity, but in an earlier revision and
   *   potentially with a different path, too (only if the backend
   *   supports item moves).
   *   - 'successor_item': The @p $other_item is a successor of the @p
   *   $target_item - same entity, but in a later revision and
   *   potentially with a different path, too (only if the backend
   *   supports item moves).
   *   - 'same_revision': The @p $other_item is at the same (global)
   *   revision as the @p $target_item. Specifically meant for backends
   *   whose version control systems don't support atomic commits.
   *
   * @return
   *   NULL if the given item does not belong to any label or if an
   *   appropriate label cannot be retrieved. Otherwise a
   *   VersioncontrolLabel object is returned.
   *   In case the label array also contains the 'label_id' element
   *   (which happens when it's copied from the $operation->labels
   *   array) there will be a small performance improvement as the label
   *   doesn't need to be compared to and loaded from the database
   *   anymore.
   */
  public abstract function getSelectedLabelFromItem(&$other_item, $other_item_tags = array());
}
+0 −22
Changes for includes/VersioncontrolOperation.php: 0 added lines, 22 removed lines.
Original line number Diff line number Diff line
@@ -326,26 +326,4 @@ abstract class VersioncontrolOperation extends VersioncontrolEntity {
  public function formatRevisionIdentifier($format = 'full') {
    return $this->getBackend()->formatRevisionIdentifier($this->revision, $format);
  }

  /**
   * Retrieve the tag or branch that applied to that item during the
   * given operation. The result of this function will be used for the
   * selected label property of the item, which is necessary to preserve
   * the item state throughout navigational API functions.
   *
   * @param $item
   *   The item revision for which the label should be retrieved.
   *
   * @return
   *   NULL if the given item does not belong to any label or if the
   *   appropriate label cannot be retrieved. Otherwise a
   *   VersioncontrolLabel array is returned
   *
   *   In case the label array also contains the 'label_id' element
   *   (which happens when it's copied from the $operation->labels
   *   array) there will be a small performance improvement as the label
   *   doesn't need to be compared to and loaded from the database
   *   anymore.
   */
  public abstract function getSelectedLabel($item);
}
+9 −3
Changes for includes/interfaces.inc: 9 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -198,6 +198,8 @@ interface VersioncontrolWebviewerUrlHandlerInterface {
   *
   * @param $item
   *   The item whose log view URL should be retrieved.
   * @param $current_label
   *   The current label being shown, if applicable.
   *
   * @return
   *   The item log view URL corresponding to the given arguments.
@@ -205,7 +207,7 @@ interface VersioncontrolWebviewerUrlHandlerInterface {
   *   (and if not even Commit Log is enabled), or if the item cannot be viewed
   *   for any reason.
   */
  public function getItemLogViewUrl($item);
  public function getItemLogViewUrl($item, $current_label = NULL);

  /**
   * Retrieve the URL of the repository viewer that displays the contents of the
@@ -213,13 +215,15 @@ interface VersioncontrolWebviewerUrlHandlerInterface {
   *
   * @param $item
   *   The item whose view URL should be retrieved.
   * @param $current_label
   *   The current label being shown, if applicable.
   *
   * @return
   *   The item view URL corresponding to the given arguments.
   *   An empty string is returned if no item view URL has been defined,
   *   or if the item cannot be viewed for any reason.
   */
  public function getItemViewUrl($item);
  public function getItemViewUrl($item, $current_label = NULL);

  /**
   * Retrieve the URL of the repository viewer that displays the diff between
@@ -229,13 +233,15 @@ interface VersioncontrolWebviewerUrlHandlerInterface {
   *   The new version of the file that should be diffed.
   * @param $file_item_old
   *   The old version of the file that should be diffed.
   * @param $current_label
   *   The current label being shown, if applicable.
   *
   * @return
   *   The diff URL corresponding to the given arguments.
   *   An empty string is returned if no diff URL has been defined,
   *   or if the two items cannot be diffed for any reason.
   */
  public function getDiffUrl($file_item_new, $file_item_old);
  public function getDiffUrl($file_item_new, $file_item_old, $current_label = NULL);
}

/**
+20 −18
Changes for includes/plugins/webviewer_url_handlers/VersioncontrolRepositoryUrlHandler.inc: 20 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHa
   *
   * @param $item
   *   The item whose log view URL should be retrieved.
   * @param $current_label
   *   The current label being shown, if appliable.
   *
   * @return
   *   The item log view URL corresponding to the given arguments.
@@ -94,18 +96,16 @@ class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHa
   *   (and if not even Commit Log is enabled), or if the item cannot be viewed
   *   for any reason.
   */
  public function getItemLogViewUrl($item) {
    $label = $item->getSelectedLabel();

    if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $current_branch = $label->name;
  public function getItemLogViewUrl($item, $current_label = NULL) {
    if (isset($current_label->type) && $current_label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $label_name = $current_label->name;
    }

    $placeholders = array(
      '%repo_name' => $this->repository->name,
      '%path'     => $item->path,
      '%revision' => $item->revision,
      '%branch'   => isset($current_branch) ? $current_branch : '',
      '%branch'   => isset($label_name) ? $label_name : '',
    );

    if ($item->isFile()) {
@@ -122,18 +122,19 @@ class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHa
   *
   * @param $item
   *   The item whose view URL should be retrieved.
   * @param $current_label
   *   The current label being shown, if appliable.
   *
   * @return
   *   The item view URL corresponding to the given arguments.
   *   An empty string is returned if no item view URL has been defined,
   *   or if the item cannot be viewed for any reason.
   */
  public function getItemViewUrl($item) {
    $label = $item->getSelectedLabel();

    if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $current_branch = $label->name;
  public function getItemViewUrl($item, $current_label = NULL) {
    if (isset($current_label->type) && $current_label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $label_name = $current_label->name;
    }

    $view_url = $item->isFile()
      ? $this->getTemplateUrl('file_view')
      : $this->getTemplateUrl('directory_view');
@@ -142,7 +143,7 @@ class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHa
      '%repo_name' => $this->repository->name,
      '%path'     => $item->path,
      '%revision' => $item->revision,
      '%branch'   => isset($current_branch) ? $current_branch : '',
      '%branch'   => isset($label_name) ? $label_name : '',
    ));
  }

@@ -154,25 +155,26 @@ class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHa
   *   The new version of the file that should be diffed.
   * @param $file_item_old
   *   The old version of the file that should be diffed.
   * @param $current_label
   *   The current label being shown, if appliable.
   *
   * @return
   *   The diff URL corresponding to the given arguments.
   *   An empty string is returned if no diff URL has been defined,
   *   or if the two items cannot be diffed for any reason.
   */
  public function getDiffUrl($file_item_new, $file_item_old) {
    $label = $file_item_new->getSelectedLabel();

    if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $current_branch = $label->name;
  public function getDiffUrl($file_item_new, $file_item_old, $current_label = NULL) {
    if (isset($current_label->type) && $current_label->type == VERSIONCONTROL_LABEL_BRANCH) {
      $label_name = $current_label->name;
    }

    return strtr($this->getTemplateUrl('diff'), array(
      '%repo_name' => $this->repository->name,
      '%path'         => $file_item_new->path,
      '%new_revision' => $file_item_new->revision,
      '%old_path'     => $file_item_old->path,
      '%old_revision' => $file_item_old->revision,
      '%branch'       => isset($current_branch) ? $current_branch : '',
      '%branch'       => isset($label_name) ? $label_name: '',
    ));
  }

+0 −25
Changes for tests/versioncontrol_test.inc: 0 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -45,14 +45,6 @@ class VersioncontrolTestRepository extends VersioncontrolRepository {
}

class VersioncontrolTestOperation extends VersioncontrolOperation {

  /**
   * Implementation of abstract method.
   */
  public function getSelectedLabel($target_item) {
    return $operation->labels[0];
  }

}

class VersioncontrolTestBranch extends VersioncontrolBranch {
@@ -64,23 +56,6 @@ class VersioncontrolTestTag extends VersioncontrolTag {
}

class VersioncontrolTestItem extends VersioncontrolItem {

  /**
   * Implementation of abstract method.
   * Now we do not test fecth from repo, so this method is empty. So,
   * when it's needed see fakevcs backend implementation for reference.
   */
  public function getSelectedLabelFromItem(&$other_item, $other_item_tags = array()) {
    $_repo = array(
      'name' => 'A test repo',
      'vcs'  => 'fakevcs',
      'root' => '/path/to/the/repo',
      'authorization_method' => 'versioncontrol_admin',
    );
    $repo = new VersioncontrolTestRepository(1, $_repo, FALSE);
    return new VersioncontrolBranch('HEAD', NULL, '1', $repo);
  }

}

class VersioncontrolTestEvent extends VersioncontrolEvent {
Loading