Permalink
Browse files

OTWO-415 Rake passes using HglibAdapter

  • Loading branch information...
1 parent 29c311d commit 20d25e2823a6f035fc53bfd07ec519e54d4dc0f3 @robinluckey committed Nov 30, 2011
@@ -1,9 +1,14 @@
module Scm::Adapters
class HglibAdapter < HgAdapter
- def cat(revision, path)
- hg_client.cat_file(revision, path)
+ def cat_file(commit, diff)
+ hg_client.cat_file(commit.token, diff.path)
end
+ def cat_file_parent(commit, diff)
+ tokens = parent_tokens(commit)
+ hg_client.cat_file(tokens.first, diff.path) if tokens.first
+ end
+
end
end
@@ -17,7 +17,15 @@ def open_repository
end
def cat_file(revision, file)
- send_command("CAT_FILE\t#{revision}\t#{file}")
+ begin
+ send_command("CAT_FILE\t#{revision}\t#{file}")
+ rescue RuntimeError => e
+ if e.message =~ /not found in manifest/
+ return nil # File does not exist.
+ else
+ raise
+ end
+ end
end
def parent_tokens(revision)
@@ -0,0 +1,9 @@
+module Scm::Adapters
+ class HglibAdapter < HgAdapter
+
+ def parent_tokens(commit)
+ hg_client.parent_tokens(commit.token)
+ end
+
+ end
+end
@@ -16,7 +16,9 @@ def get_file_content(self, filename, revision):
return contents
def get_parent_tokens(self, revision):
- return None
+ c = self.repository.changectx(revision)
+ parents = [p.hex() for p in c.parents() if p.hex() != '0000000000000000000000000000000000000000']
+ return parents
class Command:
def __init__(self, line):
@@ -45,42 +47,38 @@ def send_data(result):
sys.stdout.write(result)
sys.stdout.flush()
-def exit_delayed(status, delay=1):
- time.sleep(delay)
- sys.exit(status)
-
def command_loop():
while True:
- cmd = Command(sys.stdin.readline())
- if cmd.get_action() == 'REPO_OPEN':
+ s = sys.stdin.readline()
+ cmd = Command(s)
+ if s == '' or cmd.get_action() == 'QUIT':
+ sys.exit(0)
+ elif cmd.get_action() == 'REPO_OPEN':
commander = HglibPipeServer(cmd.get_arg(1))
send_success()
elif cmd.get_action() == 'CAT_FILE':
- content = commander.get_file_content(cmd.get_arg(2), cmd.get_arg(1))
- if content == None:
- send_failure()
- else:
+ try:
+ content = commander.get_file_content(cmd.get_arg(2), cmd.get_arg(1))
send_success(len(content))
send_data(content)
+ except Exception:
+ send_failure() # Assume file not found
elif cmd.get_action() == 'PARENT_TOKENS':
tokens = commander.get_parent_tokens(cmd.get_arg(1))
- tokens = '|'.join(tokens)
+ tokens = '\n'.join(tokens)
send_success(len(tokens))
send_data(tokens)
- elif cmd.get_action() == 'QUIT':
- send_success()
- exit_delayed(status=0)
else:
error = "Invalid Command - %s" % cmd.get_action()
send_error(len(error))
send_data(error)
- exit_delayed(status=1)
+ sys.exit(1)
if __name__ == "__main__":
try:
command_loop()
- except:
+ except Exception:
exc_trace = traceback.format_exc()
send_error(len(exc_trace))
send_data(exc_trace)
- exit_delayed(status=1)
+ sys.exit(1)
@@ -22,3 +22,4 @@ def cleanup
end
require 'lib/scm/adapters/hglib/cat_file'
+require 'lib/scm/adapters/hglib/head'
@@ -21,7 +21,7 @@ def test_cat_file
EXPECTED
# The file was deleted in revision 468336c6671c. Check that it does not exist now, but existed in parent.
- # assert_equal nil, hg.cat_file(Scm::Commit.new(:token => '75532c1e1f1d'), Scm::Diff.new(:path => 'helloworld.c'))
+ assert_equal nil, hg.cat_file(Scm::Commit.new(:token => '75532c1e1f1d'), Scm::Diff.new(:path => 'helloworld.c'))
assert_equal expected, hg.cat_file_parent(Scm::Commit.new(:token => '75532c1e1f1d'), Scm::Diff.new(:path => 'helloworld.c'))
assert_equal expected, hg.cat_file(Scm::Commit.new(:token => '468336c6671c'), Scm::Diff.new(:path => 'helloworld.c'))
end
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+module Scm::Adapters
+ class HgHeadTest < Scm::Test
+
+ def test_head_and_parents
+ with_hglib_repository('hg') do |hg|
+ assert_equal '75532c1e1f1d', hg.head_token
+ assert_equal '75532c1e1f1de55c2271f6fd29d98efbe35397c4', hg.head.token
+ assert hg.head.diffs.any? # diffs should be populated
+
+ assert_equal '468336c6671cbc58237a259d1b7326866afc2817', hg.parents(hg.head).first.token
+ assert hg.parents(hg.head).first.diffs.any?
+ end
+ end
+
+ end
+end

0 comments on commit 20d25e2

Please sign in to comment.