COMP9041 Assignment 1 LeGit solved

Original price was: $35.00.Current price is: $28.00.



5/5 - (1 vote)


This assignment aims to give you
practice in Perl programming generally
introduce you to git & give you a clear concrete understanding of it basic semantics

Note: the material in the lecture notes will not be sufficient by itself to allow you to complete
this assignment. You may need to search on-line documentation for Perl, git etc. Being able to
search documentation efficiently for the information you need is a very useful skill for any kind of
computing work.


Your task in this assignment is to write a Perl program which implements a subset of the
version control system Git
Git is a very complex program which has many individual commands. You will implement only a
few of the most importnat commands.
You will be given a number of simplifying assumptions which make your task easier.

Reference implementation

Many aspects of this assignment are not fully specified in this document.
Instead you must match the behaviour of a reference implementation –
Provision of a reference implementation is a common method to provide an operational
specification, and it something you will likely need to do after you leave UNSW.

Discovering & matching the reference implementation’s behaviour is deliberately part of the
Your Perl script should match the behaviour of /home/cs2041/bin/legit exactly,
including for example proiducing the same error messages.

The reference implementation is a wrapper around git, so tutorials for the equivalent git
commands will help you understand the reference implementation. For example this Meet Git
video from Atlassian:

While the code in the reference implementation is fairly straight forward, reverse-engineering its
behaviour is obviously not so simple and it’s a nice example of how coming to grips with the
precise semantics of an apparently obvious task can still be challenging.

If you discover what you believe to be a bug in the reference implementation, report it in the
class forum. Andrew may be fix the bug or indicate that you do not need to match the reference
implementation’s behaviour in this case.
Legit Commands – Subset 0 init
The init command creates an empty Legit repository. should create a directory named .legit which it will use to store the repository.
It should produce an error message if this directory already exists. You should match this and
other error messages exactly. For example:
$ ls -l .legit
ls: cannot access .legit: No such file or directory
$ ./ init
Initialized empty legit repository in .legit
$ ls -d .legit
$ ./ init error: .legit already exists may create initial files or directories inside .legit.
You do not have to use a particular representation to store the repository.

You do not have to create the same files or directory inside .legit as the reference
implementation. add filenames
The add command adds the contents of one or more files to the “index”.
Files are added to the repository in a two step process. The first step is adding them to the

You will need to store files in the index somehow in the .legit sub-directory. For example you
might choose store them in a sub-directory of .legit.
Only ordinary files in the current directory can be added, and their names will always start with
an alphanumeric character ([a-zA-Z0-9]) and will only contain alpha-numeric characters plus ‘.’,
‘-‘ and ‘_’ characters.

The add command, and other command, will not be given pathnames with slashes. commit -m message
The commit command saves a copy of all files in the index to the repository.
A message describing the commit must be included as part of the commit command. commits are numbered (not hashes like git). You must match the numbering scheme.
You can assume the commit message is ASCII and does not contain new-line characters. log log prints one line for every commit that has been made to the repository.
Each line should contains the commit number and the commit message. show commit:filename show should print the contents of the specified file as of the specified commit.
If the commit is omitted the contents of the file in the index should be printed.
For example:
$ ./ init
Initialized empty legit repository in .legit
$ echo line 1 > a

$ echo hello world >b
$ ./ add a b
$ ./ commit -m ‘first commit’
Commited as commit 0
$ echo line 2 >>a
$ ./ add a
$ ./ commit -m ‘second commit’

Commited as commit 1
$ ./ log
1 second commit
0 first commit
$ echo line 3 >>a
$ ./ add a
$ echo line 4 >>a

$ ./ show 0:a
line 1
$ ./ show 1:a
line 1
line 2
$ ./ show :a
line 1
line 2

Legit Commands – Subset 1 commit [-a] -m message commit can have -a options which causes all files already in the index to have their
current state added to the index. rm [–force] [–cached] filenames rm removes a file from the current directory or from the current directory and the index status status show the status of files in the current directory, index, and repository.
$ ./ init
Initialized empty legit repository in .legit
$ touch a b c d e f g h
$ ./ add a b c d e f

$ ./ commit -m ‘first commit’
Commited as commit 0
$ echo hello >a
$ echo hello >b
$ echo hello >c
$ ./ add a b

$ echo world >a
$ rm d
$ ./ rm e
$ ./ add g

$ ./ status
a – file modified and changes in index
b – file modified
c – changes in index
d – file deleted
e – deleted

f – same as repo
g – added to index
h – untracked – untracked
Legit Commands – Subset 2 branch [-d] [branch-name] branch either creates a branch, deletes a branch or lists current branch-names. checkout branch-name checkout switches branches. merge branch-name|commit merge -m message adds the changes that have been made to specified branch or
commit to the index and commits them.

$ ./ init
Initialized empty legit repository in .legit
$ seq 1 7 >7.txt
$ ./ add 7.txt
$ ./ commit -m commit-1
Commited as commit 0

$ ./ branch b1
$ ./ checkout b1
Switched to branch ‘b1’
$ perl -pi -e ‘s/2/42/’ 7.txt
$ cat 7.txt
$ ./ commit -a -m commit-2

Commited as commit 1
$ ./ checkout master
Switched to branch ‘master’
$ cat 7.txt


If a file contains conflicting changes merge produces an error message.
$ ./ init
Initialized empty legit repository in .legit
$ seq 1 7 >7.txt
$ ./ add 7.txt
$ ./ commit -m commit-1
Commited as commit 0

$ ./ branch b1
$ ./ checkout b1
Switched to branch ‘b1’
$ perl -pi -e ‘s/2/42/’ 7.txt
$ cat 7.txt
$ ./ commit -a -m commit-2
Commited as commit 1
$ ./ checkout master
Switched to branch ‘master’
$ cat 7.txt

Legit – Challenge
Often commits involve small changes to large files.
Can you use a data representations such that a commit involving a small change to a large file
use only small amount of extra space.


You must keep notes of each piece of you make work on this assignment. The notes should
include date, starting & finishing time, and a brief description of the work carried out. For
Date Start Stop Activity Comments
29/09/17 16:00 17:30 coding implemented assignment statements
30/09/17 20:00 10:30 debugging found bug in while loops
Include these notes in the files you submit as an ASCII file named diary.txt.


As usual some autotests will be available:
$ 2041 autotest legit
You will need to do most of the testing yourself.
Test Scripts
You should submit ten Shell scripts named .. which run legit
commands which test an aspect of Legit.

The test??.sh scripts do not have to be examples that your program implements successfully.
You may share your test examples with your friends but the ones you submit must be your own
The test scripts should show how you’ve thought about testing carefully.


Like all good programmers, you should make as few assumptions as possible. Your assignment
must be entirely written in Perl.
It must not run external programs (e.g. via system or back-quotes).
Your program will be run with version of Perl installed on CSE lab machines.

You may write scripts in Shell or other languages to assist in testing your assignment.
You may only use Perl packages which are installed on CSE’s lab computers.
You may submit multiple Perl files but the primary file must be named
You assume is always run in the same directory as the repository and only files from
that directory are added to the repository.

You can assume that the directory in which is run will not contain sub-directories apart
from .legit.
You can assume that the filenames in the directory in which is run all start with an
alphanumeric character ([a-zA-Z0-9]) and will only contain alpha-numeric characters plus ‘.’, ‘-‘
and ‘_’.

The which are given filenames (add, show, rm) with be given just the filename, not
pathnames with slashes .
You do not have to consider file permissions or other file metadata, for example you do not have
to ensure files created by a checkout command have the same permisisons as when they were

Attribution of Work

This is an individual assignment. The work you submit must be your own work and only your
work apart from any exceptions explicitly include in the assignment specification above.
Joint work is not permitted.
You are only permitted to request help with the assignment in the course forum, help sessions or
from course lecturers or tutors.

Do not provide or show your assignment work to any other person (including by posting it on the
forum) apart from the teaching staff of COMP[29]041.
The work you submit must otherwise be entirely your own work. Submission of work partially or
completely derived from any other person or jointly written with any other person is not

The penalties for such an offence may include negative marks, automatic failure of
the course and possibly other academic discipline. Assignment submissions will be examined
both automatically and manually for such submissions.

We are required to inform scholarship authorities if students holding scholarships are involved in
an incident of plagiarism or other misconduct, and this may result in a loss of the scholarship.
Plagiarism or other misconduct can also result in loss of student visas.

If you knowingly provide or show your assignment work to another person for any reason, and
work derived from it is submitted you may be penalized, even if the work was submitted without
your knowledge or consent. This may apply even if your work is submitted by a third party
unknown to you.

Note, you will not be penalized if your work is taken without your consent or knowledge.

Submission of Work

You are required to submit intermediate versions of your assignment.
Every time you work on the assignment and make some progress you should copy your work to
your CSE account and submit it using the give command below.

It is fine if intermediate versions do not compile or otherwise fail submission tests.
Only the final submitted version of your assignment will be marked.
All these intermediate versions of your work will be placed in a git repo and made available to
you via a web interface at this URL, replace z5555555 with your zpass.

This will allow you to retrieve earlier versions of your code if needed.
You submit your work like this:
$ give cs2041 ass1_legit test*.sh diary.txt


This assignment will contribute 15 marks to your final COMP[29]041 mark
15% of the marks for assignment 1 will come from hand marking. These marks will be awarded
on the basis of clarity, commenting, elegance and style. In other words, you will be assessed on
how easy it is for a human to read and understand your program.

5% of the marks for assignment 1 will be based on the test suite you submit.
80% of the marks for assignment 1 will come from the performance of your code on a large
series of tests.
HD+ 100 All subsets working & challenge, is beautiful, great test suite &
HD (90) Subset 2 working, is very clear & very readable, very good test
suite & diary

DN (80) Subset 1 working, is good clear code, good test suite & diary
CR (70) Subset 0 working, is good clear code, good test suite & diary
PS (60) Subset 0 passing some tests, is reasonably readable, reasonable
test suite & diary

PS (55) Subset 0 working internally (storing data) put not passing tests
0% Knowingly providing your work to anyone and it is subsequently
submitted (by anyone).
0 FL for
Submitting any other person’s work. This includes joint work.


Submitting another person’s work without their consent. Paying another
person to do work for you.
The lecturer may vary the assessment scheme after inspecting the assignment submissions but
its likely to be broadly similar to the above.
Due Date

This assignment is tentatively due Wednesday 03 October 23:59:59
If your assignment is submitted after this date, each hour it is late reduces the maximum mark it
can achieve by 2%. For example if an assignment worth 74% was submitted 10 hours late, the
late submission would have no effect.

If the same assignment was submitted 15 hours late it
would be awarded 70%, the maximum mark it can achieve at that time.