A&O Matt Enright 2009-06-29: Sharpy-git-goodness

1 view
Skip to first unread message

Matt Enright

unread,
Jun 30, 2009, 1:54:44 AM6/30/09
to mono-s...@googlegroups.com
A&O Matt Enright 2009-06-29: Sharpy-git-goodness
==============================================
Since I'm sure I'm not the only one frustrated, this week I adopted a
more top-down approach to adding stuff, and, as a consequence, there's
a whole bunch of classes and things that don't have anything but
properties or very basic methods right now, and are getting their
plumbing added as it becomes necessary.
These are mostly confined to the 'dreams' branch, though they are
popping-up elsewhere as I give them actual functionality.
* * *

Achievements
--------------
- Loose object serialization to disk [DONE*]
- Core data structures [Index, ObjectStore] [DONE]

Objectives
------------
- Stub out MonoDevelop addin
- Start hooking the difftools code up to the Git objects (diff-tree,
diff-stages, diff-index, etc.)

Bonus
-------
- * The refactor-objects branch is full of my haphazard drunken
scrawlings towards this aim. I am cleaning the rest of it up and will
merge a patchset that doesn't look like a slaughterhouse to master
this morning, but this is complete, modulo an unresolved design issue
of how to keep a reference to a (potentially very large) byte stream.
(i.e. deserialization is a bit of a pain in the ass right now since
you have to call multiple methods with the same stream argument)

- I've had quite enough of bit-packing and binary file formats, thank
you very much. The index read is now quasi-functional, but does not
include any of the nifty extensions (but does include the extension
flags supported in the cache entry).

- I could use a little bit of help, if anyone has the time or
inclination, with a good way to abstract some of the platform-specfic
code out. Reading the binary files uses memory-maps, and the index in
particular needs to get the stat information for files on-disk, among
a few other things. I don't have any designs on implementing ie a
Windows backend at the moment, but I'd ideally like to just have an
interface (or abstract classes) that the rest of the code works with,
and then just implement them in separate namespaces/assemblies
(runtime? compile-time?) So if anyone can spare a few lines here on
that (or ping me, wshimmy), it would be much appreciated! (at the
moment I'm just going with the Mono.Unix* stuff so it works).

Alan McGovern

unread,
Jun 30, 2009, 5:38:59 AM6/30/09
to mono-s...@googlegroups.com
Hey,


On Tue, Jun 30, 2009 at 6:54 AM, Matt Enright <awicke...@gmail.com> wrote:
- I could use a little bit of help, if anyone has the time or
 inclination, with a good way to abstract some of the platform-specfic
 code out. Reading the binary files uses memory-maps, and the index in
 particular needs to get the stat information for files on-disk, among
 a few other things. I don't have any designs on implementing ie a
 Windows backend at the moment, but I'd ideally like to just have an
 interface (or abstract classes) that the rest of the code works with,
 and then just implement them in separate namespaces/assemblies
 (runtime? compile-time?) So if anyone can spare a few lines here on
 that (or ping me, wshimmy), it would be much appreciated! (at the
 moment I'm just going with the Mono.Unix* stuff so it works).

This is actually relatively easy to manage. I'll use a basic example of listing files in a folder just because I can ;) So the idea is that for each platform you're on, you need to provide a platform specific implementation of reading directory contents.

In this case I've been a little sneaky and used partial classes so that WindowsPlatform, MacOSPlatform and UnixPlatform can be completely invisible to user code and are instead instantiated as required in the static Platform constructor and accessed through the Instance variable. There's no reason for *any* code other than the Platform class to even know that there are multiple implementations available.

Hopefully the code below is enough to give you an idea on how to approach it. If anyone wants to chime in with a better approach, let me know.

    // Platform.cs
    public partial abstract class Platform
    {
        public static Platform Instance {
            get; private set;
        }
        static Platform ()
        {
            // Warning: You may need a better way to check the platform than this
            // There are issues with the PlatformID enum.
            switch (Environment.OSVersion.Platform) {
            case PlatformID.MacOSX:
                Instance = new MacPlatform ();
                break;
            case PlatformID.Unix:
                Instance = new UnixPlatform ();
                break;
            default:
                Instance = new WindowsPlatform ();
            }
        }
         
        public abstract string[] ListDirectory (string path);
    }
    
    // UnixPlatform.cs
    partial class Platform
    {
        class UnixPlatform : Platform
        {
            public override string[] ListDirectory (string path)
            {
                return Mono.Unix.Whatever.ListDirectory (path);
            }
        }
    }
    
    // WindowsPlatform.cs
    partial class Platform
    {
        class WindowsPlatform : Platform
        {
            public override string[] ListDirectory (string path)
            {
                return Native.PInvokes.ReadContents (path);
            }
        }
    }
 





Reply all
Reply to author
Forward
0 new messages