Hi all!

This is my attempt to  fixissue1039. The patches introduce a 'repo-id'
parameter that is created during init and stored in format file. During
get source repo id is copied to the local repo. During push/pull/send
we compare repo ids and ask for confirmation if they do not match.

There are two things I do not like about the patch:

- older darcs versions are not able to get repositories with 'repo-id'.
  Perhaps repo-id should be stored not in the format file.

- tests do not pass. I suppose it hangs on prompt input.
  How is this handled in other places?

Reviews, comments welcomed :)

Regards,
  Dmitry

Tue Sep 16 22:12:19 MSD 2008  Dmitry Kurochkin <[EMAIL PROTECTED]>
  * Refactor copyInventory to not use identifyRepositoryFor.

Wed Sep 17 00:21:37 MSD 2008  Dmitry Kurochkin <[EMAIL PROTECTED]>
  * Resolve issue1039: detect seemingly unrelated repositories.

New patches:

[Refactor copyInventory to not use identifyRepositoryFor.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080916181219] hunk ./src/Darcs/Commands/Get.lhs 179
-                             identifyRepositoryFor repository repodir >>= copyRepository
+                             fromrepository <- identifyRepositoryFor repository repodir
+                             copyRepository repository fromrepository
hunk ./src/Darcs/Repository.lhs 109
-copyRepository :: RepoPatch p => Repository p C(r u t) -> IO ()
-copyRepository fromrepository@(Repo _ opts rf _)
+copyRepository :: RepoPatch p => Repository p C(r u t) -> Repository p C(r u t) -> IO ()
+copyRepository repo fromrepository@(Repo _ opts rf _)
hunk ./src/Darcs/Repository.lhs 112
-        do isPartial <- copyPartialRepository fromrepository
-           unless (isPartial == IsPartial) $ copyFullRepository fromrepository
-    | otherwise = copyFullRepository fromrepository
+        do isPartial <- copyPartialRepository repo fromrepository
+           unless (isPartial == IsPartial) $ copyFullRepository repo fromrepository
+    | otherwise = copyFullRepository repo fromrepository
hunk ./src/Darcs/Repository.lhs 121
-copyInventory :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> IO ()
-copyInventory fromrepo@(Repo fromdir opts rf (DarcsRepository _ cremote)) = do
-  repo@(Repo todir xx rf2 (DarcsRepository yy c)) <- identifyRepositoryFor fromrepo "."
+copyInventory :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> Repository p C(r u t) -> IO ()
+copyInventory repo@(Repo todir xx rf2 (DarcsRepository yy c)) fromrepo@(Repo fromdir opts rf (DarcsRepository _ cremote)) = do
hunk ./src/Darcs/Repository.lhs 166
-copyPartialRepository :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> IO PorNP
-copyPartialRepository fromrepository@(Repo _ opts _ _) = do
+copyPartialRepository :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> Repository p C(r u t) -> IO PorNP
+copyPartialRepository repo fromrepository@(Repo _ opts _ _) = do
hunk ./src/Darcs/Repository.lhs 173
-      do copyInventory fromrepository
+      do copyInventory repo fromrepository
hunk ./src/Darcs/Repository.lhs 187
-copyFullRepository :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> IO ()
-copyFullRepository fromrepository@(Repo fromdir opts rffrom _) = do
-  copyInventory fromrepository
+copyFullRepository :: forall p C(r u t). RepoPatch p => Repository p C(r u t) -> Repository p C(r u t) -> IO ()
+copyFullRepository repo fromrepository@(Repo fromdir opts rffrom _) = do
+  copyInventory repo fromrepository

[Resolve issue1039: detect seemingly unrelated repositories.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080916202137] hunk ./src/Darcs/Commands/Get.lhs 42
-import Darcs.Repository.Format ( identifyRepoFormat, RepoFormat,
+import Darcs.Repository.Format ( copyRepoId, identifyRepoFormat, RepoFormat,
hunk ./src/Darcs/Commands/Get.lhs 152
+  copyRepoId rf rfsource
hunk ./src/Darcs/Commands/Init.lhs 150
-    let rf = create_repo_format opts
+    rf <- create_repo_format opts
hunk ./src/Darcs/Repository/Format.lhs 10
-                    format_has, format_has_together,
+                    format_has, format_has_together, sameRepoId, copyRepoId
hunk ./src/Darcs/Repository/Format.lhs 13
-import Data.List ( sort, intersperse )
+import Data.List ( delete, sort, intersperse, isPrefixOf )
hunk ./src/Darcs/Repository/Format.lhs 16
+import System.Time ( getClockTime, toUTCTime )
hunk ./src/Darcs/Repository/Format.lhs 27
+import SHA1 ( sha1PS )
hunk ./src/Darcs/Repository/Format.lhs 30
-data RepoProperty = Darcs1_0 | Darcs2 | HashedInventory
+data RepoProperty = Darcs1_0 | Darcs2 | HashedInventory | RepoId String
hunk ./src/Darcs/Repository/Format.lhs 63
+sameRepoId :: RepoFormat -> RepoFormat -> Bool
+sameRepoId rf rf' = get_repoid rf == get_repoid rf'
+
+copyRepoId :: RepoFormat -> RepoFormat -> IO ()
+copyRepoId (RF ks) rf =
+  writeRepoFormat (RF $ removeRepoId ks ++ repoid) df
+    where removeRepoId = delete [] . map (filter (not.(isPrefixOf tok).unpackPS))
+          tok = unpackPS $ rp2ps (RepoId "")
+          repoid = case get_repoid rf of
+                     Just s -> [[rp2ps (RepoId s)]]
+                     Nothing -> []
+
hunk ./src/Darcs/Repository/Format.lhs 82
-create_repo_format :: [DarcsFlag] -> RepoFormat
-create_repo_format fs = RF ([map rp2ps flags2inv] ++ maybe2)
+create_repo_format :: [DarcsFlag] -> IO RepoFormat
+create_repo_format fs = do s <- genRepoId
+                           return $ RF ([map rp2ps flags2inv] ++ maybe2 ++ repoid s)
hunk ./src/Darcs/Repository/Format.lhs 88
+          repoid s = [[rp2ps (RepoId s)]]
+          genRepoId = fmap (sha1PS . packString . show . toUTCTime) getClockTime
hunk ./src/Darcs/Repository/Format.lhs 121
-is_known p = p `elem` map rp2ps known_properties
+is_known p = not . null $ filter (== p') props ++ filter (`isPrefixOf` p') props_with_arg
+    where p' = unpackPS p
+          fn = map (unpackPS.rp2ps)
+          props = fn known_properties
+          props_with_arg = fn known_properties_with_arg
hunk ./src/Darcs/Repository/Format.lhs 130
+known_properties_with_arg :: [RepoProperty]
+known_properties_with_arg = [RepoId ""]
+
hunk ./src/Darcs/Repository/Format.lhs 138
+
+get_repoid :: RepoFormat -> Maybe String
+get_repoid (RF ks) = rid $ filter (isPrefixOf tok) (map unpackPS (concat ks))
+    where tok = unpackPS $ rp2ps (RepoId "")
+          rid []    = Nothing
+          rid (a:_) = Just $ drop 8 a
hunk ./src/Darcs/Repository/Format.lhs 162
+rp2ps (RepoId s) = packString ("repo-id "++s)
hunk ./src/Darcs/Repository/Internal.lhs 68
-                                 identifyRepoFormat, format_has,
+                                 identifyRepoFormat, format_has, sameRepoId,
hunk ./src/Darcs/Repository/Internal.lhs 222
-         Nothing -> return $ Repo absurl opts rf_ t'
+         Nothing -> do unless (sameRepoId rf rf_) ask_confirmation
+                       return $ Repo absurl opts rf_ t'
+    where ask_confirmation = do
+            yorn <- promptYorn "These repositories seem to be unrelated. Proceed? "
+            when (yorn /= 'y') $ do putStrLn "Cancelled."
+                                    exitWith ExitSuccess

Context:

[remove now-unused is_addrmfile and is_addrmdir.
David Roundy <[EMAIL PROTECTED]>**20080916173136] 
[resolve issue1012: it seems to be fixed by the fix for issue709.
David Roundy <[EMAIL PROTECTED]>**20080916173116] 
[resolve issue885: fix patchSetToRepository to work with hashed.
David Roundy <[EMAIL PROTECTED]>**20080916173030] 
[resolve issue709: avoid adding changes to pending in rmpend when possible.
David Roundy <[EMAIL PROTECTED]>**20080916173002] 
[first-stage fix for issue709.
David Roundy <[EMAIL PROTECTED]>**20080916170333
 Here I fix the bug which leads to a corrupt pending being left, with a
 rmfile change but no hunk removing the contents.  This doesn't fix
 issue709, since an incorrect pending is left, it's just no longer a
 corrupt pending (i.e. it's still got the rmfile, but if you record it
 there's no problem).
] 
[add new test that we don't do anything when repairing a clean repo.
David Roundy <[EMAIL PROTECTED]>**20080916165437] 
[whitespace change in prepend.
David Roundy <[EMAIL PROTECTED]>**20080916160425] 
[make shell_harness print summary of passing tests when running bugs tests.
David Roundy <[EMAIL PROTECTED]>**20080916145820] 
[trailing whitespace cleanup in Repository.Internal.
David Roundy <[EMAIL PROTECTED]>**20080916142112] 
[tiny refactor in Internal.lhs.
David Roundy <[EMAIL PROTECTED]>**20080916155922] 
[simplify issue965 test (which took quite a while for me to figure out).
David Roundy <[EMAIL PROTECTED]>**20080916152028] 
[Make match.pl test understand Windows dates.
Eric Kow <[EMAIL PROTECTED]>**20080916011339
 Windows does not abbreviate its timezones.
] 
[Disable some tests that don't work under Windows.
Eric Kow <[EMAIL PROTECTED]>**20080916000912] 
[Translate get.pl test into shell.
Eric Kow <[EMAIL PROTECTED]>**20080916000227
 The original get.pl uses the Perl Cwd library, which seems not
 to work for purposes of this test under MSYS.
] 
[Test for issue691.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080916111332] 
[Resolve issue691: distinguish between NoArg and ReqArg in defaults parser.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080915224046] 
[Move get_default_flag type to definition.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080915220316] 
[reverse overly-invasive haddocking.
David Roundy <[EMAIL PROTECTED]>**20080915110353] 
[Fix overzealous escaping in haddock.
Eric Kow <[EMAIL PROTECTED]>**20080915070926] 
[Haddock documentation for English.lhs
[EMAIL PROTECTED]
 Docstrings by Eric Kow
] 
[Haddock documentation for PrintPatch
[EMAIL PROTECTED] 
[Haddock documentation for Flags
[EMAIL PROTECTED] 
[Haddock documentation for Motd
[EMAIL PROTECTED]
 docstring by Eric Kow
] 
[Haddock string for TheCommands
[EMAIL PROTECTED]
 Docstring by Eric Kow
] 
[In darcs send if POST fails try sendmail.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914234314] 
[Run testing in temp directories to avoid collosions, fail if DarcsURL header is not found.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914223930] 
[Use tempfile() UNLINK option to automatically remove temp files at exit.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914223827] 
[Coding style in upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914223751] 
[Stop after we found the first DarcsURL: in patch bundle.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914220421] 
[Spaces in upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914220324] 
[Grammar in Darcs.Commands.Send.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914232923] 
[Print "Successfully sent patch bundle to" only when we really sent something.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080914232905] 
[Really allow pull.sh test to pass on Windows.
Eric Kow <[EMAIL PROTECTED]>**20080914211458
 
 It seems that these redirections cause an openBinaryFile failure under
 Windows.  I do not yet understand why using different names makes a
 difference, but it could provide an interesting clue.
] 
[ChangeLog entries for darcs 2.0.3pre1
Eric Kow <[EMAIL PROTECTED]>**20080914094144] 
[Disable amend-cancelling test under Cygwin.
Eric Kow <[EMAIL PROTECTED]>**20080913213039] 
[Make binary.sh test more portable (avoid copying an exe).
Eric Kow <[EMAIL PROTECTED]>**20080913212843
 Under Windows, copying the exe file will result in an .exe extension
 being appended to the filename.  This confuses the test.
] 
[rewrite upload.cgi so it won't need any customization by default.
David Roundy <[EMAIL PROTECTED]>**20080913171447
 The downside is that it has to do a darcs get --lazy in order to check if
 the patch can be applied.  If you define $target_repo, however, it doesn't
 need to do this (but then can only accept patches to a single
 locally-present repo).
] 
[when _darcs/prefs/post is present, use _darcs/prefs/post for To: header.
David Roundy <[EMAIL PROTECTED]>**20080913171025] 
[sketchy documentation of _darcs/prefs/post
David Roundy <[EMAIL PROTECTED]>**20080913115655] 
[set default upload.cgi to work on darcs-unstable.
David Roundy <[EMAIL PROTECTED]>**20080913112227] 
[Improve upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912230953
 - check if patch is valid before sending
 - use sendmail to send patches or drop to maildir
] 
[Spaces and punctuation in upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912230827] 
[fix problem in Darcs.URL refactor pointed out by Eric.
David Roundy <[EMAIL PROTECTED]>**20080913104327] 
[Disable a pull.sh test under Windows.
Eric Kow <[EMAIL PROTECTED]>**20080912224027
 It relies on darcs not working if we chmod u-r a file.
 This seems to have little effect in Windows.
] 
[refactor Darcs.URL to eliminate use of Regexes.
David Roundy <[EMAIL PROTECTED]>**20080912173611
 The algorithms here are not tricky, and I find this easier to read.
] 
[change is_file to return false on [EMAIL PROTECTED]:
David Roundy <[EMAIL PROTECTED]>**20080912173501] 
[clean up whitespace.
David Roundy <[EMAIL PROTECTED]>**20080912150248] 
[fix manual for optional arguments.
David Roundy <[EMAIL PROTECTED]>**20080912150231] 
[clean up whitespace.
David Roundy <[EMAIL PROTECTED]>**20080912145708] 
[add test for new --output-auto-name feature.
David Roundy <[EMAIL PROTECTED]>**20080912145648] 
[Spaces in Darcs.Commands.Send module.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912122223] 
[Make '--output-auto-name' accept optional directory argument.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912120516] 
[Add DarcsOptAbsPathOption for options with optional path argument.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912112458] 
[Refactor Darcs.Repository.Prefs.getCaches.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912055204] 
[Print warning when '--http-pipelining' option is used, but darcs is compiled without HTTP pipelining support.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912054253] 
[Do not download URL we have speculated before.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912053236] 
[Spaces and parentheses in URL module.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912053000] 
[Coding style in Darcs.Arguments.network_options.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911140710] 
[Resolve issue1054: --no-cache option to ignore patch caches.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911140233] 
[Remove unused variable from configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911132107] 
[Comment in configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911115840] 
[Indentation fixes in configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911115117] 
[Formating and minor refactoring in URL.urlThread.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080910061227] 
[insecure printfs - fix the two that I can currently hit
Steve Cotton <[EMAIL PROTECTED]>**20080910230659] 
[TAG this version works.
David Roundy <[EMAIL PROTECTED]>**20080910212908] 
Patch bundle hash:
e3b4e6b8386ac39cb32cfa4f24437554f423df7b
_______________________________________________
darcs-users mailing list
[email protected]
http://lists.osuosl.org/mailman/listinfo/darcs-users

Reply via email to