How to Limit Node Revisions in Drupal7
You can use the Node Revision Restrict module for this.


  The Node Revision Restrict module allows you to restrict revisions of node for each content type. This module has an admin interface to specify node revision threshold for each content type available. The possible settings include node type, the number of count provided on configuration form for each content type and more. Users with specific permissions can delete any unwanted revisions. Note that this module does not and cannot delete the current revisions of a node. 


You could either use the module, or incorporate some of its code. It is a short module. Most of the code relevant to your task can be found in the node_revision_restrict_node_presave function: 

/**
 * Implements of hook_presave().
 */
function node_revision_restrict_node_presave($node) {
  $node_type = $node-&gt;type;
  $nid = $node-&gt;nid;
  $node_data = db_query('SELECT * FROM {node} WHERE nid = :nid', array(':nid' =&gt; $nid));
  foreach ($node_data as $node) {
    $revision_data = node_revision_list($node);
    foreach ($revision_data as $revision) {
      $revision_ids[] = $revision-&gt;vid;
    }
    $count_to_restrict_set_value = variable_get('restrict_node_revision_number_for_' . $node_type);
    if (isset($count_to_restrict_set_value)) {
      $node_to_restrict = array_slice($revision_ids, $count_to_restrict_set_value, count($revision_ids));
      foreach ($node_to_restrict as $revision_id) {
        node_revision_delete($revision_id);
      }
    }
  }
}


In general, I prefer using a contributed module, if it provides the functionality needed, over maintaining my own code, because I won't have to worry as much about security updates, and other debugging issues, down the road.