Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Package Functions | Static Package Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
BlameTable Class Reference
Collaboration diagram for BlameTable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

String getBlame (String bonsaiPath, int line)

Static Package Functions

static String quoteTags (StringBuffer buf)
 Simply replaces instances of '<' with "&LT;" and '>' with "&GT;".

Static Package Attributes

static final String CVSBLAME_CGI = "http://bonsai.mozilla.org/cvsblame.cgi?data=1&file="

Private Member Functions

Blame assignBlame (String bonsaiPath)
 Contact bonsai, and get a blame table for each line in a file.

Static Private Member Functions

static int parseInt (String str)

Private Attributes

Hashtable blameTable = new Hashtable()

Detailed Description

Definition at line 51 of file BlameTable.java.


Member Function Documentation

Blame BlameTable.assignBlame ( String  bonsaiPath) [inline, private]

Contact bonsai, and get a blame table for each line in a file.

This information can be compressed, in all likelyhood.

Definition at line 108 of file BlameTable.java.

                                                    {
              try {
                     Vector vec = new Vector();
                     URL url = new URL(CVSBLAME_CGI + bonsaiPath);
                     BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                     
                     // read revision for each line of the file. this is really slow. I asked slam to
                     // use buffered output, to speed this up.
                     for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                            if (line.charAt(0) == 'R')
                                   break;
                            // decompress "revision:count" to simplify getBlame() above.
                            int colonIndex = line.indexOf(':');
                            String revision = line.substring(0, colonIndex);
                            int count = parseInt(line.substring(colonIndex + 1));
                            while (count-- > 0)
                                   vec.addElement(revision);
                     }
                     String[] lines = new String[vec.size()];
                     vec.copyInto(lines);
                     vec.removeAllElements();

                     // read revision records, which are of the form "rev|date|who|comment" where comment can span multiple lines,
                     // and each record is terminated by a "." on its own line.
                     Hashtable info = new Hashtable();
                     String revision = null;
                     StringBuffer buffer = new StringBuffer();
                     for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                            // we're in one of two states, either we've seen a line starting with a revision,
                            // and we're waiting for the final ending line, or we're starting a new revision
                            // record.
                            if (revision != null) {
                                   if (line.equals(".")) {
                                          // end of current revision record.
                                          info.put(revision, quoteTags(buffer));
                                          revision = null;
                                          buffer.setLength(0);
                                   } else {
                                          // continuation of a comment
                                          buffer.append(" " + line);
                                   }
                            } else {
                                   int orIndex = line.indexOf('|');
                                   if (orIndex >= 0) {
                                          // new revision info record.
                                          revision = line.substring(0, orIndex);
                                          buffer.append(line);
                                   }
                            }
                     }
                     reader.close();
                     
                     return new Blame(lines, info);
              } catch (Exception e) {
                     System.err.println("[error assigning blame for: " + bonsaiPath + "]"); 
                     e.printStackTrace(System.err);
              }
              return null;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

String BlameTable.getBlame ( String  bonsaiPath,
int  line 
) [inline]

Definition at line 54 of file BlameTable.java.

                                                           {
              Blame blame = (Blame) blameTable.get(bonsaiPath);
              if (blame == null) {
                     blame = assignBlame(bonsaiPath);
                     blameTable.put(bonsaiPath, blame);
              }
              if (blame != null) {
                     String[] lines = blame.lines;
                     if (line > 0 && lines.length > 0 && line <= lines.length)
                            return (String) blame.info.get(lines[line - 1]);
              }
              return "error";
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static int BlameTable.parseInt ( String  str) [inline, static, private]

Definition at line 70 of file BlameTable.java.

                                               {
              int value = 0;
              try {
                     value = Integer.parseInt(str);
              } catch (NumberFormatException nfe) {
              }
              return value;
       }

Here is the caller graph for this function:

static String BlameTable.quoteTags ( StringBuffer  buf) [inline, static, package]

Simply replaces instances of '<' with "&LT;" and '>' with "&GT;".

Definition at line 82 of file BlameTable.java.

                                                 {
              int length = buf.length();
              for (int i = 0; i < length; ++i) {
                     char ch = buf.charAt(i);
                     switch (ch) {
                     case '<':
                            buf.setCharAt(i, '&');
                            buf.insert(i + 1, "LT;");
                            i += 4;
                            length += 3;
                            break;
                     case '>':
                            buf.setCharAt(i, '&');
                            buf.insert(i + 1, "GT;");
                            i += 4;
                            length += 3;
                            break;
                     }
              }
              return buf.toString();
       }

Here is the caller graph for this function:


Member Data Documentation

Hashtable BlameTable.blameTable = new Hashtable() [private]

Definition at line 52 of file BlameTable.java.

final String BlameTable.CVSBLAME_CGI = "http://bonsai.mozilla.org/cvsblame.cgi?data=1&file=" [static, package]

Definition at line 68 of file BlameTable.java.


The documentation for this class was generated from the following file: