Skip to content
Browse files

[git] Fix the git repository pluggins.

The tests pass.
  • Loading branch information...
1 parent e1744d3 commit 763e341d9d3123c028f9ab489134cdf42af2736c @samoht samoht committed May 18, 2012
Showing with 44 additions and 24 deletions.
  1. +1 −1 src/path.ml
  2. +4 −4 src/repo/git/download.ml
  3. +13 −8 src/repo/git/init.ml
  4. +2 −1 src/repo/git/update.ml
  5. +8 −10 src/run.ml
  6. +16 −0 src/utils.ml
View
2 src/path.ml
@@ -22,7 +22,7 @@ let available dir =
let files = List.filter (fun f -> Filename.check_suffix f ".opam") files in
List.fold_left (fun set file ->
match NV.of_filename file with
- | None -> log "XXX %s" (Filename.to_string file); set
+ | None -> log "%s is not a valid package filename!" (Filename.to_string file); set
| Some nv -> NV.Set.add nv set
) NV.Set.empty files
View
8 src/repo/git/download.ml
@@ -19,7 +19,7 @@ let git_archive () =
let url =
let p = local_path / "url" / package in
if Sys.file_exists p then
- Run.read p
+ Utils.string_strip (Run.read p)
else
Globals.error_and_exit "Cannot find %s" p in
Run.mkdir "git";
@@ -32,7 +32,7 @@ let git_archive () =
(* Then run git-archive to get a tar.gz *)
Run.in_dir dirname (fun () ->
let err =
- Run.command "git archive --format=tar --prefix=%s HEAD | gzip > %s.tar.gz" package package in
+ Run.command "git archive --format=tar --prefix=%s/ HEAD | gzip > %s.tar.gz" package package in
if err <> 0 then
Globals.error_and_exit "Cannot run git-archive in %s" dirname
)
@@ -42,7 +42,7 @@ let () =
git_archive ();
(* and copy the archive at the right place *)
- Run.mkdir (local_path / "archive");
+ Run.mkdir (local_path / "archives");
Run.copy
(local_path / "git" / package / package ^ ".tar.gz")
- (local_path / "archive" / package ^ ".tar.gz")
+ (local_path / "archives" / package ^ ".tar.gz")
View
21 src/repo/git/init.ml
@@ -1,13 +1,13 @@
(* Init script for git repositories *)
(* Git repositories should have the following structure:
- - opam/ contains the OPAM files
- - descr/ contains the description files
- - url/$name.$version contains the git url for package
- $name.version
- - git/$name.$version/ will contain the git repo for the
- package $name.$version when it will
- be cloned
+ - opam/ contains the OPAM files
+ - descr/ contains the description files
+ - url/$name.$version contains the git url for package
+ $name.version
+ - packages/$name.$version/ will contain the git repo for the
+ package $name.$version when it will
+ be cloned
*)
let _ =
@@ -20,8 +20,13 @@ let remote_address = Sys.argv.(1)
let git_clone () =
let err =
- Run.command "git clone %s ./" remote_address in
+ Run.commands [
+ "git init";
+ Printf.sprintf "git remote add origin %s" remote_address;
+ "git pull origin master"
+ ] in
exit err
let () =
+ Run.mkdir "packages";
git_clone ()
View
3 src/repo/git/update.ml
@@ -13,7 +13,7 @@ let _ =
let local_path = Run.cwd ()
let remote_address = Sys.argv.(1)
-let repositories = Filename.concat local_path "repositories"
+let repositories = Filename.concat local_path "packages"
(* Return the list of modified files of the git repository located
at [dirname] *)
@@ -46,6 +46,7 @@ let () =
let repo_updates =
Utils.filter_map (fun f -> NV.of_filename (Filename.of_string f)) repo_updates in
let repo_updates = List.fold_right NV.Set.add repo_updates NV.Set.empty in
+ update local_path;
(* Look at already cloned packages *)
let dirs = Run.directories repositories in
View
18 src/run.ml
@@ -66,7 +66,7 @@ let write file contents =
let cwd = Unix.getcwd
let chdir dir =
- log "chdir %s" dir;
+(* log "chdir %s" dir; *)
Unix.chdir dir
let in_dir dir fn =
@@ -225,7 +225,7 @@ let is_archive file =
| Some s -> fun _ -> Some s
| None -> fun (ext, c) ->
if List.exists (Filename.check_suffix file) ext then
- Some (command "tar xvf%c %s -C %s" c file)
+ Some (command "tar xf%c %s -C %s" c file)
else
None)
None
@@ -235,16 +235,14 @@ let is_archive file =
let extract file dst =
log "untar %s" file;
let files = read_command_output "tar tf %s" file in
- log "%d files found: %s" (List.length files) (String.concat ", " files);
+ log "%s contains %d files: %s" file (List.length files) (String.concat ", " files);
let aux name =
- if root name = Filename.basename dst then
- Filename.concat tmp_dir name, Filename.concat dst name
- else
- let root = root name in
- let n = String.length root in
- let rest = String.sub name n (String.length name - n) in
- Filename.concat tmp_dir name, dst ^ rest in
+ let root = root name in
+ let n = String.length root in
+ let rest = String.sub name n (String.length name - n) in
+ Filename.concat tmp_dir name, dst ^ rest in
let moves = List.map aux files in
+ remove_dir tmp_dir;
mkdir tmp_dir;
let err =
match is_archive file with
View
16 src/utils.ml
@@ -29,3 +29,19 @@ module IntMap = Map.Make(struct type t = int let compare = compare end)
module IntSet = Set.Make(struct type t = int let compare = compare end)
let (|>) f g x = g (f x)
+
+let string_strip str =
+ let p = ref 0 in
+ let l = String.length str in
+ let fn = function
+ | ' ' | '\t' | '\r' | '\n' -> true
+ | _ -> false in
+ while !p < l && fn (String.unsafe_get str !p) do
+ incr p;
+ done;
+ let p = !p in
+ let l = ref (l - 1) in
+ while !l >= p && fn (String.unsafe_get str !l) do
+ decr l;
+ done;
+ String.sub str p (!l - p + 1)

0 comments on commit 763e341

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