Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tidy up consistency check code, and fix some unidiomatic constructions

  • Loading branch information...
commit ffd9c8df3615c17cba5a4545e49bae6ef62cc557 1 parent a110c04
Steve Purcell authored

Showing 1 changed file with 31 additions and 37 deletions. Show diff stats Hide diff stats

  1. +31 37 darcs-to-git
68 darcs-to-git
@@ -72,14 +72,10 @@ end
72 72 opts.parse!
73 73
74 74 SRCREPO = ARGV[0]
75   -if SRCREPO.nil? or not FileTest.exists?(SRCREPO + '/_darcs') then
76   - if SRCREPO.nil? then
77   - puts opts.banner()
78   - puts opts.summarize()
79   - else
80   - puts "Argument must be a valid local darcs repository"
81   - end
82   - exit(1)
  75 +if SRCREPO.nil?
  76 + abort opts.banner() + opts.summarize()
  77 +elsif !FileTest.exists?(SRCREPO + '/_darcs')
  78 + abort "#{SRCREPO} is not a valid local darcs repository"
83 79 end
84 80
85 81
@@ -166,7 +162,7 @@ class CommitHistory
166 162
167 163 def find_git_commit(is_tag, git_tag_name, identifier)
168 164 return nil unless File.exists?(".git/refs/heads/master") # empty repo
169   - if is_tag then
  165 + if is_tag
170 166 output_of("git-tag", "-l").split(/\r?\n/).include?(git_tag_name) &&
171 167 output_of("git-rev-list", "--max-count=1", "tags/#{git_tag_name}").strip
172 168 else
@@ -280,7 +276,7 @@ class DarcsPatch
280 276 # aren't well-defined, so we ignore the timezone name and instead
281 277 # calculate the timezone offset ourselves by calculating the
282 278 # difference between local time and UTC time.
283   - if not utc =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ then
  279 + if not utc =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/
284 280 raise "Wrong darcs date format"
285 281 end
286 282 utc_time = Time.utc($1,$2,$3,$4,$5,$6)
@@ -288,7 +284,7 @@ class DarcsPatch
288 284 # everything except timezone name is fixed-length, if parsing
289 285 # fails we just use UTC
290 286 pat = /^\w\w\w (\w\w\w) ([ 1-9]\d) ([ 0-9]\d)\:(\d\d)\:(\d\d) \w* (\d\d\d\d)/
291   - local_time = if local =~ pat then
  287 + local_time = if pat =~ local
292 288 Time.utc($6,$1,$2,$3,$4,$5)
293 289 else
294 290 utc_time
@@ -358,7 +354,7 @@ unless FileTest.exists?("#{GIT_PATCHES}")
358 354 exit(1)
359 355 end
360 356
361   -AUTHOR_MAP = if OPTIONS[:author_map] then
  357 +AUTHOR_MAP = if OPTIONS[:author_map]
362 358 AuthorMap.load(OPTIONS[:author_map])
363 359 elsif File.exists?(DEFAULT_AUTHOR_MAP_FILE)
364 360 AuthorMap.load(DEFAULT_AUTHOR_MAP_FILE)
@@ -371,7 +367,7 @@ COMMIT_HISTORY = CommitHistory.new(GIT_PATCHES)
371 367
372 368
373 369 patches = DarcsPatch.read_from_repo(SRCREPO)
374   -if OPTIONS[:list_authors] then
  370 +if OPTIONS[:list_authors]
375 371 extract_authors(patches)
376 372 exit(0)
377 373 end
@@ -382,37 +378,35 @@ while patch = patches.pop
382 378 patches_to_pull.unshift(patch)
383 379 end
384 380
385   -$run_consistency_check = true
386   -if OPTIONS[:num_patches] > 0 then
  381 +want_consistency_check = true
  382 +if OPTIONS[:num_patches] > 0
387 383 # if we don't pull all patches, then the consistency check would
388 384 # fail, so we simply skip it
389   - $run_consistency_check = patches_to_pull.length <= OPTIONS[:num_patches]
  385 + want_consistency_check = patches_to_pull.length <= OPTIONS[:num_patches]
390 386 # only pull specified number of patches
391   - patches_to_pull = patches_to_pull[0, OPTIONS[:num_patches]]
  387 + patches_to_pull = patches_to_pull.first(OPTIONS[:num_patches])
392 388 end
393 389
394 390 patches_to_pull.each &:pull_and_apply
395 391
396   -def check_consistent(pulled)
397   - ok = true
398   - if $run_consistency_check then
399   - puts "Checking for consistency ..."
400   - system("diff", "-ur", "-x", "_darcs", "-x", ".git", ".", SRCREPO)
401   - ok = $? == 0
402   - end
403   - if ok then
404   - if pulled.length == 0 then
405   - puts "\nNothing to pull."
406   - else
407   - puts "\nPulled #{pulled.length} patch#{pulled.length != 1 ? "es" : ""}."
408   - puts "\nDarcs import successful! You may now want to run `git gc' to
  392 +
  393 +pulled = patches_to_pull.size
  394 +if pulled == 0
  395 + puts "\nNothing to pull."
  396 +else
  397 + puts "\nPulled #{pulled} patch#{"es" unless pulled == 1}."
  398 + puts "\nDarcs import successful! You may now want to run `git gc' to
409 399 improve space usage the git repo"
410   - end
411   - else
412   - puts "!!! There were differences! See diff above for details."
413   - puts "!!! It maybe that the source repository was dirty."
414   - puts "!!! Run \"cd #{SRCREPO} && darcs whatsnew -sl\" to check."
415   - end
416 400 end
417 401
418   -check_consistent(patches_to_pull)
  402 +if want_consistency_check
  403 + puts "Comparing final state with source repo..."
  404 + system("diff", "-ur", "-x", "_darcs", "-x", ".git", ".", SRCREPO)
  405 + if $? != 0
  406 + abort <<-end_msg
  407 +!!! There were differences! See diff above for details.
  408 +!!! It may be that the source repository was dirty.
  409 +!!! Run "cd #{SRCREPO} && darcs whatsnew -sl" to check.
  410 + end_msg
  411 + end
  412 +end

0 comments on commit ffd9c8d

Please sign in to comment.
Something went wrong with that request. Please try again.