Git and Subversion Workflow – Part 1

Setting up git to use with subversion

Creating the initial subversion repository as a git repository, run this command:
$ git svn init -s [repository_url]

Then…
$ git svn fetch

This command will probably run for a while (especially large repositories) as it needs to find branches, tags, etc.

Switching to branches and creating local branches

This command will show you all your local and remote branches. Any remote branches will always have “remote/” before it.
$ git branch -a

This command will checkout your subversion code.
$ git checkout remotes/[subversion directory]

Then, to create a branch from that remote version.
$ git checkout -b [name_of_new_branch]

Committing to subversion

After some code changes, you can commit to whatever branch or trunk folder you’re current working off of by running the following command:

$ git svn dcommit

Cleaning up git

Run this command after you’ve had the repository running for awhile or if you run into some problems. This will do some compression and clean up of the git objects.
$ git gc

Adding a remote repository


$ git remote add [repository_name] [repository]

Then to add to it:


$ git push [repository_name] [branch]

Git and Subversion together

Subversion has been around for awhile as a version control system and I’ve been using it since it became a 1.0 application. Recently, I’ve begun using Git and found that I like it a lot more because it allows more finer control over my local code with things like local branching, fast branch switching, local commits, rewriting local commits before submit to main repository, and the stash.

So with the Git SVN bridge, you can pull from your subversion repository. Be forewarned though, if you have a large subversion repository with lots of revisions, it will take awhile to do the following because Git needs to process the revisions of the entire repository.
$ git svn clone [SVN_REPO_URL] --tags=tags --branches=branches --trunk=trunk

Now you have a local repository with changes with the above Git command. What I want though is a repository where I can make changes on more than one machine because I code on a work computer, a home desktop computer and a home laptop, I can create a personal repository that would sync all my computers but not commit changes to subversion yet. To do that I would create a personal Git repository, then add a remote site to the subversion clone from last command.
$ git add remote [NAME] [PERSONAL_REPO_SITE]

Push the subversion clone to my personal repository:
$ git push origin master

Once that’s done, I can pull from my local repository on any of my computers. Any changes that I want to commit to subversion, I go back to the computer with the subversion clone, update from my personal repository and commit those changes for everyone to see.
$ git svn dcommit

That’s it — that would be hard to do with Subversion alone and Git actually works the way I work. Sweet!

Reference:
Git SVN Crash Course
Git-SCM Book

Hardcopy Reference:
Pragmatic Version Control Using Git

Using ant, flextask, flexsdk, and compc to build a classes holding component for Flash and Flex

You can set up the location of the flex sdk anywhere and remember to re-adjust the location.

I’ve found out that when you use compc, the swc generated catalog.xml file includes digests and omits the components information that Flash components need to appear in the Components panel. So in order to fix the components, you need to set a custom namespace and include it in your build’s compilation properties. My manifest.xml is located in the resources direct and looks like this –

<?xml version="1.0" encoding="utf-8"?>
<componentPackage>
	<component id="MyComponent" class="com.momentstar.MyComponent" />
</componentPackage>

Then, to disable adding digest information, you have to disable the digests information. The properties highlighted are the namespace, include-namespaces, and compute-digest tags in the build file below –

<taskdef resource="flexTasks.tasks" classpath="${basedir}/flex_sdk_3/ant/lib/flexTasks.jar" />

<property name="FLEX_HOME" value="${basedir}/flex_sdk_3" />
<property name="BUILD.DIR" value="target" />
<property name="PACKAGE.DIR" value="${BUILD.DIR}/project" />

<target name="build" description="Builds project">
  <mkdir dir="${PACKAGE.DIR}" />
  <compc output="${PACKAGE.DIR}/MyComponent.swc" locale="en_US">
                  <namespace uri="http://momentstar.com/2008" manifest="resources/manifest.xml" />
                  <include-namespaces>http://momentstar.com/2008</include-namespaces>
                  <strict>true</strict>
                  <optimize>true</optimize>
                  <warnings>true</warnings>
                  <source-path>src</source-path>
                  <compute-digest>false</compute-digest>
  </compc>
</target>

What is service-config.xml and remote-config.xml

In using amfphp, I found that I need to create two configuration files: services-config.xml and remoting-config.xml. In the Flex 2 documentation, the former file defines the basic services settings such as security and logging. Destination services definitions should not be defined in the services-config.xml, instead create references in the file to separate specific configuraton files reserved for the different services types to a dedicated file. These files include the data-management-config.xml, messaging-config.xml, and proxy-config.xml. And finally, the latter file is used on of those so called configuration files and defines RemoteObject services. You may also use multiple files of the same type, if it’ll help with maintaining groups of services.

services-config.xml

There are several nodes and attributes for this file. For a complete list, bring up the help index in Flex Builder and search for “Data Service configuration file syntax”. For amfphp, you only need the following defined:

<?xml version="1.0" encoding="UTF-8"?>
<services-config> 

<services>
      <service-include file-path="remoting-config.xml" />
   </services>

<channels>
      <channel-definition id="[your channel service id]"
      		class="mx.messaging.channels.AMFChannel">
         <endpoint uri="http:/[your_server]/amfphp/gateway.php"
         		class="flex.messaging.endpoints.AMFEndpoint"/>
      </channel-definition>
   </channels>

</services-config>

From Adobe’s documentation, the services node contains the individual data services or references that are the xml files containing the service definitions. It is declared at the top level of the configuration as the child node for services-config node. Inside the services node, is the service-include file-path node. This provides the service file locations and their path is relative to the directory containing the services-config.xml file. As an aside, if you don’t want to break up the definitions, you could include them using the service as a child of the services node. But based on all the other documentation I’ve read, just break up the definitions into managable smaller files. (I’m sure there’s a reason for this other then scalability, let me know and I’ll update this post.)

The channels node provides information about the data transportation between the server and the clients. The channel-definition node defines the message channel that can be used to transport the data with it’s id attribute should match the one defined in the service definition and it’s class attribute being the fully qualified AS3 class for the message channel, which is the AMF in our case. The others are RTMP, AMF polling, Secure RTMP, Secure AMF, HTTP, and Secure HTTP. Per the Configuring message channels documentation, you can actually pair any type of service with any type of channel. Next, the endpoint node is where the client should begin requesting the service with it’s URI attribute pointing to the url of the service and class attribute is the fully qualified AS3 class for the endpoint. The url points to AMFPHP’s gateway.php file.

And that’s it for the service-config file.

remote-config.xml

Just like the services-config file, there are lot of nodes and their associated attributes that are allowed for the remote-config file, which again only references “RemoteObject” calls. To find the Adobe documentation, do a search for “Understanding destination configuration”. The following example is the only thing needed to make a call from our Flex application:

<?xml version="1.0" encoding="utf-8" ?>
<service id="[my flash remote id]"
 	class="flex.messaging.services.RemotingService"
 	messageTypes="flex.messaging.messages.RemotingMessage"> 

<default-channels>
      <channel ref="[your channel service id]"/>
   </default-channels>

<destination id="categoryService">
      <properties>
         <source>com.momentstar.service.CategoryDao</source>
      </properties>
   </destination>

</service>

So a destination is object/service that you connect to using <mx:RemoteObject>, <mx:WebService>, or <mx:HTTPService> tags or Actionscript code. The service node defines the type of service with the id attribute is your arbitrary value, class and messageTypes referring to the RemoteObject.

The default-channels node and it’s child channel correspond to the channel-definition found in the services-config. Next, the destination node and the id attribute is what is used and referred to in your MXML/AS3 code. And finally, within the destination noe is the properties node, where you provide the source node that contains the qualified class name of our AMFPHP service.

Using the files in the compilation

Next, is to tell your application to use the configuration files. When using mxmlc, add -services option with the path to the services-config.xml file. In Flexbuilder, go to the Project, then Properties, and select the Flex Compiler option and in the Additional compiler arguments text box, where you should add something like:

 -services=./WEB-INF/flex/services-config.xml

So the next thing is to use the above definitions in the Flex application. One thing I’d like to ask is how do you make different service destination calls and display them in some datagrid. Right now, I’ve only been making one service call per screen in my Flex application. If anyone has tips, again, just let me know!

References:
http://www.flex.org/documentation/

Difference between Remote Procedure Call (RPC) Services: HttpService, Remote Objects, and Web Services in Flex

Disclaimer, the post are my research into the issue as I was curious about the different RPC services.

Now, if I could afford it, I would like to use the Flex Data Services (FDS) especially since I really want to see if Adobe/Macromedia has made Data Management and Messaging simpler, I might research the FDS Express later on; but I want to get up and running, so here we go. For right now, the RPC calls are built-in to the Flex SDK and Flexbuilder, so I got to go with what I got.

Basically, Flex allows three types of RPC services: HttpService, WebServices, and RemoteObject Services. In Flex, using the “RemoteObjects specifies named or unnamed sources and connects to an Action Message Format (AMF) gateway, whereas using the HTTPService and WebService use named services or raw URLs and connect to an HTTP proxy using text-based query parameters or XML”. Specifically, HTTPServices use raw HTTP requests, WebServices use the SOAP protocol and RemoteObjects uses AMF3.

“RemoteObject provides two advantages over HTTP or SOAP. First, while the AMF protocol uses HTTP to transfer packets, the data is transferred in a binary format that is natively understood by the Flash Player. As a result, data can move across the network more quickly and it can be deserialized more rapidly than text-based formats such as XML. Both of these result in performance gains, particularly where large sets of data are involved. Secondly, RemoteObject provides signficant productivity advantages. The remoting service, which runs on your server, automatically marshalls data between AMF and your server-side language (e.g., PHP, Java, C#). As a result, you can directly call methods on your PHP objects without having to write an XML REST interface or create web service interfaces”.

So which one to choose? As far as I’m concerned, I use little data sets so receiving data over the HTTPService has been a cinch. If I ever have to go through a larger data sets, I’ve looked at AMFPHP and found version 1.9 was very good and easier to configure then others. Again, this will probably be something that I’ll have to further research.

References:

http://store1.adobe.com/devnet/flex/articles/refactoring_flex.html
The article explains how to refact flex and about the data management services in FDS.

http://www.adobe.com/devnet/flex/articles/rpc_service.html
An article about Flex’s RPC services

http://www.adobe.com/devnet/flex/articles/remoteobject_sabreamf.html
Article about the other PHP Remoting framework, SabreAMF.