Beispiel #1
0
  public RepositoryTagMap(
      AbstractRepository repository,
      RepositoryTagMap parent,
      Map<String, RepositoryTagEntry> tagMap)
      throws IOException {
    _tagMap = Collections.unmodifiableMap(tagMap);

    long now = Alarm.getCurrentTime();

    if (parent.getSequence() < now) _sequence = now;
    else _sequence = parent.getSequence() + 1;

    TempStream os = new TempStream();
    WriteStream out = new WriteStream(os);

    writeTagMap(out);
    out.close();

    String tagHash;

    InputStream is = os.getInputStream();

    try {
      tagHash = repository.addBlob(is);
    } finally {
      is.close();
    }

    _tree = new GitTree();

    _tree.addBlob("tags", 0775, tagHash);

    for (String key : tagMap.keySet()) {
      RepositoryTagEntry entry = tagMap.get(key);

      String sha1 = entry.getTagEntryHash();
      String root = entry.getRoot();

      _tree.addBlob(sha1, 0644, sha1);

      GitType type = repository.getType(root);

      if (type == GitType.BLOB) _tree.addBlob(root, 0644, root);
      else if (type == GitType.TREE) _tree.addDir(root, root);
      else throw new IllegalStateException(L.l("'{0}' has an unknown type {1}", root, type));
    }

    String treeHash = repository.addTree(_tree);

    _commit = new GitCommit();
    _commit.setTree(treeHash);
    _commit.put("sequence", String.valueOf(_sequence));

    _commitHash = repository.addCommit(_commit);
  }
  /** Creates a write stream to a CharBuffer. This is the standard way to write to a string. */
  public static WriteStream openWrite(CharBuffer cb) {
    com.caucho.vfs.StringWriter s = new com.caucho.vfs.StringWriter(cb);
    WriteStream os = new WriteStream(s);

    try {
      os.setEncoding("utf-8");
    } catch (Exception e) {
    }

    return os;
  }
  public static WriteStream openWrite(Writer writer) {
    ReaderWriterStream s = new ReaderWriterStream(null, writer);
    WriteStream os = new WriteStream(s);

    try {
      os.setEncoding("utf-8");
    } catch (Exception e) {
    }

    return os;
  }
Beispiel #4
0
 private void writeTagMap(WriteStream out) throws IOException {
   for (Map.Entry<String, RepositoryTagEntry> entry : _tagMap.entrySet()) {
     out.println(entry.getKey());
     out.println(entry.getValue().getTagEntryHash());
   }
 }
Beispiel #5
0
  /** Close the connection. */
  public void close() throws IOException {
    if (_isKeepalive) {
      // If recycling, read any unread data
      if (!_didGet) getConnInput();

      if (!_isRequestDone) {
        if (_tempBuffer == null) _tempBuffer = new byte[256];

        try {
          while (read(_tempBuffer, 0, _tempBuffer.length) > 0) {}
        } catch (IOException e) {
          _isKeepalive = false;
        }
      }
    }

    if (_isKeepalive) {
      HttpStream oldSaved;

      long now;

      now = CurrentTime.getCurrentTime();

      synchronized (LOCK) {
        oldSaved = _savedStream;
        _savedStream = this;
        _saveTime = now;
      }

      if (oldSaved != null && oldSaved != this) {
        oldSaved._isKeepalive = false;
        oldSaved.close();
      }

      return;
    }

    try {
      try {
        if (_ws != null) _ws.close();
      } catch (Throwable e) {
      }
      _ws = null;

      try {
        if (_rs != null) _rs.close();
      } catch (Throwable e) {
      }
      _rs = null;

      try {
        if (_os != null) _os.close();
      } catch (Throwable e) {
      }
      _os = null;

      try {
        if (_is != null) _is.close();
      } catch (Throwable e) {
      }
      _is = null;
    } finally {
      if (_s != null) _s.close();
      _s = null;
    }
  }
Beispiel #6
0
  /** Send the request to the server, wait for the response and parse the headers. */
  private void getConnInputImpl() throws IOException {
    if (_didGet) return;

    _didGet = true;

    if (log.isLoggable(Level.FINER)) log.finer(this + " connect " + _method + " post=" + _isPost);

    if (_method != null) {
      _ws.print(_method);
      _ws.print(' ');
    } else if (_isPost) _ws.print("POST ");
    else if (_isHead) _ws.print("HEAD ");
    else _ws.print("GET ");

    // Not splitting query? Also fullpath?
    _ws.print(_path.getPath());

    if (_path.getQuery() != null) {
      _ws.print("?");
      _ws.print(_path.getQuery());
    }

    if (_isHttp11) {
      _ws.print(" HTTP/1.1\r\n");
      Object host = getAttribute("host");
      _ws.print("Host: ");
      if (host != null) {
        _ws.print(host);
      } else if (_virtualHost != null) _ws.print(_virtualHost);
      else {
        _ws.print(_path.getHost());
        if (_path.getPort() != 80) {
          _ws.print(":");
          _ws.print(String.valueOf(_path.getPort()));
        }
      }
    } else _ws.print(" HTTP/1.0\r\n");

    _ws.print("\r\n");

    Object userAgent = getAttribute("User-Agent");
    if (userAgent == null) _ws.print("User-Agent: Mozilla/4.0 (compatible; Resin 1.0; JDK)\r\n");
    else _ws.print("User-Agent: " + userAgent + "\r\n");
    Iterator iter = getAttributeNames();
    while (iter.hasNext()) {
      String name = (String) iter.next();
      if (_reserved.get(name.toLowerCase(Locale.ENGLISH)) == null) {
        Object value = getAttribute(name);
        if (value instanceof String[]) {
          String[] values = (String[]) value;
          for (int i = 0; i < values.length; i++) {
            _ws.print(name + ": " + values[i] + "\r\n");
          }
        } else _ws.print(name + ": " + value + "\r\n");
      }
    }
    if (!_isKeepalive) _ws.print("Connection: close\r\n");

    if (_isPost) {
      int writeLength = 0;
      if (_tempStream != null) writeLength = _tempStream.getLength();

      Object contentLength = getAttribute("Content-Length");

      if (contentLength != null) {
        long len = 0;

        if (contentLength instanceof Number) len = ((Number) contentLength).longValue();
        else {
          String lenStr = contentLength.toString().trim();

          for (int i = 0; i < lenStr.length(); i++) {
            char ch = lenStr.charAt(i);

            if ('0' <= ch && ch <= '9') len = len * 10 + ch - '0';
            else break;
          }
        }

        // server/1963
        if (len != writeLength) {
          throw new IOException(
              L.l("Content-Length={0} but only received {1}", len, "" + writeLength));
        }
      }

      _ws.print("Content-Length: " + writeLength);
      _ws.print("\r\n");
    }
    _ws.print("\r\n");

    if (_isPost) {
      MemoryStream tempStream = _tempStream;
      _tempStream = null;
      if (tempStream != null) {
        tempStream.writeToStream(_ws);
        tempStream.destroy();
      }
    }

    _attributes.clear();

    parseHeaders();

    if (_isHead) _isRequestDone = true;
  }