Tuesday, March 15, 2011

git workflow question

Hi, this will be a long one but I hope you could bear with me.

I am trying to use git to put my team's source codes under version control. After trying to find different approaches that would work for me, I finally decided to use git format-patch feature. FWIW, the product is an ASP.NET web application running in Windows and I am currently using msysgit.

Background: I have a staging server(mirrors production server) which contains all the aspx files. I then created a git repo using init-db inside my root folder and did a "git add ." to track all the files.

In order for me to have a local copy on my laptop, I actually zipped up the ".git" folder from the staging server and FTP'ed it to my local machine. Renamed it to "staging.git" and did a "git clone staging.git webappfolder" to do my development against.

After doing 2 commits for feature1 and feature2, its time to apply the changes back to the staging server. I did a "git format-patch -2" which outputs to files 0001blah.patch and 0002blah.patch.

This 2 patch files are then sent to the staging server and I did a "git am 0001blah.patch" on the staging server itself. Doing a "git log" shows the commit went through. But when I do a "git status", it shows "Changed but not updated: modified: file1.aspx".

What does that mean exactly? I also tried doing a "git apply 0001blah.patch" but all I got was an "error" patch failed: file1.aspx: patch does not apply".

Is there a problem with my workflow? Any insight regarding the proper way or help would be exremely helpful. Again, the patching model would be the most viable for us right now as we won't be setting up an SSH server anytime. Once again, thanks in advance.

From stackoverflow
  • Did you try a

    git am -3
    

    ? From the git-am doc,

    -3
    --3way
    
    When the patch does not apply cleanly, fall back on 3-way merge
    


    Note: From Git Google Summer of Code 2009, there is a project to "Teach git-apply the 3-way merge fallback git-am knows":

    When git-apply patches file(s) the files may not patch cleanly. In such a case git-apply currently rejects the patch.
    If it is called from git-am then a 3-way merge is attempted by:

    • taking the "index ..." data from the patch and
    • constructing a temporary tree,
    • applying the patch to that, then
    • merging the temporary tree to the current branch.

    For various reasons it would be nice to do the entire temporary tree dance directly inside of git-apply, as it can benefit say the git-sequence's "apply" command, speed up git-am processing by forking less, etc

    Ghazaly : I tried git am -3 but the results were still the same but nonetheless, thanks for taking the time and effort.
  • I just tried this:

    rm -rf clone?
    
    # clone 1 is the working copy
    mkdir clone1
    (
        cd clone1
        git init
        echo foo >> file1
        git add file1
        git commit -m "Initial state"
    )
    
    # clone 2 is the staging repo
    git clone clone1 clone2
    
    # create patches
    (
        cd clone1
        git tag staging # tag to track what's in staging
    
        echo feature1 >> file1
        git add file1
        git commit -m "Feature 1"
    
        echo feature2 >> file1
        git add file1
        git commit -m "Feature 2"
    
        rm *.patch
        git format-patch staging
    )
    
    # apply patches
    (
        cd clone2
        git am ../clone1/*.patch
        # Cygwin/msysgit line ending weirdness when patching. Aborting and
        # reapplying clears it up.
        git am --abort 
        git am ../clone1/*.patch
        git log
        git status
    )
    

    Has the minor issue with the patches not applying clearly without doing the am twice, but I end up with a clean working dir in clone 2 with the right contents of file1. So there doesn't seem to be anything wrong with your workflow per se.

    Git apply will only update the working tree, not perform a commit.

    That said, I wouldn't use a git repository for staging. My workflow would probably make a release branch / fork of the development repository (or not), and just deploy full clean copies of that.

    For incremental updates to the staging environment, just use git tag staging in the release branch, "git diff staging..HEAD > update.patch" to email, and the standard unix "patch -p1" to apply it should work. That is unless you really need have the change history physically on the staging server.

    VonC : "Git apply will only"... "will only what" ? ;)
    Ghazaly : Thanks SiitheMoose, after trying out your example and getting no errors, I began to wonder what's wrong with my source files. That prompted me to re-edit my line endings and doing a "git am" works with no errors. I'm marking this answer correct since your suggestion works for my staging environment.
    VonC : Great test and description. +1

How to get UdpClient to react to DNS updates

I am using a UdpClient to send packets to a server. I am initializing the UdpClient upon construction of my Sender object, using the (hostname, port) constructor. When constructed in this manner, the UdpClient resolves the hostname to an IP address. Subsequent calls to the UdpClient object use the IP address.

Unfortunately, if the DNS alias used is updated through the DNS system to point to a different IP address, this change is not reflected in my Sender object unless it is re-created.

What would be the best way to have my Sender object react to DNS changes in a timely manner? Performance is very important. I can think of several solutions:

  1. Doing a DNS resolve on every call (i.e using the Send overload which accepts a hostname parameter). This may actually be quite fast because of the Windows DNS cache, I don't know.
  2. Having some sort of DNS checker running on a timer thread to check periodically if the DNS alias resolves to a different IP. If it does, it would somehow update the UdpClient to use the new IP Address. However, I don't really want to be locking the UdpClient object on every call - as I said, performance is important.

Anybody got any experience of doing this?

From stackoverflow
  • I would separate the address resolution from the UdpClient.

    1. Use Dns class to resolve IPaddress (and store in local variable)
    2. Use the parameterless constructor of UdpClient,
    3. Don't do a connect on UdpClient
    4. Use the explicit Send with the IPEndPoint parameter.

    On a background thread:

    1. check every X seconds for updated DNS
    2. replace the local IPEndPoint variable you pass to your UdpClient.Send call.

    No need to destroy your UdpClient every time you do this. Also, no need to lock when updating the IPEndPoint. The worse case is that you have one dirty send to an old address, but since you are not instantly notified on updates, you will have dirty sends anyway.

EntityFramework ObjectQuery<T>.Include With Filter ability

Hi, I'm using ObjectQuery.CreateQuery() to create eSQL query. I want to use the ObjcetQuery.Include to load related data, like Customer => Orders so let the EF to load all the orders for customer at the same time. The issue is that i don't want all the related objects and i want to fetch the result with condition.

Any idea?

From stackoverflow
  • Include will not work if you intend to materialize a master entity (Customer) with only some of the related child entities (Orders). The Entity Framework will not materialize a partially-complete type. Instead, I would recommend projecting into a new, anonymous type. Then you can include whichever Orders you like.

WCF Self Hosted App on 64bit Windows Server

I have a windows application that acts as a WCF Service that I developed on a 32bit Windows Server 2008 box. I have tested the application and everything works fine when running it from my development machine, as well as from my 32bit workstation. However, when attempting to run the application on a 64bit Windows 2008 Server, the application does not run, and a Windows Error Report is generated stating that the application stopped working. I have attempted to build the application on my 32bit Development Workstation, targeting both x86 and x64, to no avail. The only time I can get the application to run is if I comment out the code that starts the WCF Service. So my question is, do I need to dev and/or build this application on a 64bit workstation to allow the application to run on a 64bit machine?

From stackoverflow

Is there any way to put my custom name to LIB folder which i am going to place in WEB-INF folder of struts application?

Is there any way to put my custom name to LIB folder which i am going to place in WEB-INF folder of struts application?

From stackoverflow
  • And why on earth you wanna do that? FYI, its lib not LIB.

  • No.

    Or yes… if you don't want its contents on the classpath.

Is it possible to get upcoming event / show information from a Myspace page without scraping?

I want to get show information from myspace artists. One way I could do this is ask an artist to input their myspace URL and I could try to scrape the page.

What I would really like to do is ask the artist for their myspace credentials and use the myspace api to get their show data. I cannot find how to do this on the myspace developers site. Does anyone know?

And as a side question, if I decide to go the page scraping route, is that legal? I feel like a lot of people do this.

From stackoverflow
  • Try out http://livekick.com . It includes all music concerts posted on myspace.

  • Found this great article on just that: scraping myspace for tour dates. Haven't tested it but looks good. http://bit.ly/14HWWM

When to use boost thread join function?

I've recently managed to create a thread using the boost::bind function.

For the time being, I'm having the thread display to stdout. I can see the output if I use thread.join. However, if I don't do this, I don't see any output.

Why is this?

I'm hoping I don't have to use the join function, because I would like to call this function multiple times, without having to wait for the previously launched thread to finish.

Thanks for your responses. What I really wanted to make sure of was that the thread actually executed. So I added a system call to touch a non-existent file, and it was there afterwards, so the thread did execute.

From stackoverflow
  • I can see the output if I use thread.join. However, if I don't do this, I don't see any output. Why is this?

    Most probably this is a side-effect of the way standard output is buffered on your system. Do you have '\n' and/or endl sprinkled around in every print statement? That should force output (endl will flush the stream in addition).

    If you look at the documentation for join, you'd see that this function is called to wait till until termination of the thread. When a thread is terminated (or for that matter, a process) all buffered output is flushed.

    You do not need to wait till the thread has completed execution in order to see output. There are at least a couple of ways (I can remember off the top of my head) you can achieve this:

    • Make cout/stdout unbuffered, or
    • Use \n and fflush(stdout) (for C-style I/O) or std::endl stream manipulator
    Skurmedel : Maybe you should rephrase "is called to terminate a thread". join does not terminate the thread, but makes the current thread wait for the one the join-method was called on. Which I'm sure you are aware of.
    Skurmedel : "wait for the one the join-method was called on to terminate." (SO needs an edit comment button.)
    dirkgently : Yes, and yes again.
  • By default the thread object's destructor does not join to the main thread, could it be that your main thread terminates and closes STDOUT before the thread manages to flush its output?

    Note that in C++0x the default destructor for thread does join (rather than detach as in boost) so this will not happen (see A plea to reconsider detach-on-destruction for thread objects).

  • It may help to show some example code. I will guess that your main() may exit before your thread can print. The join call makes main wait for the thread to complete.

  • Maybe mail thread is finishing...Paste your code, so we can help you