gtx


  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
package main

import (
	"crypto/sha1"
	_ "embed"
	"encoding/hex"
	"errors"
	"flag"
	"io"
	"io/fs"
	"log"
	"os"
	"path/filepath"
	"text/template"

	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/plumbing/object"
)

// CONFIG_FILE=".ht_git2html"
const configFile = ".ht_git2html"

/*
show_progress=1
force_rebuild=0
*/
const showProgress = true
const forceRebuild = false

// TODO: add log.Debug
/*
 progress()
 {
   if test x"$show_progress" = x1
   then
     echo "$@"
   fi
 }
*/

//go:embed config.tmpl
var tmpl string

type options struct {
	project  string
	repo     string
	link     string
	branches string
	quiet    bool
	force    bool
}

/*
usage()

	{
	  echo "Usage $0 [-prlbq] TARGET"
	  echo "Generate static HTML pages in TARGET for the specified git repository."
	  echo
	  echo "  -p  Project's name"
	  echo "  -r  Repository to clone from."
	  echo "  -l  Public repository link, e.g., 'http://host.org/project.git'"
	  echo "  -b  List of branches to process (default: all)."
	  echo "  -q  Be quiet."
	  echo "  -f  Force rebuilding of all pages."
	  exit $1
	}
*/
func main() {
	/*
	   while getopts ":p:r:l:b:qf" opt
	   do
	     case $opt in
	       p)
	         PROJECT=$OPTARG
	         ;;
	       r)
	         # Directory containing the repository.
	         REPOSITORY=$OPTARG
	         ;;
	       l)
	         PUBLIC_REPOSITORY=$OPTARG
	         ;;
	       b)
	         BRANCHES=$OPTARG
	         ;;
	       q)
	         show_progress=0
	         ;;
	       f)
	         force_rebuild=1
	         ;;
	       \?)
	         echo "Invalid option: -$OPTARG" >&2
	         usage
	         ;;
	     esac
	   done
	   shift $(($OPTIND - 1))
	*/
	opts := &options{}

	flag.StringVar(&opts.project, "p", "My project", "Project's name")
	flag.StringVar(&opts.repo, "r", "/path/to/repo", "Repository to clone from.")
	flag.StringVar(&opts.link, "l", "http://host.org/project.git", "Public repository link, e.g., 'http://host.org/project.git'")
	flag.StringVar(&opts.branches, "b", "all", "List of branches (default: all)")
	flag.BoolVar(&opts.quiet, "q", false, "Be quiet.")
	flag.BoolVar(&opts.force, "f", false, "Force rebuilding of all pages.")
	flag.Parse()

	// TODO: print usage?
	/*
	   if test $# -ne 1
	   then
	     usage 1
	   fi
	*/

	log.Printf("+%v", opts)

	args := os.Args

	// TODO: check only one target
	// if len(args) != 2 {
	// 	log.Fatalf("jimmy: please specify a single target path")
	// }

	//# Where to create the html pages.
	//TARGET="$1"
	targetDir := args[len(args)-1]

	//# Make sure TARGET is an absolute path.
	/*
	   if test x"${TARGET%%/*}" != x
	   then
	       TARGET=$(pwd)/$TARGET
	   fi
	*/

	if ok := filepath.IsAbs(targetDir); !ok {
		cwd, err := os.Getwd()

		if err != nil {
			log.Fatalf("jimmy: %v", err)
		}

		targetDir = filepath.Join(cwd, targetDir)
	}

	//# Make sure the target exists.
	//mkdir -p "$TARGET"

	// TODO: Look up more mode for 755 or 644.
	if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
		log.Fatalf("jimmy: unable to create target directory: %v", err)
	}

	//# Read the configuration file.
	/*
	   if test -e "$TARGET/$CONFIG_FILE"
	   then
	     . "$TARGET/$CONFIG_FILE"
	   fi
	*/
	// TODO: Read config file

	// TODO: Check repository is required
	/*
	   if test x"$REPOSITORY" = x
	   then
	     echo "-r required."
	     echo
	     usage 1
	   fi
	*/

	writeConfigFile(targetDir, opts)

	// TODO: check how to make -r arg mandatory
	/*
	   if test ! -d "$REPOSITORY"
	   then
	     echo "Repository \"$REPOSITORY\" does not exists.  Misconfiguration likely."
	     exit 1
	   fi
	*/

	createDirectories(targetDir, opts.force)

	setUpRepo(targetDir, opts)

	setGitConfig()

	cleanBranches := cleanUpBranches(opts.branches)

	fetchBranches(cleanBranches)

	writeIndex()

	doTheRealWork()

	writeIndexFooter()
}

func writeConfigFile(targetDir string, opts *options) {
	/*
	   # The output version
	   CURRENT_TEMPLATE="$(sha1sum "$0")"
	   if test "x$CURRENT_TEMPLATE" != "x$TEMPLATE"
	   then
	     progress "Rebuilding all pages as output template changed."
	     force_rebuild=1
	   fi
	   TEMPLATE="$CURRENT_TEMPLATE"
	*/
	configTmpl := template.Must(template.New("default").Parse(tmpl))

	// TODO: Check file permissions are set to 0666.
	// TODO: Read file if it exists.
	outFile, err := os.Create(filepath.Join(targetDir, configFile))

	if err != nil {
		log.Fatalf("jimmy: unable to create config file: %v", err)
	}

	h := sha1.New()

	// (spike): why did we do this step?
	if _, err := io.Copy(h, outFile); err != nil {
		log.Fatal(err)
	}

	/*
	   {
	     save()
	     {
	       # Prefer environment variables and arguments to the configuration file.
	       echo "$1=\"\${$1:-\"$2\"}\""
	     }
	     save "PROJECT" "$PROJECT"
	     save "REPOSITORY" "$REPOSITORY"
	     save "PUBLIC_REPOSITORY" "$PUBLIC_REPOSITORY"
	     save "TARGET" "$TARGET"
	     save "BRANCHES" "$BRANCHES"
	     save "TEMPLATE" "$TEMPLATE"
	   } > "$TARGET/$CONFIG_FILE"
	*/
	configTmpl.Execute(outFile, struct {
		Project          string
		Repository       string
		PublicRepository string
		Target           string
		Branches         string
		// SHA1SUM
		Template string
	}{
		Project:          opts.project,
		Repository:       opts.repo,
		PublicRepository: opts.link,
		Target:           targetDir,
		Branches:         opts.branches,
		Template:         hex.EncodeToString(h.Sum(nil)),
	})
}

func createDirectories(targetDir string, force bool) {
	//# Ensure that some directories we need exist.
	/*
	   if test x"$force_rebuild" = x1
	   then
	     rm -rf "$TARGET/objects" "$TARGET/commits"
	   fi

	   if test ! -d "$TARGET/objects"
	   then
	     mkdir "$TARGET/objects"
	   fi

	   if test ! -e "$TARGET/commits"
	   then
	     mkdir "$TARGET/commits"
	   fi

	   if test ! -e "$TARGET/branches"
	   then
	     mkdir "$TARGET/branches"
	   fi
	*/

	// Repository
	dirs := []string{"branches", "commits", "objects"}

	for _, dir := range dirs {
		d := filepath.Join(targetDir, dir)

		// Clear existing dirs if force true.
		if force && dir != "branches" {
			if err := os.RemoveAll(d); err != nil {
				log.Printf("jimmy: unable to remove directory: %v", err)
			}
		}

		if err := os.MkdirAll(d, os.ModePerm); err != nil {
			log.Printf("jimmy: unable to create directory: %v", err)
		}
	}
}

func setUpRepo(targetDir string, opts *options) {
	var pathError *fs.PathError
	repoPath := filepath.Join(targetDir, "repository")

  _, err := os.Stat(repoPath)

	if errors.As(err, &pathError) {
		localRepo, err := git.PlainClone(repoPath, false, &git.CloneOptions{
			URL:      opts.repo,
			Progress: os.Stdout,
		})

		commitObjects, err := localRepo.CommitObjects()

		if err != nil {
			log.Printf("%v", err)
		}

		commitObjects.ForEach(func(c *object.Commit) error {
			log.Print(c)
			return nil
		})

		localBranches, err := localRepo.Branches()

		if err != nil {
			log.Printf("%v", err)
		}

		branch, err := localBranches.Next()

		if err != nil {
			log.Printf("jimmy: failed to list branches: %v", err)
		}

		ref := plumbing.NewHashReference(branch.Name(), branch.Hash())

		if err != nil {
			log.Printf("jimmy: failed to create ref: %v", err)
		}

		workTree, err := localRepo.Worktree()

		if err != nil {
			log.Printf("jimmy: failed to open worktree: %v", err)
		}

		err = workTree.Checkout(&git.CheckoutOptions{
			Hash: ref.Hash(),
		})

		if err != nil {
			log.Printf("jimmy: failed to checkout detached HEAD: %v", err)
		}

		err = localRepo.Storer.RemoveReference(ref.Name())

		if err != nil {
			log.Printf("jimmy: failed to delete branch: %v", err)
		}
	}
}

// TODO: implement!
func setGitConfig() {
	/*
	   # git merge fails if there are not set.  Fake them.
	   git config user.email "git2html@git2html"
	   git config user.name "git2html"
	*/
}

// TODO: implement!
func cleanUpBranches(branches string) []string {
	/*
	   if test x"$BRANCHES" = x
	   then
	     # Strip the start of lines of the form 'origin/HEAD -> origin/master'
	     BRANCHES=$(git branch --no-color -r \
	                  | sed 's#.*->##; s#^ *origin/##;')
	   fi

	   first=""
	   # Ignore 'origin/HEAD -> origin/master'
	   for branch in ${BRANCHES:-$(git branch --no-color -r \
	                                 | sed 's#.*->.*##;
	                                        s#^ *origin/##;
	                                        s#^ *HEAD *$##;')}
	   do
	     first="$branch"
	     break
	   done

	   # Due to branch aliases (a la origin/HEAD), a branch might be listed
	   # multiple times.  Eliminate this possibility.
	   BRANCHES=$(for branch in $BRANCHES
	     do
	       echo "$branch"
	     done | sort | uniq)
	*/
	return []string{}
}

// TODO: implement!
func fetchBranches(branches []string) {
	/*
	   	   for branch in $BRANCHES
	   	   do
	   	     # Suppress already up to date status messages, but don't use grep -v
	   	     # as that returns 1 if there is no output and causes the script to
	   	     # abort.
	   	     git fetch --force origin "refs/heads/${branch}:refs/origin/${branch}" \
	   	         | gawk '/^Already up-to-date[.]$/ { skip=1; }
	   	                 { if (! skip) print; skip=0 }'
	   	   done
	   	   git checkout "origin/$first"
	      }

	   	   # For each branch and each commit create and extract an archive of the form
	   	   #   $TARGET/commits/$commit
	   	   #
	   	   # and a link:
	   	   #
	   	   #   $TARGET/branches/$commit -> $TARGET/commits/$commit

	   	   # Count the number of branch we want to process to improve reporting.
	   	   bcount=0
	   	   for branch in $BRANCHES
	   	   do
	   	     let ++bcount
	   	   done
	*/
}

// TODO: implement!
func writeIndex() {
	/*
	   INDEX="$TARGET/index.html"

	   {
	     html_header

	     if test -e "$REPOSITORY/description"
	     then
	       echo "<h2>Description</h2>"
	       cat "$REPOSITORY/description"
	     fi

	     echo "<h2>Repository</h2>"
	     if test x"$PUBLIC_REPOSITORY" != x
	     then
	       echo  "Clone this repository using:" \
	         "<pre>" \
	         " git clone $PUBLIC_REPOSITORY" \
	         "</pre>"
	     fi

	     echo "<h2>Branches</h2>" \
	       "<ul>"
	   } > "$INDEX"

	*/
}

// TODO: implement!
func doTheRealWork() {
	/*
	   b=0
	   for branch in $BRANCHES
	   do
	     let ++b

	     cd "$TARGET/repository"

	     COMMITS=$(mktemp)
	     git rev-list --graph "origin/$branch" > $COMMITS

	     # Count the number of commits on this branch to improve reporting.
	     ccount=$(egrep '[0-9a-f]' < $COMMITS | wc -l)

	     progress "Branch $branch ($b/$bcount): processing ($ccount commits)."

	     BRANCH_INDEX="$TARGET/branches/$branch.html"

	     c=0
	     while read -r commitline
	     do
	       # See http://www.itnewb.com/unicode
	       graph=$(echo "$commitline" \
	               | sed 's/ [0-9a-f]*$//; s/|/\&#x2503;/g; s/[*]/\&#x25CF;/g;
	                      s/[\]/\&#x2B0A;/g; s/\//\&#x2B0B;/g;')
	*/
	//    commit=$(echo "$commitline" | sed 's/^[^0-9a-f]*//')
	/*
	     if test x"$commit" = x
	     then
	       # This is just a bit of graph.  Add it to the branch's
	       # index.html and then go to the next commit.
	       echo "<tr><td valign=\"middle\"><pre>$graph</pre></td><td></td><td></td><td></td></tr>" \
	   >> "$BRANCH_INDEX"
	       continue
	     fi

	     let ++c
	     progress "Commit $commit ($c/$ccount): processing."

	     # Extract metadata about this commit.
	     metadata=$(git log -n 1 --pretty=raw $commit \
	         | sed 's#<#\&lt;#g; s#>#\&gt;#g; ')
	     parent=$(echo "$metadata" \
	   | gawk '/^parent / { $1=""; sub (" ", ""); print $0 }')
	     author=$(echo "$metadata" \
	   | gawk '/^author / { NF=NF-2; $1=""; sub(" ", ""); print $0 }')
	     date=$(echo "$metadata" | gawk '/^author / { print $(NF=NF-1); }')
	     date=$(date -u -d "1970-01-01 $date sec")
	     log=$(echo "$metadata" | gawk '/^    / { if (!done) print $0; done=1; }')
	     loglong=$(echo "$metadata" | gawk '/^    / { print $0; }')

	     if test "$c" = "1"
	     then
	       # This commit is the current head of the branch.  Update the
	       # branch's link, but don't use ln -sf: because the symlink is to
	       # a directory, the symlink won't be replaced; instead, the new
	       # link will be created in the existing symlink's target
	       # directory:
	       #
	       #   $ mkdir foo
	       #   $ ln -s foo bar
	       #   $ ln -s baz bar
	       #   $ ls -ld bar bar/baz
	       #   lrwxrwxrwx 1 neal neal 3 Aug  3 09:14 bar -> foo
	       #   lrwxrwxrwx 1 neal neal 3 Aug  3 09:14 bar/baz -> baz
	       rm -f "$TARGET/branches/$branch"
	       ln -s "../commits/$commit" "$TARGET/branches/$branch"

	       # Update the project's index.html and the branch's index.html.
	       echo "<li><a href=\"branches/$branch.html\">$branch</a>: " \
	         "<b>$log</b> $author <i>$date</i>" >> "$INDEX"

	       {
	         html_header "Branch: $branch" ".."
	   echo "<p><a href=\"$branch/index.html\">HEAD</a>"
	         echo "<p><table>"
	       } > "$BRANCH_INDEX"
	     fi

	     # Add this commit to the branch's index.html.
	     echo "<tr><td valign=\"middle\"><pre>$graph</pre></td><td><a href=\"../commits/$commit/index.html\">$log</a></td><td>$author</td><td><i>$date</i></td></tr>" \
	   >> "$BRANCH_INDEX"


	     # Commits don't change.  If the directory already exists, it is up
	     # to date and we can save some work.
	     COMMIT_BASE="$TARGET/commits/$commit"
	     if test -e "$COMMIT_BASE"
	     then
	       progress "Commit $commit ($c/$ccount): already processed."
	       continue
	     fi

	     mkdir "$COMMIT_BASE"

	     # Get the list of files in this commit.
	     FILES=$(mktemp)
	     git ls-tree -r "$commit" > "$FILES"

	     # Create the commit's index.html: the metadata, a summary of the changes
	     # and a list of all the files.
	     COMMIT_INDEX="$COMMIT_BASE/index.html"
	     {
	       html_header "Commit: $commit" "../.."

	       # The metadata.
	       echo "<h2>Branch: <a href=\"../../branches/$branch.html\">$branch</a></h2>" \
	   "<p>Author: $author" \
	   "<br>Date: $date" \
	         "<br>Commit: $commit"
	       for p in $parent
	       do
	         echo "<br>Parent: <a href=\"../../commits/$p/index.html\">$p</a>" \
	   " (<a href=\"../../commits/$commit/diff-to-$p.html\">diff to parent</a>)"
	       done
	       echo "<br>Log message:" \
	   "<p><pre>$loglong</pre>"
	       for p in $parent
	       do
	   echo "<br>Diff Stat to $p:" \
	     "<blockquote><pre>"
	         git diff --stat $p..$commit \
	           | gawk \
	               '{ if (last_line) print last_line;
	                  last_line_raw=$0;
	                  $1=sprintf("<a href=\"%s.raw.html\">%s</a>" \
	                             " (<a href=\"../../commits/'"$p"'/%s.raw.html\">old</a>)" \
	                             "%*s" \
	                             "(<a href=\"diff-to-'"$p"'.html#%s\">diff</a>)",
	                             $1, $1, $1, 60 - length ($1), " ", $1);
	                     last_line=$0; }
	                   END { print last_line_raw; }'
	         echo "</pre></blockquote>"
	       done
	       echo "<p>Files:" \
	         "<ul>"

	       # The list of files as a hierarchy.  Sort them so that within a
	       # directory, files preceed sub-directories
	       sed 's/\([^ \t]\+[ \t]\)\{3\}//;
	*/
	//                 s#^#/#; s#/\([^/]*/\)#/1\1#; s#/\([^/]*\)$#/0\1#;' \
	/*
	         < "$FILES" \
	   | sort | sed 's#/[01]#/#g; s#^/##' \
	   | gawk '
	          function spaces(l) {
	            for (space = 1; space <= l; space ++) { printf ("  "); }
	          }
	          function max(a, b) { if (a > b) { return a; } return b; }
	          function min(a, b) { if (a < b) { return a; } return b; }
	          function join(array, sep, i, s) {
	            s="";
	            for (i in array) {
	              if (s == "")
	                s = array[i];
	              else
	                s = s sep array[i];
	            }
	            return s;
	          }
	          BEGIN {
	            current_components[1] = "";
	            delete current_components[1];
	          }
	          {
	            file=$0;
	            split(file, components, "/")
	            # Remove the file.  Keep the directories.
	            file=components[length(components)]
	            delete components[length(components)];

	            # See if a path component changed.
	            for (i = 1;
	                 i <= min(length(components), length(current_components));
	                 i ++)
	            {
	              if (current_components[i] != components[i])
	                # It did.
	                break
	            }
	            # i-1 is the last common component.  The rest from the
	            # current_component stack.
	            last=length(current_components);
	            for (j = last; j >= i; j --)
	            {
	              spaces(j);
	              printf ("</ul> <!-- %s -->\n", current_components[j]);
	              delete current_components[j];
	            }

	            # If there are new path components push them on the
	            # current_component stack.
	            for (; i <= length(components); i ++)
	            {
	                current_components[i] = components[i];
	                spaces(i);
	                printf("<li><a name=\"files:%s\">%s</a>\n",
	                       join(current_components, "/"), components[i]);
	                spaces(i);
	                printf("<ul>\n");
	            }

	            spaces(length(current_components))
	            printf ("<li><a name=\"files:%s\" href=\"%s.raw.html\">%s</a>\n",
	                    $0, $0, file);
	            printf ("  (<a href=\"%s\">raw</a>)\n", $0, file);
	          }
	          END {
	            for (i = length(current_components); j >= 1; j --)
	            {
	              spaces(j);
	              printf ("</ul> <!-- %s -->\n", current_components[j]);
	              delete current_components[j];
	            }
	          }'

	     echo "</ul>"
	     html_footer
	   } > "$COMMIT_INDEX"

	   # Create the commit's diff-to-parent.html file.
	   for p in $parent
	   do
	     {
	*/
	//        html_header "diff $(echo $commit | sed 's/^\(.\{8\}\).*/\1/') $(echo $p | sed 's/^\(.\{8\}\).*/\1/')" "../.."
	/*
	           echo "<h2>Branch: <a href=\"../../branches/$branch.html\">$branch</a></h2>" \
	             "<h3>Commit: <a href=\"index.html\">$commit</a></h3>" \
	       "<p>Author: $author" \
	       "<br>Date: $date" \
	       "<br>Parent: <a href=\"../$p/index.html\">$p</a>" \
	       "<br>Log message:" \
	       "<p><pre>$loglong</pre>" \
	       "<p>" \
	             "<pre>"
	           git diff -p $p..$commit \
	             | sed 's#<#\&lt;#g; s#>#\&gt;#g;
	                    s#^\(diff --git a/\)\([^ ]\+\)#\1<a name="\2">\2</a>#;
	                    s#^\(\(---\|+++\|index\|diff\|deleted\|new\) .\+\)$#<b>\1</b>#;
	                    s#^\(@@ .\+\)$#<font color=\"blue\">\1</font>#;
	                    s#^\(-.*\)$#<font color=\"red\">\1</font>#;
	                    s#^\(+.*\)$#<font color=\"green\">\1</font>#;' \
	             | gawk '{ ++line; printf("%5d: %s\n", line, $0); }'
	           echo "</pre>"
	           html_footer
	         } > "$COMMIT_BASE/diff-to-$p.html"
	       done


	       # For each file in the commit, ensure the object exists.
	       while read -r line
	       do
	         file_base=$(echo "$line" | gawk '{ print $4 }')
	         file="$TARGET/commits/$commit/$file_base"
	         sha=$(echo "$line" | gawk '{ print $3 }')

	         object_dir="$TARGET/objects/"$(echo "$sha" \
	       | sed 's#^\([a-f0-9]\{2\}\).*#\1#')
	         object="$object_dir/$sha"

	         if test ! -e "$object"
	         then
	           # File does not yet exists in the object repository.
	           # Create it.
	     if test ! -d "$object_dir"
	     then
	       mkdir "$object_dir"
	     fi

	           # The object's file should not be commit or branch specific:
	           # the same html is shared among all files with the same
	           # content.
	           {
	             html_header "$sha"
	             echo "<pre>"
	             git show "$sha" \
	               | sed 's#<#\&lt;#g; s#>#\&gt;#g; ' \
	               | gawk '{ ++line; printf("%6d: %s\n", line, $0); }'
	             echo "</pre>"
	             html_footer
	           } > "$object"
	         fi

	         # Create a hard link to the formatted file in the object repository.
	         mkdir -p $(dirname "$file")
	         ln "$object" "$file.raw.html"

	         # Create a hard link to the raw file.
	         raw_filename="raw/$(echo "$sha" | sed 's/^\(..\)/\1\//')"
	         if ! test -e "$raw_filename"
	         then
	       mkdir -p "$(dirname "$raw_filename")"
	       git cat-file blob "$sha" > $raw_filename
	         fi
	         ln "$raw_filename" "$file"
	       done <"$FILES"
	       rm -f "$FILES"
	     done <$COMMITS
	     rm -f $COMMITS

	     {
	       echo "</table>"
	       html_footer
	     } >> "$BRANCH_INDEX"
	   done
	*/
}

// TODO: implement!
func writeIndexFooter() {
	/*
	   {
	     echo "</ul>"
	     html_footer
	   } >> "$INDEX"
	*/
}

// TODO: implement!
func htmlHeader() {
	/*
	   html_header()
	   {
	     title="$1"
	     top_level="$2"

	     if test x"$PROJECT" != x -a x"$title" != x
	     then
	       # Title is not the empty string.  Prefix it with ": "
	       title=": $title"
	     fi

	     echo "<html><head><title>$PROJECT$title</title></head>" \
	       "<body>" \
	       "<h1><a href=\"$top_level/index.html\">$PROJECT</a>$title</h1>"
	   }
	*/
}

func htmlFooter() {
	/*
	   html_footer()
	   {
	     echo "<hr>" \
	       "Generated by" \
	       "<a href=\"http://hssl.cs.jhu.edu/~neal/git2html\">git2html</a>."
	   }
	*/
}