Example usage for org.eclipse.jgit.lib Constants encode

List of usage examples for org.eclipse.jgit.lib Constants encode

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants encode.

Prototype

public static byte[] encode(String str) 

Source Link

Document

Convert a string to a byte array in the standard character encoding.

Usage

From source file:com.google.gerrit.server.git.LocalDiskRepositoryManager.java

License:Apache License

@Override
public void setProjectDescription(final Project.NameKey name, final String description) {
    // Update git's description file, in case gitweb is being used
    ////from  w  w w.  j ava 2 s  .c om
    try (Repository e = openRepository(name)) {
        final String old = getProjectDescription(e);
        if ((old == null && description == null) || (old != null && old.equals(description))) {
            return;
        }

        final LockFile f = new LockFile(new File(e.getDirectory(), "description"), FS.DETECTED);
        if (f.lock()) {
            String d = description;
            if (d != null) {
                d = d.trim();
                if (d.length() > 0) {
                    d += "\n";
                }
            } else {
                d = "";
            }
            f.write(Constants.encode(d));
            f.commit();
        }
    } catch (IOException e) {
        log.error("Cannot update description for " + name, e);
    }
}

From source file:com.google.gerrit.server.git.MultiProgressMonitor.java

License:Apache License

private void send(StringBuilder s) {
    if (write) {/*from  www.  j av  a  2s . c  om*/
        try {
            out.write(Constants.encode(s.toString()));
            out.flush();
        } catch (IOException e) {
            write = false;
        }
    }
}

From source file:com.google.gerrit.server.git.SubmoduleOpTest.java

License:Apache License

/**
 * It creates and adds a regular file to git index of a repository.
 *
 * @param fileName The file name./*from   w  w  w. j a  va  2s.  com*/
 * @param content File content.
 * @param repository The Repository instance.
 * @throws IOException If an I/O exception occurs.
 */
private void addRegularFileToIndex(final String fileName, final String content, final Repository repository)
        throws IOException {
    final ObjectInserter oi = repository.newObjectInserter();
    AnyObjectId objectId = oi.insert(Constants.OBJ_BLOB, Constants.encode(content));
    oi.flush();
    addEntryToIndex(fileName, FileMode.REGULAR_FILE, objectId, repository);
}

From source file:com.google.gerrit.server.git.VersionedMetaData.java

License:Apache License

protected void saveUTF8(String fileName, String text) throws IOException {
    saveFile(fileName, text != null ? Constants.encode(text) : null);
}

From source file:com.google.gerrit.server.tools.hooks.CommitMsgHookTest.java

License:Apache License

private DirCacheEntry file(final String name) throws IOException {
    try (ObjectInserter oi = repository.newObjectInserter()) {
        final DirCacheEntry e = new DirCacheEntry(name);
        e.setFileMode(FileMode.REGULAR_FILE);
        e.setObjectId(oi.insert(Constants.OBJ_BLOB, Constants.encode(name)));
        oi.flush();/*from   w w w .  j  av  a2  s  . c o m*/
        return e;
    }
}

From source file:com.googlesource.gerrit.plugins.secureconfig.SecureConfigStore.java

License:Apache License

private void saveSecure(final FileBasedConfig sec) throws IOException {
    if (FileUtil.modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }//from ww w. j av  a  2 s  .c  o  m
        try {
            FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}

From source file:org.eclipse.tycho.extras.buildtimestamp.jgit.PathFilter.java

License:Open Source License

public PathFilter(String basedir, String filters) {
    this.basedir = Constants.encode(basedir);

    if (filters != null) {
        StringTokenizer st = new StringTokenizer(filters, "\n\r\f", false);
        List<IgnoreRule> rules = new ArrayList<IgnoreRule>();
        while (st.hasMoreTokens()) {
            rules.add(new IgnoreRule(st.nextToken().trim()));
        }//w  ww .j  a v  a  2 s .c om
        this.rules = Collections.unmodifiableList(rules);
    } else {
        this.rules = null;
    }
}

From source file:org.gitective.redis.RedisRefTable.java

License:Open Source License

public boolean compareAndPut(RefKey refKey, RefData oldData, RefData newData)
        throws DhtException, TimeoutException {
    Jedis jedis = acquire();//from w w  w . j av a2 s  . c  o m
    try {
        byte[] ref = Constants.encode(refKey.getName());
        byte[] key = REFS.append(refKey.getRepositoryKey().asBytes());
        boolean same = equal(ref, key, oldData, jedis);
        if (same)
            jedis.hset(key, ref, newData.toByteArray());
        return same;
    } finally {
        release(jedis);
    }
}

From source file:org.gitective.redis.RedisRefTable.java

License:Open Source License

public boolean compareAndRemove(RefKey refKey, RefData oldData) throws DhtException, TimeoutException {
    Jedis jedis = acquire();/*from w ww  . j  a  va2  s . c om*/
    try {
        byte[] ref = Constants.encode(refKey.getName());
        byte[] key = REFS.append(refKey.getRepositoryKey().asBytes());
        boolean same = equal(ref, key, oldData, jedis);
        if (same)
            jedis.hdel(key, ref);
        return same;
    } finally {
        release(jedis);
    }
}

From source file:org.kuali.student.git.model.branch.utils.GitBranchUtils.java

License:Educational Community License

/**
 * Compute the objectid of the branch name given.
 * /*from   w ww. j ava  2 s.com*/
 * @param branchName
 * @return
 */
public static ObjectId getBranchNameObjectId(String branchName) {

    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");

        byte[] branchNameBytes = Constants.encode(branchName);

        md.update(branchNameBytes);

        return ObjectId.fromRaw(md.digest());
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("failed to get SHA-1 digest Message Digest.", e);
    }
}