/[drupal]/contributions/modules/gitbrowser/gb.inc
ViewVC logotype

Diff of /contributions/modules/gitbrowser/gb.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri May 1 00:13:13 2009 UTC revision 1.2, Fri May 1 01:37:57 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: gb.inc,v 1.1 2009/05/01 00:13:13 gordon Exp $
3  /**  /**
4   * @file   * @file
5   * Provide all git integration   * Provide all git integration
# Line 46  function gb_shortlog($repos, $head = 'HE Line 46  function gb_shortlog($repos, $head = 'HE
46   *   *
47   */   */
48  function gb_get_short_log($repos, $start = 'HEAD', $count = 16) {  function gb_get_short_log($repos, $start = 'HEAD', $count = 16) {
49      drupal_add_css(drupal_get_path('module', 'gb') .'/gb.css');
50    
51    $revs = gb_rev_list($repos, $count, $start);    $revs = gb_rev_list($repos, $count, $start);
52    $rows = array();    $rows = array();
53    foreach ($revs as $rev) {    foreach ($revs as $rev) {
54      $info = gb_get_commit_info($repos, $rev);      $info = gb_get_commit_info($repos, $rev);
55    
56      $rows[] = array(      $rows[] = array(
57        format_date($info['author'][0]['date'], 'short'),        format_date($info['author'][0]['date'], 'short'),
58        $info['author'][0]['name'],        $info['author'][0]['name'],
59        $info['description'][0],        $info['description'][0] .implode('', array_map('_gb_format_refs', $info['refs'])),
60      );      );
61    }    }
62    
# Line 63  function gb_get_short_log($repos, $start Line 65  function gb_get_short_log($repos, $start
65    return $output;    return $output;
66  }  }
67    
68    function _gb_format_refs($a) {
69      return '<span class="'. $a['type'] .'">'. $a['name'] .'</span>';
70    }
71    
72  function gb_get_heads($repos) {  function gb_get_heads($repos) {
73    $return = gb_git($repos, 'show-ref --heads');    return gb_show_ref($repos, '--heads');
74    }
75    $heads = array();  
76    function gb_get_tags($repos) {
77    foreach ($return as $line) {    return gb_show_ref($repos, '--tags');
     if (preg_match('/^([0-9a-f]{40}) (.*)$/i', $line, $match)) {  
       $heads[] = array(  
         'hash' => $match[1],  
         'fullname' => $match[2],  
         'name' => basename($match[2]),  
       );  
     }  
   }  
   
   return $heads;  
78  }  }
 // ------------------------------------------------------------------------  
79    
80  /**  /**
81   * Get commit info   * Get commit info
# Line 124  function gb_get_commit_info($repos, $has Line 119  function gb_get_commit_info($repos, $has
119        $info['hash'] = $line;        $info['hash'] = $line;
120      }      }
121    }    }
122    
123      $info['refs'] = gb_show_ref($repos, '', $info['hash']);
124    
125    return $info;    return $info;
126  }  }
127    
128    function gb_show_ref($repos, $options, $hash = NULL) {
129      $return = gb_git($repos, 'show-ref '. $options);
130    
131      $refs = array();
132    
133      foreach ($return as $line) {
134        if (preg_match('/^([0-9a-f]{40}) refs\/(.*?)\/(.*)$/i', $line, $match)) {
135          if (!isset($hash) || $hash == $match[1]) {
136            $refs[] = array(
137              'hash' => $match[1],
138              'type' => $match[2],
139              'fullname' => 'refs/'. $match[2] .'/'. $match[3],
140              'name' => $match[3],
141            );
142          }
143        }
144      }
145    
146      return $refs;
147    }
148    
149  /**  /**
150   * Get rev list   * Get rev list
151   */   */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2