Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 652:cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 02 Jul 2013 23:21:16 +0200 |
| parents | 6e98d34eaca8 |
| children | 545b1d4cc11d |
comparison
equal
deleted
inserted
replaced
| 651:6e98d34eaca8 | 652:cd77bf51b562 |
|---|---|
| 467 rv.add(new Pair<String, Nodeid>(bm, n)); | 467 rv.add(new Pair<String, Nodeid>(bm, n)); |
| 468 } | 468 } |
| 469 return new Bookmarks(rv); | 469 return new Bookmarks(rv); |
| 470 } | 470 } |
| 471 | 471 |
| 472 public void updateBookmark(String name, Nodeid oldRev, Nodeid newRev) throws HgRemoteConnectionException, HgRuntimeException { | 472 public Outcome updateBookmark(String name, Nodeid oldRev, Nodeid newRev) throws HgRemoteConnectionException, HgRuntimeException { |
| 473 final String namespace = "bookmarks"; | 473 initCapabilities(); |
| 474 HttpURLConnection c = null; | 474 if (!remoteCapabilities.contains("pushkey")) { |
| 475 try { | 475 return new Outcome(Failure, "Server doesn't support pushkey protocol"); |
| 476 URL u = new URL(url, String.format("%s?cmd=pushkey&namespace=%s&key=%s&old=%s&new=%s",url.getPath(), namespace, name, oldRev.toString(), newRev.toString())); | 476 } |
| 477 c = setupConnection(u.openConnection()); | 477 if (pushkey("Update remote bookmark", "bookmarks", name, oldRev.toString(), newRev.toString())) { |
| 478 c.connect(); | 478 return new Outcome(Success, String.format("Bookmark %s updated to %s", name, newRev.shortNotation())); |
| 479 if (debug) { | 479 } |
| 480 dumpResponseHeader(u, c); | 480 return new Outcome(Failure, String.format("Bookmark update (%s: %s -> %s) failed", name, oldRev.shortNotation(), newRev.shortNotation())); |
| 481 } | |
| 482 checkResponseOk(c, "Update remote bookmark", "pushkey"); | |
| 483 } catch (MalformedURLException ex) { | |
| 484 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("pushkey").setServerInfo(getLocation()); | |
| 485 } catch (IOException ex) { | |
| 486 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("pushkey").setServerInfo(getLocation()); | |
| 487 } finally { | |
| 488 if (c != null) { | |
| 489 c.disconnect(); | |
| 490 } | |
| 491 } | |
| 492 } | 481 } |
| 493 | 482 |
| 494 public Phases getPhases() throws HgRemoteConnectionException, HgRuntimeException { | 483 public Phases getPhases() throws HgRemoteConnectionException, HgRuntimeException { |
| 495 initCapabilities(); | 484 initCapabilities(); |
| 496 if (!remoteCapabilities.contains("pushkey")) { | 485 if (!remoteCapabilities.contains("pushkey")) { |
| 520 public Outcome updatePhase(HgPhase from, HgPhase to, Nodeid n) throws HgRemoteConnectionException, HgRuntimeException { | 509 public Outcome updatePhase(HgPhase from, HgPhase to, Nodeid n) throws HgRemoteConnectionException, HgRuntimeException { |
| 521 initCapabilities(); | 510 initCapabilities(); |
| 522 if (!remoteCapabilities.contains("pushkey")) { | 511 if (!remoteCapabilities.contains("pushkey")) { |
| 523 return new Outcome(Failure, "Server doesn't support pushkey protocol"); | 512 return new Outcome(Failure, "Server doesn't support pushkey protocol"); |
| 524 } | 513 } |
| 525 if (pushkey("phases", n.toString(), String.valueOf(from.mercurialOrdinal()), String.valueOf(to.mercurialOrdinal()))) { | 514 if (pushkey("Update remote phases", "phases", n.toString(), String.valueOf(from.mercurialOrdinal()), String.valueOf(to.mercurialOrdinal()))) { |
| 526 return new Outcome(Success, String.format("Phase of %s updated to %s", n.shortNotation(), to.name())); | 515 return new Outcome(Success, String.format("Phase of %s updated to %s", n.shortNotation(), to.name())); |
| 527 } | 516 } |
| 528 return new Outcome(Failure, String.format("Phase update (%s: %s -> %s) failed", n.shortNotation(), from.name(), to.name())); | 517 return new Outcome(Failure, String.format("Phase update (%s: %s -> %s) failed", n.shortNotation(), from.name(), to.name())); |
| 529 } | |
| 530 | |
| 531 | |
| 532 public static void main(String[] args) throws Exception { | |
| 533 final HgRemoteRepository r = new HgLookup().detectRemote("http://selenic.com/hg", null); | |
| 534 if (r.isInvalid()) { | |
| 535 return; | |
| 536 } | |
| 537 System.out.println(r.remoteCapabilities); | |
| 538 r.getPhases(); | |
| 539 final Iterable<Pair<String, Nodeid>> bm = r.getBookmarks(); | |
| 540 for (Pair<String, Nodeid> pair : bm) { | |
| 541 System.out.println(pair); | |
| 542 } | |
| 543 } | 518 } |
| 544 | 519 |
| 545 @Override | 520 @Override |
| 546 public String toString() { | 521 public String toString() { |
| 547 return getClass().getSimpleName() + '[' + getLocation() + ']'; | 522 return getClass().getSimpleName() + '[' + getLocation() + ']'; |
| 632 c.disconnect(); | 607 c.disconnect(); |
| 633 } | 608 } |
| 634 } | 609 } |
| 635 } | 610 } |
| 636 | 611 |
| 637 private boolean pushkey(String namespace, String key, String oldValue, String newValue) throws HgRemoteConnectionException, HgRuntimeException { | 612 private boolean pushkey(String opName, String namespace, String key, String oldValue, String newValue) throws HgRemoteConnectionException, HgRuntimeException { |
| 638 HttpURLConnection c = null; | 613 HttpURLConnection c = null; |
| 639 try { | 614 try { |
| 640 final String p = String.format("%s?cmd=pushkey&namespace=%s&key=%s&old=%s&new=%s", url.getPath(), namespace, key, oldValue, newValue); | 615 final String p = String.format("%s?cmd=pushkey&namespace=%s&key=%s&old=%s&new=%s", url.getPath(), namespace, key, oldValue, newValue); |
| 641 URL u = new URL(url, p); | 616 URL u = new URL(url, p); |
| 642 c = setupConnection(u.openConnection()); | 617 c = setupConnection(u.openConnection()); |
| 643 c.setRequestMethod("POST"); | 618 c.setRequestMethod("POST"); |
| 644 c.connect(); | 619 c.connect(); |
| 645 if (debug) { | 620 if (debug) { |
| 646 dumpResponseHeader(u, c); | 621 dumpResponseHeader(u, c); |
| 647 } | 622 } |
| 648 checkResponseOk(c, key, "pushkey"); | 623 checkResponseOk(c, opName, "pushkey"); |
| 649 final InputStream is = c.getInputStream(); | 624 final InputStream is = c.getInputStream(); |
| 650 int rv = is.read(); | 625 int rv = is.read(); |
| 651 is.close(); | 626 is.close(); |
| 652 return rv == '1'; | 627 return rv == '1'; |
| 653 } catch (MalformedURLException ex) { | 628 } catch (MalformedURLException ex) { |
