comparison src/com/tmate/hgkit/fs/RepositoryLookup.java @ 4:aa1912c70b36

Fix offset issue for inline revlogs. Commandline processing.
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 Dec 2010 04:20:52 +0100
parents 08db726a0fb7
children e34f90b9ded1
comparison
equal deleted inserted replaced
3:24bb4f365164 4:aa1912c70b36
2 * Copyright (c) 2010 Artem Tikhomirov 2 * Copyright (c) 2010 Artem Tikhomirov
3 */ 3 */
4 package com.tmate.hgkit.fs; 4 package com.tmate.hgkit.fs;
5 5
6 import java.io.File; 6 import java.io.File;
7 import java.util.ArrayList;
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.Iterator;
11 import java.util.LinkedList;
12 import java.util.List;
7 13
8 import com.tmate.hgkit.ll.HgRepository; 14 import com.tmate.hgkit.ll.HgRepository;
9 import com.tmate.hgkit.ll.LocalHgRepo; 15 import com.tmate.hgkit.ll.LocalHgRepo;
10 16
11 /** 17 /**
12 * @author artem 18 * @author artem
13 */ 19 */
14 public class RepositoryLookup { 20 public class RepositoryLookup {
15 21
22 public HgRepository detect(Options opts) throws Exception {
23 if (opts.repoLocation != null) {
24 return detect(opts.repoLocation);
25 }
26 return detectFromWorkingDir();
27 }
28
16 public HgRepository detect(String[] commandLineArgs) throws Exception { 29 public HgRepository detect(String[] commandLineArgs) throws Exception {
17 if (commandLineArgs.length == 0) { 30 return detect(Options.parse(commandLineArgs));
18 return detectFromWorkingDir();
19 }
20 return detect(commandLineArgs[0]);
21 } 31 }
22 32
23 public HgRepository detectFromWorkingDir() throws Exception { 33 public HgRepository detectFromWorkingDir() throws Exception {
24 return detect(System.getProperty("user.dir")); 34 return detect(System.getProperty("user.dir"));
25 } 35 }
39 if (repository == null) { 49 if (repository == null) {
40 return new LocalHgRepo(location); 50 return new LocalHgRepo(location);
41 } 51 }
42 return new LocalHgRepo(repository); 52 return new LocalHgRepo(repository);
43 } 53 }
54
55 public static class Options {
56
57 public String repoLocation;
58 public List<String> files;
59
60 public static Options parse(String[] commandLineArgs) {
61 Options rv = new Options();
62 List<String> args = Arrays.asList(commandLineArgs);
63 LinkedList<String> files = new LinkedList<String>();
64 for (Iterator<String> it = args.iterator(); it.hasNext(); ) {
65 String arg = it.next();
66 if (arg.charAt(0) == '-') {
67 // option
68 if (arg.length() == 1) {
69 throw new IllegalArgumentException("Bad option: -");
70 }
71 switch ((int) arg.charAt(1)) {
72 case (int) 'R' : {
73 if (! it.hasNext()) {
74 throw new IllegalArgumentException("Need repo location");
75 }
76 rv.repoLocation = it.next();
77 break;
78 }
79 }
80 } else {
81 // filename
82 files.add(arg);
83 }
84 }
85 if (!files.isEmpty()) {
86 rv.files = new ArrayList<String>(files);
87 } else {
88 rv.files = Collections.emptyList();
89 }
90 return rv;
91 }
92 }
44 } 93 }