CSE333 12au -- Homework #0

out: Monday September 4th, 2012
due: Wednesday September 6th, 2012 by 11:15am.

[ summary | part a | part b | how to submit | grading ]

Summary.

For homework #0, you will prepare a "Git" repository to use for the quarter, and you will also pull some code from a repository maintained by the course staff. Next, you will trivially modify a simple hello world C application and use "make" to compile it. Third, you will run the application to learn the magic code. Finally, you will push your changes to your repository as a way of submitting your code.

As you can probably tell, the goal of this homework is to make sure that all of the course infrastructure is working for you.

Part A -- preparing your git repositories

Overview

For this quarter, we will be using the "Git" distributed version control system to accomplish several tasks, as illustrated by the picture to the right:

  • You will create a "central" git repository of your own. This central repository will act as a clearinghouse, coordinating between you and the course staff, as well as between you and any project partners you eventually recruit. You (and later in the quarter, your project partner) will push your code modifications and additions into this central repository. Your central repository will live on CSE's servers, somewhere inside the /projects/instr/12au/cse333 directory.

  • On a machine of your choice, such as your laptop or a Linux virtual machine, you will create a local "working" git repository that you will use for doing your code editing and testing. You will pull code into your working git repository from your central repository, you will make and commit code modifications into your working repository, and you will push your commits back into your central repository. So, the "working" repository is something only you will interact with, and it is the place where you will spend most of your time editing code.

  • From time to time, you will pull code that we distribute from our "course" git repository into your working repository. (From there, our code will find its way into your central repository the next time you push your commits.) During the quarter, we will be handing out five programming project assignments, each of which builds upon the previous one. The assignments will consist of skeleton code that we provide to you that you must complete. To get the skeleton code, you will fetch the skeleton code from the course repository to your working repository.

  • When we are ready to grade one of your assignments, we will pull your code from your central repository.

Git is a complicated system, but we will be gentle in how we use it. If you are interested in learning more about Git, I recommend the following:

  • The Pro Git Book: an easy-to-understand overview of Git, and lots of details about how to use it in different ways.
  • Git for Computer Scientists: a very quick but detailed look at what's going on under the covers.
  • Git ready: a series of tutorials on how to accomplish specific tasks with Git. Very useful as a reference.
  • Git guys: a supposedly simplified tutorial on learning git.


Create your "central" repository

Each student enrolled in the class has been given their own unique UNIX group for this course. To find out which group you are a member of, look at this page. If you don't see your name on the list, please contact Steve immediately. You will create your central repository with the permissions of this UNIX group.

First, ssh into attu.cs.washington.edu. Next, run the following commands, replacing "cse333xx" with your UNIX group name.

bash:~%  chgrpsh +cse333xx
bash:~% cd /projects/instr/12au/cse333/cse333xx
bash:cse333xx% git init --bare --shared=group central.git
Initialized empty shared Git repository in /projects/instr/12au/cse333/cse333xx/central.git/
bash:cse333xx% chgrp -R cse333xx central.git
bash:cse333xx%  

If all went well, you've created your central repository!


Create and prepare your "working" repository

Your next job is to pick a CSE Linux machine to use to do your assignments. You have your choice of using a CSE virtual machine, one of the Linux-based workstations in the undergraduate labs, or ssh'ing into attu.cs. There is a link off of the course home page to instructions for downloading and configuring a CSE virtual machine; this is the path I'd recommend for you, since it will let you work off of your own computer anywhere you like.

Once you've picked your machine, log into it, and run the following commands to create your working repository. (Again, replace "cse333xx" with your UNIX group for the course. Also, replace "username" with your UNIX account name on attu.)

bash:~% cd ~
bash:~% git clone -o central ssh://username@attu.cs.washington.edu/projects/instr/12au/cse333/cse333xx/central.git cse333_working
Cloning into cse333_working...
warning: You appear to have cloned an empty repository.
bash:~%  

Next, you will create and commit a file to your working repository, and push into into your central repository. To do this, type the following commands, but replacing Steve's name and email address with your own:

bash:~% cd cse333_working
bash:cse333_working% echo "Steve Gribble -- gribble [at] cs.washington.edu" >> OWNERS.TXT
bash:cse333_working% git add OWNERS.TXT
bash:cse333_working% git commit -m "Added my OWNERS.TXT file"
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 OWNERS.TXT
bash:cse333_working% git push -u central master
Counting objects: 3, done.
Writing objects: 100% (3/3), 279 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://attu.cs.washington.edu/projects/instr/12au/cse333/cse333xx/central.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from central.
bash:cse333_working%  

After your git commit command, you might have seen some output complaining that your name and email address were configured automatically. If so, follow the instructions about using "git config" to configure your name and email address, and you won't see that complaint on commit anymore.

Your working repository is now set up. Your typical workflow will be to edit files locally and "git commit" your changes to your working repository. From time to time, you will invoke "git push" to push your changes from your working repository into your central repository. You should do this whenever you have made a large number of changes, or for when you eventually have a project partner, when you want to make your changes visible to him/her. (She/he will have to pull changes from the central repository to their working repository; we'll cover this later in the quarter.)


Fetch hw0 from the "course" repository

The files you need to actually do hw0 are distributed from the "course" git repository. In the following sequence of steps, you'll teach your working repository about the "course" repository, fetch files from it, and merge those files into a new branch in your working repository.

First, teach your working repo about the "course" repo and fetch content from it:

  bash:cse333_working% git remote add course http://www.cs.washington.edu/education/courses/cse333/12au/assignments/cse333.git
  bash:cse333_working% git fetch course
  From http://www.cs.washington.edu/education/courses/cse333/12au/assignments/cse333
   * [new branch]      hw0        -> course/hw0
  bash:cse333_working%  

Next, create a new branch in your working directory called "hw0", and merge the hw0 branch from the "course" repository into it:

bash:cse333_working% git checkout -b hw0
Switched to a new branch 'hw0'
bash:cse333_working% git merge course/hw0
Merge made by recursive.
 LICENSE.TXT       |  674 ++++++++++++
 clint.py          | 3127 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw0/.gitignore    |    2 +
 hw0/Makefile      |   18 +
 hw0/hello_world.c |   29 +
 5 files changed, 3850 insertions(+), 0 deletions(-)
 create mode 100644 LICENSE.TXT
 create mode 100755 clint.py
 create mode 100644 hw0/.gitignore
 create mode 100644 hw0/Makefile
 create mode 100644 hw0/hello_world.c
bash:cse333_working%  
Finally, push your new branch (with its merged content) back into your central repository:
bash:cse333-working% git push -u central hw0
Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 49.64 KiB, done.
Total 10 (delta 1), reused 0 (delta 0)
To ssh://attu.cs.washington.edu/projects/instr/12au/cse333/cse333xx/central.git
 * [new branch]      hw0 -> hw0
Branch hw0 set up to track remote branch hw0 from central.
bash:cse333_working%  

Take a look around inside your working repository. You should see the OWNERS.TXT file that you created, as well as a number of files and subdirectories that you fetched from the course directory. For example, you'll see a LICENSE.TXT file and a hw0 subdirectory. Look inside that subdirectory, and you'll see a Makefile, hello_world.c, and if you do a "ls -al" in there, you'll also notice a ".gitignore" file.

That's it for part A of hw0...phew!

Part B -- edit, compile, and run hello_world

In your working repository, cd into the hw0 directory and type "make". This command will use the instructions in the Makefile to compile the hello_world application using the gcc compiler. Run hello_world by typing the command "./hello_world". You should see one line of output that looks like:

bash:hw0% ./hello_world
The magic code is: <xxxxx>
bash:hw0%

for some <xxxxx>. Now, edit hello_world.c using your favorite Unix-based editor (mine is emacs), and change the printf so that it instead says:

bash:hw0% ./hello_world
The magic word is: <xxxxx>
bash:hw0% 

Type "make" to recompile and re-run hello_world to make sure it does what you expect.

Throughout the quarter, we'll also be testing whether your code has any memory leaks. We'll be using Valgrind to do this. To try out Valgrind for yourself, run the following command:

bash:hw0% valgrind --leak-check=full ./hello_world

Note that Valgrind prints out that no memory leaks were found.

Next, commit your change to hello_world.c to your working repository:

bash:hw0% git add hello_world.c
bash:hw0% git commit -m 'changed code to word'
 1 files changed, 1 insertions(+), 1 deletions(-)
bash:hw0%  

Here, the "git add" command tells your working repository that there are changes to the hello_world.c file that you would like to include in your next commit. If you've modified multiple files, you can "git add" each of them to include them in the next commit. The "git commit" command actually commits the changes to the working repository.

You can keep track of your changes by using the git diff command. Running "git diff" will display the changes to your code since your last commit, and running the command "git diff course/hw0" will display the changes relative to the initial code supplied for this lab through the "course" repo.

Turn in

When you're ready to turn in your assignment, do the following:

  1. In the hw0 directory within your working repository, run "make clean" to clean out any object files and emacs detritus; what should be left is your source file, the Makefile, and the .gitignore file.

  2. Create a README.TXT file in hw0 that contains your name, student number, and UW email address. As well, write a sentence that reveals the magic word you learned from Part B. Use "git add README.TXT" to teach git about your readme file, and then "git commit" to commit your changes. git commit will bring up an editor for you to type your commit message.

  3. Create a "tag" in your working repository called "hw0_submit" in order to mark the version contour that you want us to grade:
    bash:hw0% git tag -a hw0_submit -m "This is my hw0 submission"
    bash:hw0%  

  4. Push all of the changes you made to the hw0 branch of your working repository into the hw0 branch of your "central" repository:
    bash:hw0% git push --all
    Counting objects: 7, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 352 bytes, done.
    Total 4 (delta 3), reused 0 (delta 0)
    To ssh://attu.cs.washington.edu/projects/instr/12au/cse333/cse333xx/central.git
       587311b..60a368e  hw0 -> hw0
    bash:hw0% 

  5. Push the tag that you created into your "central" repository:
    bash:hw0% git push --tags
    Counting objects: 1, done.
    Writing objects: 100% (1/1), 176 bytes, done.
    Total 1 (delta 0), reused 0 (delta 0)
    To ssh://attu.cs.washington.edu/projects/instr/12au/cse333/cse333xx/central.git
     * [new tag]         hw0_submit -> hw0_submit
    bash:hw0% 

  6. Fill out the following survey to give us feedback on your background, which will help us tune future assignments:
    https://catalyst.uw.edu/webq/survey/gribble/176977

That's it! We will be pulling from your central repository to verify that you finished hw0 correctly.

Grading

For hw0, we'll give you 1 point if you learn the magic code, commit and push your changes correctly and on time, and submit the survey.