annotate cmdline/org/tmatesoft/hg/console/Commit.java @ 598:d29d9dc6c128

Utilize the fact nodeids are very different and are read anyway to speed up reverse lookup
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 03 May 2013 15:19:18 +0200
parents b12cc3d64a35
children
rev   line source
592
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.console;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.util.Collections;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.tmatesoft.hg.core.HgCommitCommand;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.core.HgRepoFacade;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.util.Outcome;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 /**
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 *
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 * @author Artem Tikhomirov
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * @author TMate Software Ltd.
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 */
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 public class Commit {
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 public static void main(String[] args) throws Exception {
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet());
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 HgRepoFacade repo = new HgRepoFacade();
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 if (!repo.init(cmdLineOpts.findRepository())) {
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 System.err.printf("Can't find repository in: %s\n", repo.getRepository().getLocation());
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 return;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 }
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 String message = cmdLineOpts.getSingle("-m", "--message");
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 if (message == null) {
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 System.err.println("Need a commit message");
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 return;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 HgCommitCommand cmd = repo.createCommitCommand();
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 cmd.message(message);
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 Outcome o = cmd.execute();
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 if (!o.isOk()) {
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 System.err.println(o.getMessage());
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 return;
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 System.out.printf("New changeset: %s\n", cmd.getCommittedRevision().shortNotation());
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
b12cc3d64a35 Command-line sample for commit command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }